Beispiel #1
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);
        }
Beispiel #2
0
        public void TestOfIllegalDisassignPermissions()
        {
            this.InitAdmins();

            var mainApp  = this.CreateDefaultApp();
            var mainRole = this.CreateDefaultRoleWithMembers(this.GetSCUsersByCodeNames("wanglch"));

            this.SetCurrentPrincipal(this.GetUserByCodeName("chenke"));

            var testRole = this.NewObject <SCRole>("测试角色");

            Facade.AddRole(testRole, mainApp);

            var testPermission = this.NewObject <SCPermission>("测试功能");

            Facade.AddPermission(testPermission, mainApp);

            Facade.JoinRoleAndPermission(testRole, testPermission);

            //Sleep(200);

            FacadeWithAcl.DisjoinRoleAndPermission(testRole, testPermission);

            Assert.Fail("不应该执行到此");
        }
Beispiel #3
0
        public void TestOfAssignPermissions()
        {
            this.InitAdmins();

            var mainApp  = this.CreateDefaultApp();
            var mainRole = this.CreateDefaultRoleWithMembers(this.GetSCUsersByCodeNames("wanglch"));

            base.SetContainerMemberAndPermissions(mainApp, mainRole, new string[] { "EditRelationOfRolesAndPermissions" });

            this.SetCurrentPrincipal(this.GetUserByCodeName("wanglch"));

            var testRole = this.NewObject <SCRole>("测试角色");

            Facade.AddRole(testRole, mainApp);

            var testPermission = this.NewObject <SCPermission>("测试功能");

            Facade.AddPermission(testPermission, mainApp);

            FacadeWithAcl.JoinRoleAndPermission(testRole, testPermission);

            var pm = PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(testRole.ID, testPermission.ID);

            Assert.IsNotNull(pm);
            Assert.AreEqual(pm.Status, SchemaObjectStatus.Normal);

            FacadeWithAcl.DisjoinRoleAndPermission(testRole, testPermission);

            pm = PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(testRole.ID, testPermission.ID);

            Assert.IsNotNull(pm);
            Assert.AreNotEqual(pm.Status, SchemaObjectStatus.Normal);
        }
Beispiel #4
0
        public void TestOfAdminAssignPermissions()
        {
            this.InitAdmins();

            var mainApp = this.CreateDefaultApp();

            var mainRole = this.CreateDefaultRole();

            var testRole = this.NewObject <SCRole>("测试角色");

            Facade.AddRole(testRole, mainApp);

            var testPermission = this.NewObject <SCPermission>("测试功能");

            Facade.AddPermission(testPermission, mainApp);

            FacadeWithAcl.JoinRoleAndPermission(testRole, testPermission);

            var pm = PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(testRole.ID, testPermission.ID);

            Assert.IsNotNull(pm);
            Assert.AreEqual(pm.Status, SchemaObjectStatus.Normal);

            FacadeWithAcl.DisjoinRoleAndPermission(testRole, testPermission);

            pm = PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(testRole.ID, testPermission.ID);

            Assert.IsNotNull(pm);
            Assert.AreNotEqual(pm.Status, SchemaObjectStatus.Normal);
        }
        public void TestOfLegalUpdateApplication()
        {
            this.InitAdmins();

            this.CreateDefaultRoleWithMembers(this.GetSCUsersByCodeNames("wanglch"));

            var app = this.NewObject <SCApplication>("测试应用");

            Facade.AddApplication(app);

            var role = this.NewObject <SCRole>("测试角色");

            Facade.AddRole(role, app);

            var chenke = this.GetSCUserByCodeName("chenke");

            Facade.AddMemberToRole(chenke, role);

            this.SetContainerMemberAndPermissions(app, role, new string[] { "UpdateApplications" });

            this.SetCurrentPrincipal(this.GetUserByCodeName("chenke"));

            this.RecalculateRoleUsers();

            FacadeWithAcl.UpdateApplication(app);
        }
Beispiel #6
0
        protected PC.SCRole CreateDefaultRole()
        {
            var app = (PC.SCApplication)PC.Adapters.SchemaObjectAdapter.Instance.Load(DefaultAppID);

            if (app == null || app.Status != SchemaObjectStatus.Normal)
            {
                app = this.CreateDefaultApp();
            }

            Debug.Assert(app.Status == SchemaObjectStatus.Normal);

            var role = new PC.SCRole()
            {
                ID          = DefaultRoleID,
                Name        = "测试角色" + DefaultRoleID,
                DisplayName = "测试角色(默认测试)",
                CodeName    = DefaultRoleID
            };

            Facade.AddRole(role, app);

            return(role);
        }