From e5b2335432cce7a834ab4ef64caee067688d8f22 Mon Sep 17 00:00:00 2001 From: Avazbek Olimov Date: Sun, 10 Aug 2025 23:13:45 +0300 Subject: [PATCH] fix --- .../Commands/DeleteMyAccountCommandHandler.cs | 4 ++++ src/Client/Client/Pages/Clients/Account.razor | 15 +++++++++++---- src/Client/Client/Pages/Clients/Account.razor.cs | 7 ++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Application/Features/Account/Commands/DeleteMyAccountCommandHandler.cs b/src/Application/Features/Account/Commands/DeleteMyAccountCommandHandler.cs index aee287d1..aae21f7e 100644 --- a/src/Application/Features/Account/Commands/DeleteMyAccountCommandHandler.cs +++ b/src/Application/Features/Account/Commands/DeleteMyAccountCommandHandler.cs @@ -2,6 +2,7 @@ using Application.Common.Exceptions; using Application.Common.Interfaces.Services; using Application.Contract.Account.Commands; +using Application.Contract.Identity; using Domain.Entities; using MediatR; using Microsoft.AspNetCore.Identity; @@ -23,6 +24,9 @@ public async Task Handle(DeleteMyAccountCommand request, CancellationToken var user = await userManager.FindByNameAsync(userName) ?? throw new NotFoundException("Пользователь не найден."); + + if (await userManager.IsInRoleAsync(user, ApplicationRoles.SuperAdmin)) + throw new ForbiddenException("Нельзя удалить аккаунт супер-администратора."); var res = await userManager.DeleteAsync(user); res.ThrowBadRequestIfError(); diff --git a/src/Client/Client/Pages/Clients/Account.razor b/src/Client/Client/Pages/Clients/Account.razor index c3eb9a6f..71c37550 100644 --- a/src/Client/Client/Pages/Clients/Account.razor +++ b/src/Client/Client/Pages/Clients/Account.razor @@ -165,7 +165,8 @@ else { - Мы отправим письмо с кодом подтверждения на @_email.NewEmail. Подтвердите адрес — и он + Мы отправим письмо с кодом подтверждения на @_email.NewEmail. Подтвердите + адрес — и он будет добавлен к вашему аккаунту. @@ -236,7 +237,8 @@ else { - Мы отправим SMS с кодом подтверждения на +7-@_phone. Подтвердите номер — и он будет + Мы отправим SMS с кодом подтверждения на +7-@_phone. Подтвердите номер — и он + будет добавлен к вашему аккаунту. @@ -322,7 +324,6 @@ else Сессии - Удалить аккаунт + @if (_isSuperAdmin) + { + + Учетная запись супер-администратора не может быть удалена. + + } diff --git a/src/Client/Client/Pages/Clients/Account.razor.cs b/src/Client/Client/Pages/Clients/Account.razor.cs index 3defbe61..29a8dbd3 100644 --- a/src/Client/Client/Pages/Clients/Account.razor.cs +++ b/src/Client/Client/Pages/Clients/Account.razor.cs @@ -1,6 +1,7 @@ using System.Text.RegularExpressions; using Application.Contract.Account.Commands; using Application.Contract.Account.Responses; +using Application.Contract.Identity; using Application.Contract.Verification.Commands; using Client.Infrastructure.Auth; using Client.Infrastructure.Services.Verification; @@ -48,7 +49,8 @@ public partial class Account // Подсказки/прогресс по отправке кодов private bool _promptEmailConfirm, _promptPhoneConfirm; private bool _sendingEmailCode, _sendingPhoneCode; - + private bool _isSuperAdmin; + protected override async Task OnInitializedAsync() { var myAccountResponse = await AccountService.GetAsync(); @@ -59,6 +61,9 @@ protected override async Task OnInitializedAsync() } _account = myAccountResponse; + + var auth = await AuthState.GetAuthenticationStateAsync(); + _isSuperAdmin = auth.User.IsInRole(ApplicationRoles.SuperAdmin); // Уже заполненные значения в TextField-ах _profile.Name = myAccountResponse.Name;