Different message for admin deletion, check not to delete last admin

Ref: #549, #550
This commit is contained in:
rockstardev 2019-02-10 12:25:51 -06:00 committed by Rockstar Developer
parent f53548d10f
commit b03d89c190
3 changed files with 34 additions and 5 deletions

View File

@ -383,12 +383,29 @@ namespace BTCPayServer.Controllers
var user = userId == null ? null : await _UserManager.FindByIdAsync(userId);
if (user == null)
return NotFound();
return View("Confirm", new ConfirmModel()
var admins = await _UserManager.GetUsersInRoleAsync(Roles.ServerAdmin);
if (admins.Count == 1)
{
Title = "Delete user " + user.Email,
Description = "This user will be permanently deleted",
Action = "Delete"
});
// return
return View("Confirm", new ConfirmModel("Unable to Delete Last Admin",
"This is the last Admin, so it can't be removed"));
}
var roles = await _UserManager.GetRolesAsync(user);
if (IsAdmin(roles))
{
return View("Confirm", new ConfirmModel("Delete Admin " + user.Email,
"Are you sure you want to delete this Admin and delete all accounts, users and data associated with the server account?",
"Delete"));
}
else
{
return View("Confirm", new ConfirmModel("Delete user " + user.Email,
"This user will be permanently deleted",
"Delete"));
}
}
[Route("server/users/{userId}/delete")]

View File

@ -7,6 +7,15 @@ namespace BTCPayServer.Models
{
public class ConfirmModel
{
public ConfirmModel() { }
public ConfirmModel(string title, string desc, string action = null)
{
Title = title;
Description = desc;
Action = action;
}
public string Title
{
get; set;

View File

@ -12,6 +12,8 @@
<p>@Model.Description</p>
</div>
</div>
@if (!String.IsNullOrEmpty(Model.Action))
{
<div class="row">
<div class="col-lg-12 text-center">
<form method="post">
@ -19,5 +21,6 @@
</form>
</div>
</div>
}
</div>
</section>