Add IsRoleAdmin to user service

This commit is contained in:
Umar Bolatov
2021-03-14 13:02:43 -07:00
parent e5a196918f
commit 2ed8341403
3 changed files with 16 additions and 17 deletions

View File

@@ -79,16 +79,11 @@ namespace BTCPayServer.Controllers
Id = user.Id,
Email = user.Email,
Verified = user.EmailConfirmed || !user.RequiresEmailConfirmation,
IsAdmin = IsAdmin(roles)
IsAdmin = _userService.IsRoleAdmin(roles)
};
return View(userVM);
}
private static bool IsAdmin(IList<string> roles)
{
return roles.Contains(Roles.ServerAdmin, StringComparer.Ordinal);
}
[Route("server/users/{userId}")]
[HttpPost]
public new async Task<IActionResult> User(string userId, UsersViewModel.UserViewModel viewModel)
@@ -99,7 +94,7 @@ namespace BTCPayServer.Controllers
var admins = await _UserManager.GetUsersInRoleAsync(Roles.ServerAdmin);
var roles = await _UserManager.GetRolesAsync(user);
var wasAdmin = IsAdmin(roles);
var wasAdmin = _userService.IsRoleAdmin(roles);
if (!viewModel.IsAdmin && admins.Count == 1 && wasAdmin)
{
TempData[WellKnownTempData.ErrorMessage] = "This is the only Admin, so their role can't be removed until another Admin is added.";
@@ -206,7 +201,7 @@ namespace BTCPayServer.Controllers
return NotFound();
var roles = await _UserManager.GetRolesAsync(user);
if (IsAdmin(roles))
if (_userService.IsRoleAdmin(roles))
{
var admins = await _UserManager.GetUsersInRoleAsync(Roles.ServerAdmin);
if (admins.Count == 1)