From b03d89c190e82f175e90ab945f059cbb249bce55 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Sun, 10 Feb 2019 12:25:51 -0600 Subject: [PATCH] Different message for admin deletion, check not to delete last admin Ref: #549, #550 --- BTCPayServer/Controllers/ServerController.cs | 27 ++++++++++++++++---- BTCPayServer/Models/ConfirmModel.cs | 9 +++++++ BTCPayServer/Views/Shared/Confirm.cshtml | 3 +++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/BTCPayServer/Controllers/ServerController.cs b/BTCPayServer/Controllers/ServerController.cs index 6961c4a46..2ee0372cc 100644 --- a/BTCPayServer/Controllers/ServerController.cs +++ b/BTCPayServer/Controllers/ServerController.cs @@ -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")] diff --git a/BTCPayServer/Models/ConfirmModel.cs b/BTCPayServer/Models/ConfirmModel.cs index a882e9ef8..b56f4274a 100644 --- a/BTCPayServer/Models/ConfirmModel.cs +++ b/BTCPayServer/Models/ConfirmModel.cs @@ -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; diff --git a/BTCPayServer/Views/Shared/Confirm.cshtml b/BTCPayServer/Views/Shared/Confirm.cshtml index 4a44c7cce..0b9c9a559 100644 --- a/BTCPayServer/Views/Shared/Confirm.cshtml +++ b/BTCPayServer/Views/Shared/Confirm.cshtml @@ -12,6 +12,8 @@

@Model.Description

+ @if (!String.IsNullOrEmpty(Model.Action)) + {
@@ -19,5 +21,6 @@
+ }