mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-21 22:11:48 +01:00
Fix: Spurious Error Message When Saving User With Non-Admin Rights (fix #1793)
This commit is contained in:
parent
23aefccbe9
commit
ffcc967aef
1 changed files with 4 additions and 3 deletions
|
@ -285,14 +285,15 @@ namespace BTCPayServer.Controllers
|
|||
return NotFound();
|
||||
|
||||
var admins = await _UserManager.GetUsersInRoleAsync(Roles.ServerAdmin);
|
||||
if (!viewModel.IsAdmin && admins.Count == 1)
|
||||
var roles = await _UserManager.GetRolesAsync(user);
|
||||
var wasAdmin = IsAdmin(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.";
|
||||
return View(viewModel); // return
|
||||
}
|
||||
|
||||
var roles = await _UserManager.GetRolesAsync(user);
|
||||
if (viewModel.IsAdmin != IsAdmin(roles))
|
||||
if (viewModel.IsAdmin != wasAdmin)
|
||||
{
|
||||
if (viewModel.IsAdmin)
|
||||
await _UserManager.AddToRoleAsync(user, Roles.ServerAdmin);
|
||||
|
|
Loading…
Add table
Reference in a new issue