Esempio n. 1
0
        private static void InitApplications()
        {
            PC.SCApplication appGeneral = new PC.SCApplication()
            {
                CodeName    = "OGU_ADMIN",
                Name        = "机构人员管理",
                DisplayName = "机构人员管理",
                ID          = "99bc9c59-d436-4156-88e4-53c1147de180",
                Status      = SchemaObjectStatus.Normal,
            };

            PC.SCApplication officeHome = new PC.SCApplication()
            {
                CodeName    = "OAPORTAL",
                Name        = "办公门户",
                DisplayName = "办公门户",
                ID          = "18f556b2-f047-43a1-af53-d228818682e3",
                Status      = SchemaObjectStatus.Normal,
            };

            PC.SCApplication appAdmin = new SCApplication()
            {
                CodeName    = "APP_ADMIN",
                Name        = "通用授权",
                DisplayName = "通用授权",
                ID          = "11111111-1111-1111-1111-111111111111",
                Status      = SchemaObjectStatus.Normal
            };

            Facade.AddApplication(appGeneral);
            Facade.AddApplication(officeHome);
            Facade.AddApplication(appAdmin);
        }
Esempio n. 2
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. 3
0
        public override SCObjectSet Execute(HttpRequest req)
        {
            string[] ids = req.Form.GetValues("id");

            if (ids == null && ids.Length == 0)
            {
                throw new HttpException("当获取功能对象时,必须提供ID参数");
            }

            string appId = req.Form["appId"];

            if (string.IsNullOrEmpty(appId))
            {
                throw new HttpException("当获取功能对象时,必须提供appId参数");
            }

            SCObjectSet objectSet = new SCObjectSet();

            objectSet.Scope = "AppPermissions";

            PC.SCApplication appObj = (PC.SCApplication)PC.Adapters.SchemaObjectAdapter.Instance.Load(appId);
            if (appObj == null || appObj.Status != SchemaObjectStatus.Normal)
            {
                throw new HttpException("指定的应用不存在或者已删除");
            }

            objectSet.Objects = ExportQueryHelper.LoadObjects(ids, null);

            objectSet.Membership = ExportQueryHelper.LoadMembershipFor(ids, appId);
            return(objectSet);
        }
Esempio n. 4
0
        protected PC.SCRole CreateRoleWithMembers(PC.SCApplication app, PC.SCRole role, IEnumerable <PC.SCUser> users)
        {
            var role0 = (PC.SCRole)PC.Adapters.SchemaObjectAdapter.Instance.Load(role.ID);

            if (role0 == null || role0.Status != SchemaObjectStatus.Normal)
            {
                Facade.AddRole(role, app);
            }
            else
            {
                role = role0;
            }

            var members = PC.Adapters.SCMemberRelationAdapter.Instance.LoadByContainerID(role.ID);

            foreach (var item in members)
            {
                Facade.RemoveMemberFromRole((PC.SCBase)item.Member, role);
            }

            if (users != null)
            {
                foreach (var user in users)
                {
                    Facade.AddMemberToRole(user, role);
                }
            }


            return(role);
        }
Esempio n. 5
0
 internal static PC.SCApplication MakeCopy(PC.SCApplication app)
 {
     return(new PC.SCApplication()
     {
         Creator = MCS.Library.Principal.DeluxeIdentity.CurrentRealUser,
         ID = UuidHelper.NewUuidString(),
         Name = app.Name + "copy",
         DisplayName = app.DisplayName + "copy",
         CodeName = Util.MakeNoConflictCodeName(app.CodeName, "Applications")
     });
 }
Esempio n. 6
0
        private static void InitAppRoles()
        {
            PC.SCApplication app = (PC.SCApplication)PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(c => { }, DateTime.MinValue, "OGU_ADMIN").First();

            PC.SCRole role = new PC.SCRole()
            {
                Name        = "系统管理员",
                CodeName    = "系统管理员",
                DisplayName = "系统管理员",
                Creator     = CastUser(Wangli),
                ID          = "32491E78-BE9D-4159-8F29-1D6D56BC3166",
                Status      = SchemaObjectStatus.Normal,
            };

            PC.SCRole role2 = new PC.SCRole()
            {
                Name        = "系统维护员",
                CodeName    = "系统维护员",
                DisplayName = "系统维护员",
                Creator     = CastUser(Wangli),
                ID          = "B7C4C54C-C241-4704-9079-230CE9F61B53",
                Status      = SchemaObjectStatus.Normal,
            };

            Facade.AddRole(role, app);

            Facade.AddRole(role2, app);

            app = (PC.SCApplication)PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(c => { }, DateTime.MinValue, "APP_ADMIN").First();


            Facade.AddRole(new SCRole()
            {
                Name        = "系统应用维护员",
                CodeName    = "SYSTEM_APP_MODIFYER",
                DisplayName = "系统应用维护员",
                Creator     = CastUser(Wangli),
                ID          = "476442f3-5336-918b-4c57-f7b5cd519f6c",
                Status      = SchemaObjectStatus.Normal,
            }, app);

            Facade.AddRole(new SCRole()
            {
                Name        = "系统总管理员",
                CodeName    = "SYSTEM_MAX_ADMINISTRATOR",
                DisplayName = "系统总管理员",
                Creator     = CastUser(Wangli),
                ID          = "cdcfc01f-316a-adc7-4bac-f4f111a6d270",
                Status      = SchemaObjectStatus.Normal,
            }, app);
        }
Esempio n. 7
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. 8
0
		protected void btnGenInitData_Click(object sender, EventArgs e)
		{
			SCApplication app = new SCApplication();
			app.ID = "68DB2697-59B2-414B-8591-58CE06C4B44F";
			app.Name = "权限中心";
			app.CodeName = "OGU_ADMIN";
			app.DisplayName = "权限中心";

			PC.Executors.SCObjectOperations.Instance.AddApplication(app);

			SCRole role = new SCRole();
			role.ID = "6BEA73AB-0924-483B-BEE0-55C0847CFDAB";
			role.DisplayName = role.Name = "权限中心总管";
			role.CodeName = "SYSTEM_ADMINISTRATOR";

			PC.Executors.SCObjectOperations.Instance.AddRole(role, app);
		}
Esempio n. 9
0
        private static void InitAppPermissionsOfRoles()
        {
            PC.SCApplication app = (PC.SCApplication)PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(c => { }, DateTime.MinValue, "OGU_ADMIN").First();

            var permissions = app.CurrentPermissions;

            var roles = app.CurrentRoles;

            var justRole = (from r in roles where ((PC.SCRole)r).CodeName == "系统管理员" select((PC.SCRole)r)).First();

            var justPermission = (from p in permissions where ((PC.SCPermission)p).CodeName == "创建新用户" select((PC.SCPermission)p)).First();

            Facade.JoinRoleAndPermission(justRole, justPermission);

            justRole = (from r in roles where ((PC.SCRole)r).CodeName == "系统维护员" select((PC.SCRole)r)).First();

            justPermission = (from p in permissions where ((PC.SCPermission)p).CodeName == "创建新机构" select((PC.SCPermission)p)).First();

            Facade.JoinRoleAndPermission(justRole, justPermission);
        }
Esempio n. 10
0
        public override SCObjectSet Execute(HttpRequest req)
        {
            string[] ids = req.Form.GetValues("id");

            if (ids == null && ids.Length == 0)
            {
                throw new HttpException("当获取角色对象时,必须提供ID参数");
            }

            string appId = req.Form["appId"];

            if (string.IsNullOrEmpty(appId))
            {
                throw new HttpException("当获取角色对象时,必须提供appId参数");
            }

            SCObjectSet objectSet = new SCObjectSet();

            objectSet.Scope = "AppRoles";

            PC.SCApplication appObj = (PC.SCApplication)PC.Adapters.SchemaObjectAdapter.Instance.Load(appId);
            if (appObj == null || appObj.Status != SchemaObjectStatus.Normal)
            {
                throw new HttpException("指定的应用不存在或者已删除");
            }

            objectSet.Objects = ExportQueryHelper.LoadObjects(ids, null);

            objectSet.Membership = ExportQueryHelper.LoadFullMemberships(ids);        // 应用与角色的关系 & 应用的成员关系

            objectSet.Conditions = ExportQueryHelper.LoadConditions(ids);             // 保存对象的条件

            objectSet.Relations = ExportQueryHelper.LoadFullRelations(ids);           // 与权限的绑定关系

            return(objectSet);
        }
Esempio n. 11
0
 private void ImportRoles(IImportContext context, PC.Executors.ISCObjectOperations executor, Dictionary <object, object> mappings, PC.SCApplication app2, PC.SCRole[] roles)
 {
     if (this.IncludeRoles && roles.Length > 0)
     {
         context.AppendLog("正准备导入角色");
         foreach (var p in roles)
         {
             var role2 = this.CopyMode ? AppImportAction.MakeCopy(p) : p;
             mappings.Add(p, role2);
             context.AppendLog("正在导入角色" + role2.ToDescription());
             executor.AddRole(role2, app2);
         }
     }
 }
Esempio n. 12
0
 private void ImportPermissions(IImportContext context, PC.Executors.ISCObjectOperations executor, Dictionary <object, object> mappings, PC.SCApplication app2, PC.SCPermission[] permissions, bool copyMode)
 {
     if (permissions.Length > 0)
     {
         context.AppendLog("正准备导入功能");
         foreach (var p in permissions)
         {
             var permission2 = copyMode ? MakeCopy(p) : p;
             mappings.Add(p, permission2);
             context.AppendLog("正在导入功能" + permission2.DisplayName ?? permission2.Name);
             executor.AddPermission(permission2, app2);
         }
     }
 }
Esempio n. 13
0
        private void ImportAcl(IImportContext context, PC.Executors.ISCObjectOperations executor, PC.SCApplication targetApp, PC.Permissions.SCAclItem[] acls)
        {
            if (acls.Length > 0)
            {
                var container = new PC.Permissions.SCAclContainer(targetApp);

                context.AppendLogFormat("正在替 {0} 合并ACL定义\r\n", targetApp.ToDescription());

                var oldPermissions = PC.Adapters.SCAclAdapter.Instance.LoadByContainerID(targetApp.ID, DateTime.MinValue);

                PC.Permissions.SCAclMemberCollection members = new PC.Permissions.SCAclMemberCollection();

                foreach (var item in acls)
                {
                    ImportService.Instance.WithEffectObject <PC.SchemaObjectBase>(item.MemberID, role =>
                    {
                        members.Add(item.ContainerPermission, role);
                    }, null);
                }

                if (oldPermissions != null && oldPermissions.Count > 0)
                {
                    members.MergeChangedItems(oldPermissions);
                }

                container.Members.CopyFrom(members);

                PC.Adapters.SCAclAdapter.Instance.Update(container);
            }
        }
Esempio n. 14
0
        private void ImportApplication(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations executor, int allCount, int currentStep, int extStepCount, Dictionary <object, object> mappings, PC.SCApplication app)
        {
            var app2        = this.CopyMode ? AppImportAction.MakeCopy(app) : app;
            var summaryName = app2.DisplayName ?? app.Name;

            context.SetStatus(currentStep, allCount, "正在导入项目:" + summaryName);
            context.AppendLog("正在导入应用" + summaryName);
            executor.AddApplication((PC.SCApplication)app2);

            var permissionRelation = from p in objectSet.Membership where p.ContainerID == app.ID && p.MemberSchemaType == "Permissions" orderby p.InnerSort ascending select p;
            var permissions        = (from o in objectSet.Objects join p in permissionRelation on o.ID equals p.ID select(PC.SCPermission) o).ToArray();

            var roleRelations = from r in objectSet.Membership where r.ContainerID == app.ID && r.MemberSchemaType == "Roles" orderby r.InnerSort ascending select r;
            var roles         = (from o in objectSet.Objects join r in roleRelations on o.ID equals r.ID select(PC.SCRole) o).ToArray();

            var acls = (from acl in objectSet.Acls where acl.Status == SchemaObjectStatus.Normal && acl.ContainerID == app.ID orderby acl.SortID ascending select acl).ToArray();

            int allStepCount = allCount * (extStepCount + 1);
            int step         = currentStep * (extStepCount + 1);

            if (this.IncludePermissions)
            {
                context.SetStatus(step++, allStepCount, "正在查找功能...");
                this.ImportPermissions(context, executor, mappings, app2, permissions, this.CopyMode);
            }

            if (this.IncludeRoles)
            {
                context.SetStatus(step++, allStepCount, "正在查找角色...");
                this.ImportRoles(context, executor, mappings, app2, roles);
            }

            if (this.IncludeAcls)
            {
                context.SetStatus(step++, allStepCount, "正在查找Acl...");
                this.ImportAcl(context, executor, app2, acls);
            }

            if (this.IncludeRoleMembers)
            {
                context.SetStatus(step++, allStepCount, "正在查找角色成员...");
                this.ImportRoleMembers(objectSet, context, executor, mappings, roles);
            }

            if (this.IncludeRoleConditions)
            {
                context.SetStatus(step++, allStepCount, "正在查找角色条件...");
                this.ImportRoleConditions(objectSet, context, executor, mappings, roles);
            }

            if (this.IncludeRoles && this.IncludePermissions && this.IncludeRoleDefinitions)
            {
                context.SetStatus(step++, allStepCount, "正在查找角色功能定义...");
                this.ImportRolePermissions(objectSet, context, executor, mappings, permissions, roles, this.CopyMode);
            }
        }
Esempio n. 15
0
 protected void CreateRole(PC.SCApplication app, PC.SCRole role)
 {
     this.CreateRoleWithMembers(app, role, null);
 }
        private static void InitApplications()
        {
            PC.SCApplication appGeneral = new PC.SCApplication()
            {

                CodeName = "OGU_ADMIN",
                Name = "机构人员管理",
                DisplayName = "机构人员管理",
                ID = "99bc9c59-d436-4156-88e4-53c1147de180",
                Status = SchemaObjectStatus.Normal,
            };

            PC.SCApplication officeHome = new PC.SCApplication()
            {

                CodeName = "OAPORTAL",
                Name = "办公门户",
                DisplayName = "办公门户",
                ID = "18f556b2-f047-43a1-af53-d228818682e3",
                Status = SchemaObjectStatus.Normal,
            };

            PC.SCApplication appAdmin = new SCApplication()
            {
                CodeName = "APP_ADMIN",
                Name = "通用授权",
                DisplayName = "通用授权",
                ID = "11111111-1111-1111-1111-111111111111",
                Status = SchemaObjectStatus.Normal
            };

            Facade.AddApplication(appGeneral);
            Facade.AddApplication(officeHome);
            Facade.AddApplication(appAdmin);
        }