Ver Fonte

don't allow removal of admin rights if there is only one admin

Luke Pulverenti há 12 anos atrás
pai
commit
41e3b2fb3a
1 ficheiros alterados com 9 adições e 0 exclusões
  1. 9 0
      MediaBrowser.Api/UserService.cs

+ 9 - 0
MediaBrowser.Api/UserService.cs

@@ -285,6 +285,15 @@ namespace MediaBrowser.Api
 
             var user = _userManager.GetUserById(id);
 
+            // If removing admin access
+            if (!dtoUser.Configuration.IsAdministrator && user.Configuration.IsAdministrator)
+            {
+                if (_userManager.Users.Count(i => i.Configuration.IsAdministrator) == 1)
+                {
+                    throw new ArgumentException("There must be at least one user in the system with administrative access.");
+                }
+            }
+
             var task = user.Name.Equals(dtoUser.Name, StringComparison.Ordinal) ? _userManager.UpdateUser(user) : _userManager.RenameUser(user, dtoUser.Name);
 
             Task.WaitAll(task);