Beispiel #1
0
        public void LegalAddGroupTest()
        {
            this.InitAdmins();

            var mainApp = this.CreateDefaultApp();

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

            var mainOrg = this.GetOrganizationByCodeName("costEngineer");

            var testOrg = this.NewObject <PC.SCOrganization>("测试组织");

            Facade.AddOrganization(testOrg, mainOrg);

            this.SetContainerMemberAndPermissions(testOrg, mainRole, new string[] { "AddChildren" });

            PC.SCGroup testGrp = this.NewObject <PC.SCGroup>("测试群组");

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

            FacadeWithAcl.AddGroup(testGrp, testOrg);

            var actual = this.GetGroupByCodeName(testGrp.CodeName);

            Assert.IsNotNull(actual);
        }
Beispiel #2
0
        public void LegalRemoveUserFromGroupTest()
        {
            this.InitAdmins();

            var mainApp = this.CreateDefaultApp();

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

            var mainOrg = this.GetOrganizationByCodeName("costEngineer");

            var testOrg = this.NewObject <PC.SCOrganization>("测试组织");

            Facade.AddOrganization(testOrg, mainOrg);

            this.SetContainerMemberAndPermissions(testOrg, mainRole, new string[] { "EditMembersOfGroups" });

            PC.SCGroup testGrp = this.NewObject <PC.SCGroup>("测试群组");

            Facade.AddGroup(testGrp, testOrg);

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

            var testUser = this.GetSCUserByCodeName("jinge");

            Facade.AddUserToGroup(testUser, testGrp);

            FacadeWithAcl.RemoveUserFromGroup(testUser, testGrp);

            var actual = PC.Adapters.SCMemberRelationAdapter.Instance.Load(testGrp.ID, testUser.ID);

            Assert.IsNotNull(actual);

            Assert.AreNotEqual(actual.Status, SchemaObjectStatus.Normal);
        }
Beispiel #3
0
        public void IllegalRemoveUserFromGroupTest()
        {
            this.InitAdmins();

            var mainApp = this.CreateDefaultApp();

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

            var mainOrg = this.GetOrganizationByCodeName("costEngineer");

            var testOrg = this.NewObject <PC.SCOrganization>("测试组织");

            Facade.AddOrganization(testOrg, mainOrg);

            this.SetContainerMemberAndPermissions(testOrg, mainRole, new string[] { "EditMembersOfGroups" });

            PC.SCGroup testGrp = this.NewObject <PC.SCGroup>("测试群组");

            Facade.AddGroup(testGrp, testOrg);

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

            var testUser = this.GetSCUserByCodeName("jinge");

            FacadeWithAcl.RemoveUserFromGroup(testUser, testGrp);

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

            PC.SCGroup testGrp = this.NewObject <PC.SCGroup>("测试群组");

            var mainOrg = this.GetOrganizationByCodeName("costEngineer");

            var testOrg = this.NewObject <PC.SCOrganization>("测试组织");

            Facade.AddOrganization(testOrg, mainOrg);

            Facade.AddGroup(testGrp, testOrg);

            var testUser = this.GetSCUserByCodeName("jinge");

            Facade.AddUserToGroup(testUser, testGrp);

            FacadeWithAcl.RemoveUserFromGroup(testUser, testGrp);

            var actual = PC.Adapters.SCMemberRelationAdapter.Instance.Load(testGrp.ID, testUser.ID);

            Assert.IsNotNull(actual);

            Assert.AreNotEqual(actual.Status, SchemaObjectStatus.Normal);
        }
Beispiel #5
0
        public void LegalDeleteGroupTest()
        {
            this.InitAdmins();

            var mainApp = this.CreateDefaultApp();

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

            var mainOrg = this.GetOrganizationByCodeName("costEngineer");

            var testOrg = this.NewObject <PC.SCOrganization>("测试组织");

            Facade.AddOrganization(testOrg, mainOrg);

            this.SetContainerMemberAndPermissions(testOrg, mainRole, new string[] { "DeleteChildren" });

            PC.SCGroup testGrp = this.NewObject <PC.SCGroup>("测试群组");

            Facade.AddGroup(testGrp, testOrg);

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

            FacadeWithAcl.DeleteGroup(testGrp, testOrg, false);

            var actual = PC.Adapters.SchemaObjectAdapter.Instance.Load(testGrp.ID);

            Assert.AreNotEqual(actual.Status, SchemaObjectStatus.Normal);
        }
Beispiel #6
0
        private static void InitGroups()
        {
            PC.SCOrganization org = (PC.SCOrganization)PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(c =>
            {
                SchemaStrict(c, "O.", PC.StandardObjectSchemaType.Organizations);
            }, DateTime.MinValue, "流程管理部").First();


            PC.SCGroup grp1 = new PC.SCGroup()
            {
                Name        = "DemoGroup",
                CodeName    = "DemoGroup",
                DisplayName = "DemoGroup",
                Creator     = CastUser(Wangli),
                ID          = "BA4E965E-8A35-4986-B5EA-7631D9368FFF",
                Status      = SchemaObjectStatus.Normal,
            };

            Facade.AddGroup(grp1, org);

            org = (PC.SCOrganization)PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(c =>
            {
                SchemaStrict(c, "O.", PC.StandardObjectSchemaType.Organizations);
            }, DateTime.MinValue, "beijingYuanlian").First();

            grp1 = new PC.SCGroup()
            {
                Name        = "群组A",
                CodeName    = "groupA",
                DisplayName = "群组A",
                Creator     = CastUser(Wangli),
                ID          = "CA093A1E-B207-48DB-B3B2-B085A81DA36A",
                Status      = SchemaObjectStatus.Normal,
            };

            Facade.AddGroup(grp1, org);

            grp1 = new PC.SCGroup()
            {
                Name        = "群组B",
                CodeName    = "groupB",
                DisplayName = "群组B",
                Creator     = CastUser(Wangli),
                ID          = "A465FFC8-A742-41F3-A1B6-0D40FC5EA3D5",
                Status      = SchemaObjectStatus.Normal,
            };

            org = (PC.SCOrganization)PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(c =>
            {
                SchemaStrict(c, "O.", PC.StandardObjectSchemaType.Organizations);
            }, DateTime.MinValue, "yuanyangAobei").First();

            Facade.AddGroup(grp1, org);
        }
Beispiel #7
0
        public void AdminAddGroupTest()
        {
            this.InitAdmins();

            PC.SCGroup testGrp = this.NewObject <PC.SCGroup>("测试群组");

            var mainOrg = this.GetOrganizationByCodeName("costEngineer");

            var testOrg = this.NewObject <PC.SCOrganization>("测试组织");

            Facade.AddOrganization(testOrg, mainOrg);

            FacadeWithAcl.AddGroup(testGrp, testOrg);

            var actual = GetGroupByCodeName(testGrp.CodeName);

            Assert.IsNotNull(actual);
        }
Beispiel #8
0
        public void AdminDeleteGroupTest()
        {
            this.InitAdmins();

            PC.SCGroup testGrp = this.NewObject <PC.SCGroup>("测试群组");

            var mainOrg = this.GetOrganizationByCodeName("costEngineer");

            var testOrg = this.NewObject <PC.SCOrganization>("测试组织");

            Facade.AddOrganization(testOrg, mainOrg);

            Facade.AddGroup(testGrp, testOrg);

            FacadeWithAcl.DeleteGroup(testGrp, testOrg, false);

            var actual = PC.Adapters.SchemaObjectAdapter.Instance.Load(testGrp.ID);

            Assert.AreNotEqual(actual.Status, SchemaObjectStatus.Normal);
        }
        private static void InitGroups()
        {
            PC.SCOrganization org = (PC.SCOrganization)PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(c =>
            {
                SchemaStrict(c, "O.", PC.StandardObjectSchemaType.Organizations);
            }, DateTime.MinValue, "流程管理部").First();


            PC.SCGroup grp1 = new PC.SCGroup()
            {
                Name = "DemoGroup",
                CodeName = "DemoGroup",
                DisplayName = "DemoGroup",
                Creator = CastUser(Wangli),
                ID = "BA4E965E-8A35-4986-B5EA-7631D9368FFF",
                Status = SchemaObjectStatus.Normal,
            };

            Facade.AddGroup(grp1, org);

            org = (PC.SCOrganization)PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(c =>
            {
                SchemaStrict(c, "O.", PC.StandardObjectSchemaType.Organizations);
            }, DateTime.MinValue, "beijingYuanlian").First();

            grp1 = new PC.SCGroup()
            {
                Name = "群组A",
                CodeName = "groupA",
                DisplayName = "群组A",
                Creator = CastUser(Wangli),
                ID = "CA093A1E-B207-48DB-B3B2-B085A81DA36A",
                Status = SchemaObjectStatus.Normal,
            };

            Facade.AddGroup(grp1, org);

            grp1 = new PC.SCGroup()
            {
                Name = "群组B",
                CodeName = "groupB",
                DisplayName = "群组B",
                Creator = CastUser(Wangli),
                ID = "A465FFC8-A742-41F3-A1B6-0D40FC5EA3D5",
                Status = SchemaObjectStatus.Normal,
            };

            org = (PC.SCOrganization)PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(c =>
            {
                SchemaStrict(c, "O.", PC.StandardObjectSchemaType.Organizations);
            }, DateTime.MinValue, "yuanyangAobei").First();

            Facade.AddGroup(grp1, org);

        }
Beispiel #10
0
            private void DoImportMembers(SCObjectSet objectSet, IImportContext context, IDictionary <string, PC.SchemaObjectBase> knownObjects, PC.SCGroup group)
            {
                if (this.ImportMembers && objectSet.HasMembership)
                {
                    var members = ImportService.Instance.FilterMembership(objectSet.Membership, m => m.ContainerID == group.ID && m.Status == SchemaObjectStatus.Normal).ToArray();
                    if (members.Length > 0)
                    {
                        context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在查找群组 {0} 的固定成员", group.ToDescription()));

                        for (int j = 0; j < members.Length; j++)
                        {
                            try
                            {
                                var gm = members[j];

                                ImportService.Instance.WithEffectObject <PC.SCUser>(gm.ID, knownObjects, user =>
                                {
                                    context.SetSubStatusAndLog(j, members.Length, string.Format("正在向群组 {0} 添加成员 {1} ", group.Name, user.Name));
                                    PC.Executors.SCObjectOperations.Instance.AddUserToGroup(user, group);
                                }, null);
                            }
                            catch (Exception ex2)
                            {
                                context.SetSubStatusAndLog(j, members.Length, string.Format("向群组 {0} 添加成员时出错:", group.ToDescription(), ex2.ToString()));
                            }
                        }
                    }
                }
            }
Beispiel #11
0
            private void DoImportConditions(SCObjectSet objectSet, IImportContext context, PC.SCGroup group)
            {
                if (this.ImportConditions && objectSet.HasConditions)
                {
                    context.SetStatusAndLog(Owner.currentSteps, Owner.allSteps, string.Format("正在替换群组 {0} 的条件", group.Name));

                    try
                    {
                        var owner = PC.Adapters.SCConditionAdapter.Instance.Load(group.ID, "Default") ?? new PC.Conditions.SCConditionOwner()
                        {
                            OwnerID = group.ID, Type = "Default"
                        };

                        PC.Conditions.SCConditionCollection src = new PC.Conditions.SCConditionCollection();
                        src.CopyFrom(ImportService.Instance.FilterConditions(objectSet.Conditions, c => c.OwnerID == group.ID));

                        owner.Conditions.ReplaceItemsWith(src, group.ID, "Default");

                        PC.Adapters.SCConditionAdapter.Instance.UpdateConditions(owner);
                    }
                    catch (Exception ex)
                    {
                        context.AppendLog(string.Format("替换群组 {0} 条件成员时出错:{1}", group.ToDescription(), ex.ToString()));
                    }
                }
            }