예제 #1
0
        public int Handle(EasyADGroup group)
        {
            LogHelper.Info<DeleteGroupHandler>(string.Format("Saving group {0} started", group.Name));

            _repo.SaveOrUpdate(group);
            _repo.DeleteGroupUsers(group.Id);

            var groupUsers = _groupManager.GetUsersInGroup(group.Name);
            foreach (var groupUser in groupUsers)
            {
                var backofficeUser = _userService.GetByUsername(groupUser.Login);
                if (backofficeUser == null)
                {
                    // create the backoffice user
                    LogHelper.Info<DeleteGroupHandler>(string.Format("Creating user '{0}' in backoffice", groupUser.DisplayName));
                    backofficeUser = _userService.CreateUserWithIdentity(groupUser.Login, groupUser.Email, _userService.GetUserTypeById(group.UserType));
                }
                backofficeUser.Name = groupUser.DisplayName;

                _repo.AddUserToGroup(group.Id, backofficeUser.Id);
                var groupsUserIsIn = _repo.GetGroupsForUser(backofficeUser.Id).ToList();

                ConfigureUserRights(backofficeUser, groupsUserIsIn);
            }

            LogHelper.Info<DeleteGroupHandler>(string.Format("Saving group '{0}' completed", group.Name));

            return group.Id;
        }
예제 #2
0
        public void Resolve_OneGroup()
        {
            //Arrange
            var group1 = new EasyADGroup { Id = 1, Name = "Group A", Sections = "content;media;", UserType = 1 };
            var groups = new List<EasyADGroup> { group1 };
            var expected = new[] { "content", "media" };

            //Act
            var actual = SectionResolver.Resolve(groups);

            //Assert
            Assert.AreEqual(2, actual.Length);
        }
예제 #3
0
        public void Resolve_OneType()
        {
            //Arrange
            var group1 = new EasyADGroup { Id = 1, Name = "Group A", Sections = "content;media;", UserType = 1 };
            var groups = new List<EasyADGroup> { group1 };
            var expected = 1;

            //Act
            var actual = UserTypeResolver.Resolve(groups, _allUserTypes).Id;

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #4
0
        public void Resolve_TwoGroups()
        {
            //Arrange
            var group1 = new EasyADGroup { Id = 1, Name = "Group A", Sections = "content;media;", UserType = 1 };
            var group2 = new EasyADGroup { Id = 2, Name = "Group B", Sections = "translation;", UserType = 3 };
            var groups = new List<EasyADGroup> { group1, group2 };
            var expected = new[] { "content", "media", "translation" };

            //Act
            var actual = SectionResolver.Resolve(groups);

            //Assert
            Assert.AreEqual(3, actual.Length);
            Assert.IsTrue(expected.All(e => actual.Contains(e)));
        }
예제 #5
0
        public void Resolve_MultipleGroups()
        {
            //Arrange
            var group1 = new EasyADGroup { Id = 1, Name = "Group A", Sections = "content;media;", UserType = 1 };
            var group2 = new EasyADGroup { Id = 2, Name = "Group B", Sections = "translation;", UserType = 3 };
            var group3 = new EasyADGroup { Id = 3, Name = "Group B", Sections = "content;media;users;members;", UserType = 2 };
            var groups = new List<EasyADGroup> { group1, group2, group3 };
            var expected = 2;

            //Act
            var actual = UserTypeResolver.Resolve(groups, _allUserTypes).Id;

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #6
0
 private EasyADGroup CreateWritersGroup()
 {
     var handler = new SaveGroupHandler(Repo, Manager, Services.UserService);
     var groupName = "AD-Writers";
     Manager.AddUsers(groupName,
         ADUsers.AndrewDavis
     );
     var group = new EasyADGroup
     {
         Name = groupName,
         UserType = AllUserTypes["Writer"],
         Sections = string.Join(";", AllSections["Content"], AllSections["Media"])
     };
     handler.Handle(group);
     return group;
 }
예제 #7
0
 private EasyADGroup CreateTranslatorsGroup()
 {
     var handler = new SaveGroupHandler(Repo, Manager, Services.UserService);
     var groupName = "AD-Translators";
     Manager.AddUsers(groupName,
         ADUsers.ChristopherMoore,
         ADUsers.SethButler
         );
     var group = new EasyADGroup
     {
         Name = groupName,
         UserType = AllUserTypes["Translator"],
         Sections = AllSections["Translation"]
     };
     handler.Handle(group);
     return group;
 }
예제 #8
0
 private EasyADGroup CreateAdminsGroup()
 {
     var handler = new SaveGroupHandler(Repo, Manager, Services.UserService);
     var groupName = "AD-Admins";
     Manager.AddUsers(groupName,
         ADUsers.ChristopherMoore,
         ADUsers.DanielMiller
     );
     var group = new EasyADGroup
     {
         Name = groupName,
         UserType = AllUserTypes["Editors"],
         Sections = string.Join(";", AllSections.Values)
     };
     handler.Handle(group);
     return group;
 }
예제 #9
0
        private void AssertUserForGroup(Umbraco.Core.Models.Membership.IUser user, EasyADGroup group, string[] extraSections = null)
        {
            Assert.AreEqual(group.UserType, user.UserType.Id, "Expected the UserType to match the groups");

            var expectedSections = group.SectionsArray;
            if (extraSections != null) { expectedSections = expectedSections.Concat(extraSections).ToArray(); }

            Assert.AreEqual(expectedSections.Length, user.AllowedSections.Count(), "Expected the user sections count to be the same as the groups");
            Assert.IsTrue(expectedSections.ContainsAll(user.AllowedSections), "Expected the user sections count to be the same as the groups");
        }
예제 #10
0
 public void SaveOrUpdate(EasyADGroup group)
 {
     if (group.Id > 0)
     {
         _database.Update(group);
     }
     else
     {
         _database.Save(group);
     }
 }