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);
        }
        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 #3
0
        public void TestOfIllegalDeleteRoleMembers()
        {
            this.InitAdmins();

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

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

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

            var fanhy = GetSCUserByCodeName("fanhy");

            Facade.AddMemberToRole(fanhy, mainRole);

            FacadeWithAcl.RemoveMemberFromRole(fanhy, mainRole);

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

            var mainApp = this.CreateDefaultApp();

            var mainRole = this.CreateDefaultRole();

            var fanhy = GetSCUserByCodeName("fanhy");

            Facade.AddMemberToRole(fanhy, mainRole);

            //Sleep(200);

            FacadeWithAcl.RemoveMemberFromRole(fanhy, mainRole);

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

            Assert.IsFalse((from m in members where m.ID == fanhy.ID && m.Status == SchemaObjectStatus.Normal select m).Any());
        }
Beispiel #5
0
        protected PC.SCRole CreateDefaultRoleWithMembers(IEnumerable <PC.SCUser> users)
        {
            var role = this.CreateDefaultRole();

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

            foreach (var item in members)
            {
                if (item.Status == SchemaObjectStatus.Normal)
                {
                    Facade.RemoveMemberFromRole((PC.SCBase)item.Member, role);
                }
            }

            foreach (var user in users)
            {
                Facade.AddMemberToRole(user, role);
            }

            return(role);
        }
Beispiel #6
0
        public void TestOfDeleteRoleMembers()
        {
            this.InitAdmins();

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

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

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

            var fanhy = GetSCUserByCodeName("fanhy");

            Facade.AddMemberToRole(fanhy, mainRole);

            FacadeWithAcl.RemoveMemberFromRole(fanhy, mainRole);

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

            Assert.IsFalse((from m in members where m.ID == fanhy.ID && m.Status == SchemaObjectStatus.Normal select m).Any());
        }