Esempio n. 1
0
        private static void InitAppPermissions()
        {
            PC.SCApplication app = (PC.SCApplication)PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(c => { }, DateTime.MinValue, "OGU_ADMIN").First();

            PC.SCPermission fun1 = new PC.SCPermission()
            {
                Name        = "创建新机构",
                CodeName    = "创建新机构",
                DisplayName = "创建新机构",
                Creator     = CastUser(Wangli),
                ID          = "48DED987-42AA-4E53-A79D-270449CE6056",
                Status      = SchemaObjectStatus.Normal,
            };

            PC.SCPermission fun2 = new PC.SCPermission()
            {
                Name        = "创建新用户",
                CodeName    = "创建新用户",
                DisplayName = "创建新用户",
                Creator     = CastUser(Wangli),
                ID          = "C04A7B64-8839-49DE-AA34-4EF28ACEEEEA",
                Status      = SchemaObjectStatus.Normal,
            };

            Facade.AddPermission(fun1, app);
            Facade.AddPermission(fun2, app);

            Assert.IsTrue(app.CurrentPermissions.Count == 2);
        }
Esempio n. 2
0
 internal static PC.SCPermission MakeCopy(PC.SCPermission obj)
 {
     return(new PC.SCPermission()
     {
         Creator = MCS.Library.Principal.DeluxeIdentity.CurrentRealUser,
         ID = UuidHelper.NewUuidString(),
         Name = obj.Name + "copy",
         DisplayName = obj.DisplayName + "copy",
         CodeName = Util.MakeNoConflictCodeName(obj.CodeName, "Permissions")
     });
 }
Esempio n. 3
0
        protected PC.SCPermission CreatePermission(PC.SCApplication app, PC.SCPermission fun)
        {
            var fun0 = (PC.SCPermission)PC.Adapters.SchemaObjectAdapter.Instance.Load(fun.ID);

            if (fun0 == null || fun0.Status != SchemaObjectStatus.Normal)
            {
                Facade.AddPermission(fun, app);
            }
            else
            {
                fun = fun0;
            }

            return(fun);
        }
Esempio n. 4
0
        public override void DoImport(SCObjectSet objectSet, IImportContext context)
        {
            if (string.IsNullOrEmpty(this.ApplicationId))
            {
                throw new HttpException("没有指定ApplicationId的情况下无法导入。");
            }

            var app = (PC.SCApplication)PC.Adapters.SchemaObjectAdapter.Instance.Load(this.ApplicationId);

            if (app == null)
            {
                throw new HttpException("指定的应用并不存在");
            }

            if (objectSet.HasObjects)
            {
                int count    = 0;
                int allCount = 0;
                var exec     = PC.Executors.SCObjectOperations.InstanceWithPermissions;

                IEnumerable <PC.SCSimpleRelationBase> permissionRelations = null;

                if (this.CopyMode)
                {
                    permissionRelations = from r in objectSet.Membership where r.MemberSchemaType == "Permissions" orderby r.InnerSort ascending select r;
                }
                else
                {
                    permissionRelations = from r in objectSet.Membership where r.MemberSchemaType == "Permissions" && r.ContainerID == app.ID orderby r.InnerSort ascending select r;
                }

                var permissions = (from o in objectSet.Objects join p in permissionRelations on o.ID equals p.ID select(PC.SCPermission) o).ToArray();

                allCount = permissions.Length;

                foreach (var p in permissions)
                {
                    count++;
                    PC.SCPermission fun = this.CopyMode ? AppImportAction.MakeCopy(p) : p;

                    // 只导入明确的
                    context.SetStatus(count, allCount, "正在导入权限:" + fun.DisplayName);
                    context.AppendLogFormat("正在导入权限 {0} \r\n", fun.DisplayName ?? fun.Name);
                    exec.AddPermission(fun, app);
                }
            }
        }
Esempio n. 5
0
        private void ImportRolePermissions(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations executor, Dictionary <object, object> mappings, PC.SCPermission[] permissions, PC.SCRole[] roles, bool copyMode)
        {
            if (roles.Length > 0 && permissions.Length > 0 && objectSet.HasRelations)
            {
                foreach (var r in roles)
                {
                    PC.SCRole role2 = r;
                    if (mappings.ContainsKey(r))
                    {
                        role2 = (PC.SCRole)mappings[r];
                    }

                    context.AppendLogFormat("正在替 {0} 查找功能定义\r\n", role2.ToDescription());

                    foreach (var p in permissions)
                    {
                        PC.SCPermission permission2 = p;
                        if (mappings.ContainsKey(p))
                        {
                            permission2 = (PC.SCPermission)mappings[p];
                        }

                        var actual = PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(role2.ID, permission2.ID);
                        var actualHasPermission = actual != null && actual.Status == SchemaObjectStatus.Normal;

                        var refHasPermission = (from rr in objectSet.Relations where rr.Status == SchemaObjectStatus.Normal && rr.ParentID == r.ID && rr.ID == p.ID && rr.ChildSchemaType == "Permissions" && rr.ParentSchemaType == "Roles" select rr).FirstOrDefault() != null;

                        if (refHasPermission == false && actualHasPermission)
                        {
                            context.AppendLogFormat("正在替角色 {0} 解除功能 {1}\r\n", role2.ToDescription(), permission2.ToDescription());
                            executor.DisjoinRoleAndPermission(role2, permission2);
                        }
                        else if (refHasPermission && actualHasPermission == false)
                        {
                            context.AppendLogFormat("正在替角色 {0} 指定功能 {1}\r\n", role2.ToDescription(), permission2.ToDescription());
                            executor.JoinRoleAndPermission(role2, permission2);
                        }
                    }
                }
            }
        }
        private static void InitAppPermissions()
        {
            PC.SCApplication app = (PC.SCApplication)PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(c => { }, DateTime.MinValue, "OGU_ADMIN").First();

            PC.SCPermission fun1 = new PC.SCPermission()
            {
                Name = "创建新机构",
                CodeName = "创建新机构",
                DisplayName = "创建新机构",
                Creator = CastUser(Wangli),
                ID = "48DED987-42AA-4E53-A79D-270449CE6056",
                Status = SchemaObjectStatus.Normal,
            };

            PC.SCPermission fun2 = new PC.SCPermission()
            {
                Name = "创建新用户",
                CodeName = "创建新用户",
                DisplayName = "创建新用户",
                Creator = CastUser(Wangli),
                ID = "C04A7B64-8839-49DE-AA34-4EF28ACEEEEA",
                Status = SchemaObjectStatus.Normal,
            };

            Facade.AddPermission(fun1, app);
            Facade.AddPermission(fun2, app);

            Assert.IsTrue(app.CurrentPermissions.Count == 2);
        }