Enhance user management: prevent deletion of the last admin user and restrict admin type changes for the last admin account
All checks were successful
Build And Push Dev Docker Image / docker (push) Successful in 1m47s

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
a.beging@eas-solutions.de
2026-04-30 09:53:05 +02:00
parent c4d7fd6ed5
commit cefa47a176
3 changed files with 28 additions and 11 deletions

View File

@@ -57,6 +57,11 @@ namespace FoodsharingSiegen.Server.Pages
/// </summary>
private bool IsEditing { get; set; }
/// <summary>
/// Gets a value indicating whether the current editing user is the last admin
/// </summary>
private bool IsLastAdmin => IsEditing && EditModel?.Type == UserType.Admin && UserList?.Count(x => x.Type == UserType.Admin) <= 1;
/// <summary>
/// Gets the value of the user groups (ab)
/// </summary>
@@ -184,12 +189,6 @@ namespace FoodsharingSiegen.Server.Pages
/// <returns>A task that represents the asynchronous remove operation.</returns>
private async Task RemoveUserAsync(User user)
{
if (user.IsAdmin())
{
await Notification.Error("Admins können nicht gelöscht werden!");
return;
}
await ConfirmDialog.ShowAsync(ModalService, "Bestätigen", $"User {user.Mail} löschen?", async () =>
{
var removeR = await UserService.RemoveAsync(user.Id);