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

This commit is contained in:
Luke Pulverenti 2013-05-24 16:47:07 -04:00
parent ca3f804db6
commit 41e3b2fb3a

View File

@ -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);