Esempio n. 1
0
        public void DeleteRole(RoleInfo role)
        {
            Requires.NotNull("role", role);

            AddMessage(role, EventLogController.EventLogType.ROLE_DELETED);

            if (role.SecurityMode != SecurityMode.SecurityRole)
            {
                //remove group artifacts
                var portalSettings = PortalController.GetCurrentPortalSettings();

                IFileManager   _fileManager   = FileManager.Instance;
                IFolderManager _folderManager = FolderManager.Instance;

                IFolderInfo groupFolder = _folderManager.GetFolder(portalSettings.PortalId, "Groups/" + role.RoleID);
                if (groupFolder != null)
                {
                    _fileManager.DeleteFiles(_folderManager.GetFiles(groupFolder));
                    _folderManager.DeleteFolder(groupFolder);
                }
                JournalController.Instance.SoftDeleteJournalItemByGroupId(portalSettings.PortalId, role.RoleID);
            }

            provider.DeleteRole(role);

            ClearRoleCache(role.PortalID);
        }
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            if (!Initialized)
            {
                return(_prevProvider.DeleteRole(roleName, throwOnPopulatedRole));
            }
            if (string.IsNullOrEmpty(roleName))
            {
                MySqlSimpleMembershipProvider.NullArgumentException("roleName");
            }

            int roleid = GetRoleId(roleName);

            if (roleid <= 0)
            {
                return(false);
            }
            using (MySqlDatabaseWrapper dbConn = new MySqlDatabaseWrapper(ConnectionString))
            {
                if (throwOnPopulatedRole)
                {
                    if (IsRoleInUse(roleid))
                    {
                        throw new InvalidOperationException(string.Format(Resources.RoleInUse, roleName));
                    }
                }
                else
                {
                    dbConn.ExecuteNonQuery(string.Format("delete from {0} where roleid=?;", _userInRolesTable), roleid);
                }
                return(dbConn.ExecuteNonQuery(string.Format("delete from {0} where roleid=?;", _rolesTable), roleid) > 0);
            }
        }
 /// <summary>
 /// Clear out everything except the admin user
 /// </summary>
 private void DoFullReset()
 {
     foreach (var repository in Repository.GetAllRepositories())
     {
         Repository.Delete(repository.Id);
     }
     foreach (var team in TeamRepository.GetAllTeams())
     {
         TeamRepository.Delete(team.Id);
     }
     foreach (var user in Users.GetAllUsers())
     {
         if (!user.Username.Equals("Admin", StringComparison.OrdinalIgnoreCase))
         {
             Users.DeleteUser(user.Id);
         }
     }
     foreach (var role in RoleProvider.GetAllRoles())
     {
         if (role != Definitions.Roles.Administrator)
         {
             RoleProvider.DeleteRole(role, true);
         }
     }
 }
Esempio n. 4
0
        internal static void CreateRoles(RoleProvider provider)
        {
            ProviderRoles = provider.GetAllRoles().ToList <string>().FindAll(roleName => roleName.ToLower().Contains("test_"));
            foreach (string role in ProviderRoles)
            {
                if (provider.RoleExists(role))
                {
                    string[] usersInRoles = provider.GetUsersInRole(role);
                    if (usersInRoles.Length != 0)
                    {
                        provider.RemoveUsersFromRoles(usersInRoles, new string[] { role }); //remove users from role
                    }
                    provider.DeleteRole(role, false);                                       //remove role
                }
            }

            ProviderRoles.Clear();
            for (int x = 0; x < 20; x++)
            {
                string roleName = string.Format("TEST_ROLE:{0:000}", x);
                ProviderRoles.Add(roleName);
                provider.CreateRole(roleName);
            }

            //NOTE:  roles 0-9 are reserved for query type operations and should be considered read only
            //       roles 10-19 may be used for C-U-D operations
            addUserToRole(Users[0], ProviderRoles[0], provider);  // several users in one role
            addUserToRole(Users[2], ProviderRoles[0], provider);
            addUserToRole(Users[4], ProviderRoles[0], provider);

            addUserToRole(Users[6], ProviderRoles[1], provider); // same user in multiple roles
            addUserToRole(Users[6], ProviderRoles[2], provider);
            addUserToRole(Users[6], ProviderRoles[3], provider);

            addUserToRole(Users[10], ProviderRoles[1], provider); // same user in multiple roles
            addUserToRole(Users[10], ProviderRoles[2], provider);
            addUserToRole(Users[10], ProviderRoles[3], provider);

            addUserToRole(Users[8], ProviderRoles[1], provider);
            addUserToRole(Users[8], ProviderRoles[2], provider);

/*
 * TEST_ROLE:000
 *  Users[0]
 *  Users[2]
 *  Users[4]
 * TEST_ROLE:001
 *  Users[6]
 *  Users[8]
 * TEST_ROLE:002
 *  Users[6]
 *  Users[8]
 * TEST_ROLE:003
 *  Users[6]
 * TEST_ROLE:004
 *  -- no users
 *
 */
        }
Esempio n. 5
0
        public void Can_Delete_Role()
        {
            RoleProvider.CreateRole("admin");

            RoleProvider.DeleteRole("admin", true);

            Assert.False(Verifier.Query <Role>().Any(r => r.Name == "admin"));
        }
Esempio n. 6
0
        public void Can_Delete_Role()
        {
            RoleProvider.CreateRole("admin");

            RoleProvider.DeleteRole("admin", true);

            Assert.False(_db.CanFindRole("admin"));
        }
Esempio n. 7
0
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            LogDebug("Entering CachedProvider.DeleteRole");
            bool result;

            result = _provider.DeleteRole(roleName, throwOnPopulatedRole);

            return(result);
        }
Esempio n. 8
0
        public void DeleteRole(string roleName)
        {
            using (var ts = new TransactionScope())
            {
                // Delete role
                _roleProvider.DeleteRole(roleName, false);

                ts.Complete();
            }
        }
Esempio n. 9
0
        public void Can_Throw_When_Users_In_Role()
        {
            var user = new User {
                Username = "******", Password = "******"
            };

            RoleProvider.CreateRole("admin");
            MembershipProvider.CreateAccount(user);
            RoleProvider.AddUsersToRoles(new[] { "sallen" }, new[] { "admin" });

            Assert.Throws <ProviderException>(() => RoleProvider.DeleteRole("admin", true));
        }
Esempio n. 10
0
        public void Can_Delete_Role_With_Users()
        {
            var user = new User {
                Username = "******", Password = "******"
            };

            RoleProvider.CreateRole("admin");
            MembershipProvider.CreateAccount(user);
            RoleProvider.AddUsersToRoles(new[] { "sallen" }, new[] { "admin" });

            RoleProvider.DeleteRole("admin", false);

            Assert.False(_db.CanFindRole("admin"));
        }
Esempio n. 11
0
        public void Can_Delete_Role_With_Users()
        {
            var user = new User {
                Username = "******", Password = "******"
            };

            RoleProvider.CreateRole("admin");
            MembershipProvider.CreateAccount(user);
            RoleProvider.AddUsersToRoles(new[] { "sallen" }, new[] { "admin" });

            RoleProvider.DeleteRole("admin", false);

            Assert.False(Verifier.Query <Role>().Any(r => r.Name == "admin"));
        }
Esempio n. 12
0
 public void RemoveRoleTest()
 {
     if (!rp.RoleExists(specialRN1))
     {
         rp.CreateRole(specialRN1);
     }
     Assert.IsTrue(rp.RoleExists(specialRN1));
     if (rp.RoleExists(specialRN1))
     {
         rp.DeleteRole(specialRN1, false);
     }
     Assert.IsFalse(rp.RoleExists(specialRN1));
 }
Esempio n. 13
0
 public ActionResult Index(FormCollection form)
 {
     try
     {
         if (form["btnDelete"] != null)
         {
             var roleValues = form.GetValues("chkDelete");
             if (roleValues != null)
             {
                 foreach (var roleValue in roleValues)
                 {
                     var roleId = Convert.ToInt32(roleValue);
                     roleProvider.DeleteRole(roleId);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError(String.Empty, ex.Message);
         Logger.ErrorException(ex.Message, ex);
     }
     return(RedirectToAction("Index"));
 }
 public bool DeleteRole(string name)
 {
     return(roleProvider.DeleteRole(name, false));
 }
Esempio n. 15
0
 /// <summary>
 /// Deletes the specified role name.
 /// </summary>
 /// <param name="roleName">Name of the role.</param>
 public void Delete(string roleName)
 {
     _roleProvider.DeleteRole(roleName, false);
 }
 /// <summary>
 /// DeleteRole() Method <a name="DeleteRole"></a>
 /// The DeleteRole deletes the specified role from the portal database.
 /// Other relevant sources:
 /// + <a href="DeleteRole.htm" style="color:green">DeleteRole Stored Procedure</a>
 /// </summary>
 /// <param name="roleID">The role id.</param>
 public void DeleteRole(Guid roleID)
 {
     RoleProvider.DeleteRole(CurrentPortalSettings.PortalAlias, roleID, false);
 }
Esempio n. 17
0
 public bool DeleteRole(string roleName)
 {
     return(_provider.DeleteRole(roleName, true));
 }
Esempio n. 18
0
        public string Process(string[] args)
        {
            var sb = new StringBuilder();

            var p = new OptionSet()
            {
                { "c|create", "create a role\nUSAGE: role --create rolename",
                  v => _command = Command.Create },
                { "d|delete", "delete a role\nUSAGE: role --delete rolename",
                  v => _command = Command.Delete },
                { "l|list", "return a list of roles\nUSAGE: role --list",
                  v => _command = Command.List },
                { "g|give", "add a user to a role\nUSAGE: role --give username rolename",
                  v => _command = Command.Give },
                { "t|take", "remove a user from a role\nUSAGE: role --take username rolename",
                  v => _command = Command.Take },
                { "u|users", "list all users in a role\nUSAGE: role --users rolename",
                  v => _command = Command.Users },
                { "r|roles", "list all roles for a user\nUSAGE: role --roles username",
                  v => _command = Command.Roles },
                { "h|help", "show this list of options\nUSAGE --help",
                  v => _command = null }
            };

            List <string> extras;

            try
            {
                extras = p.Parse(args);
            }
            catch (OptionException e)
            {
                sb.Append("role: ");
                sb.AppendLine(e.Message);
                sb.AppendLine("Try `role --help' for more information.");
                return(sb.ToString());
            }

            // perform the selected command
            if (_command == Command.Create)
            {
                if (extras.Count == 1)
                {
                    _provider.CreateRole(extras[0]);
                    sb.AppendLine("Role successfully created");
                }
                else
                {
                    sb.AppendLine("USAGE: role --create rolename");
                }
            }
            else if (_command == Command.Delete)
            {
                if (extras.Count == 1)
                {
                    try
                    {
                        var success = _provider.DeleteRole(extras[0], true);

                        if (success)
                        {
                            sb.AppendLine("Role successfully deleted");
                        }
                        else
                        {
                            sb.AppendFormat("Could not delete role: {0}", extras[0]);
                            sb.AppendLine();
                        }
                    }
                    catch (Exception ex)
                    {
                        sb.AppendFormat("Could not delete role: {0} - {1}", extras[0], ex.Message);
                        sb.AppendLine();
                    }
                }
                else
                {
                    sb.AppendLine("USAGE: role --delete rolename");
                }
            }
            else if (_command == Command.List)
            {
                if (extras.Count == 0)
                {
                    var roles = _provider.GetAllRoles();

                    if (roles.Count() > 0)
                    {
                        foreach (var role in roles)
                        {
                            sb.AppendLine(role);
                        }
                    }
                    else
                    {
                        sb.AppendLine("No roles found");
                    }
                }
                else
                {
                    sb.AppendLine("USAGE: role --list");
                }
            }
            else if (_command == Command.Give)
            {
                if (extras.Count == 2)
                {
                    _provider.AddUsersToRoles(new string[] { extras[0] }, new string[] { extras[1] });
                    sb.AppendFormat("Added {0} to {1}", extras[0], extras[1]);
                    sb.AppendLine();
                }
                else
                {
                    sb.AppendLine("USAGE: role --give username rolename");
                }
            }
            else if (_command == Command.Take)
            {
                if (extras.Count == 2)
                {
                    _provider.RemoveUsersFromRoles(new string[] { extras[0] }, new string[] { extras[1] });
                    sb.AppendFormat("Removed {0} from {1}", extras[0], extras[1]);
                    sb.AppendLine();
                }
                else
                {
                    sb.AppendLine("USAGE: role --take username rolename");
                }
            }
            else if (_command == Command.Users)
            {
                if (extras.Count == 1)
                {
                    var users = _provider.GetUsersInRole(extras[0]);

                    if (users.Count() > 0)
                    {
                        sb.AppendFormat("{0} users in {1}", users.Count(), extras[0]);
                        sb.AppendLine();

                        foreach (var u in users)
                        {
                            sb.AppendLine(u);
                        }
                    }
                    else
                    {
                        sb.AppendLine("No users in role");
                    }
                }
                else
                {
                    sb.AppendLine("USAGE: role --users rolename");
                }
            }
            else if (_command == Command.Roles)
            {
                if (extras.Count == 1)
                {
                    var roles = _provider.GetRolesForUser(extras[0]);

                    if (roles.Count() > 0)
                    {
                        sb.AppendFormat("{0} roles for {1}", roles.Count(), extras[0]);
                        sb.AppendLine();

                        foreach (var r in roles)
                        {
                            sb.AppendLine(r);
                        }
                    }
                    else
                    {
                        sb.AppendLine("No roles found for user");
                    }
                }
                else
                {
                    sb.AppendLine("USAGE: role --roles username");
                }
            }
            else
            {
                sb.AppendLine(ShowHelp(p));
            }

            return(sb.ToString());
        }
Esempio n. 19
0
 public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
 {
     return(_Provider.DeleteRole(roleName, throwOnPopulatedRole));
 }
Esempio n. 20
0
 public void DeleteRole(string roleName)
 {
     roleProvider.DeleteRole(roleName, true);
 }
        public void MembershipRole_DeleteRoleTests()
        {
            bool   throwError = false;
            string rolename;

            //-------------------------------------------------------
            //  null name
            //-------------------------------------------------------
            rolename = null;
            try
            {
                _provider.DeleteRole(rolename, throwError);
                Assert.Fail("Provider did not throw expected ArgumentNullException on null rolename");
            }
            catch (ArgumentNullException)
            {
                //ignore expected exception
            }
            //-------------------------------------------------------
            //  empty name
            //-------------------------------------------------------
            rolename = string.Empty;
            try
            {
                _provider.DeleteRole(rolename, throwError);
                Assert.Fail("Provider did not thorw expected ArgumentException on empty role name");
            }
            catch (ArgumentException)
            {
                //ignore expected exception
            }
            //-------------------------------------------------------
            //  non existant name - asp doesn't thorw an error
            //    on non existant name.  It probably should but
            //    the argument can be made either way.
            //-------------------------------------------------------
            rolename = Guid.NewGuid().ToString();
            try
            {
                _provider.DeleteRole(rolename, throwError);
            }
            catch (Exception ex)
            {
                Assert.Fail("Provider threw unexpected exception '{0}' when none was expected", ex.Message);
            }

            //-------------------------------------------------------
            //  existing role with users, throw error = true
            //-------------------------------------------------------
            rolename   = TestUtils.ProviderRoles[3];
            throwError = true;
            try
            {
                _provider.DeleteRole(rolename, throwError);
                Assert.Fail("Provider did not throw expected ProviderException when deleting populated role");
            }
            catch (ProviderException)
            {
                //ignore expected exception
            }
            //-------------------------------------------------------
            //  existing role without users, throw error = true
            //-------------------------------------------------------
            rolename   = TestUtils.ProviderRoles[4];
            throwError = true;
            _provider.DeleteRole(rolename, throwError);

            //-------------------------------------------------------
            //  existing role with users, throw error = false
            //-------------------------------------------------------
            rolename   = TestUtils.ProviderRoles[3];
            throwError = false;
            _provider.DeleteRole(rolename, throwError);
            Assert.IsFalse(_provider.RoleExists(rolename));

            //-------------------------------------------------------
            //  existing role without users, throw error = false
            //-------------------------------------------------------
            rolename   = TestUtils.ProviderRoles[13];
            throwError = false;
            _provider.DeleteRole(rolename, throwError);
        }