Enhance role selection functionality in ListSelectableRolesQueryHandler and update frontend role display
CI / Backend (build + test) (push) Successful in 1m22s
CI / Frontend (lint + typecheck + build) (push) Successful in 44s

- Updated ListSelectableRolesQueryHandler to include IIdentityService and ICurrentUser for user authorization and profile retrieval.
- Added logic to filter out the current user's role and admin roles from the selectable roles list.
- Enhanced CreateRoleRequestDialog to display role options with additional information, including max configs and IP limits, using localization support.
- Updated i18n resources to include new role option formatting for both Russian and English.
This commit is contained in:
Leonid Pershin
2026-07-14 23:31:56 +03:00
parent 8f6807a456
commit b6bffcc302
4 changed files with 114 additions and 3 deletions
@@ -1,11 +1,15 @@
using PnvPanel.Application.Auth;
using PnvPanel.Application.Common.Interfaces;
using PnvPanel.Application.Common.Messaging;
using PnvPanel.Application.Common.Models;
namespace PnvPanel.Application.Support.ListSelectableRoles;
public sealed class ListSelectableRolesQueryHandler(IRoleService roleService)
: IQueryHandler<ListSelectableRolesQuery, Result<IReadOnlyList<RoleDto>>>
public sealed class ListSelectableRolesQueryHandler(
IRoleService roleService,
IIdentityService identityService,
ICurrentUser currentUser
) : IQueryHandler<ListSelectableRolesQuery, Result<IReadOnlyList<RoleDto>>>
{
// Совпадает со значением Infrastructure.Identity.RoleNames.Admin — см. пояснение в
// CreateRoleRequestTicketCommandHandler (Application не может ссылаться на Infrastructure).
@@ -16,9 +20,16 @@ public sealed class ListSelectableRolesQueryHandler(IRoleService roleService)
CancellationToken cancellationToken
)
{
if (currentUser.UserId is not { } userId)
return Result.Failure<IReadOnlyList<RoleDto>>(AuthErrors.Unauthorized);
var profile = await identityService.GetProfileAsync(userId, cancellationToken);
var roles = await roleService.ListRolesAsync(cancellationToken);
// Без admin (нельзя запросить) и без текущей роли пользователя (уже есть — нечего запрашивать).
var selectable = roles
.Where(r => !r.Name.Equals(AdminRoleName, StringComparison.OrdinalIgnoreCase))
.Where(r => profile is null || r.Id != profile.RoleId)
.ToList();
return Result.Success<IReadOnlyList<RoleDto>>(selectable);