Verrouille le nom d'utilisateur en edition admin

This commit is contained in:
2026-04-15 22:28:37 +02:00
parent 52d5bf4e98
commit c92df9a8f0
5 changed files with 16 additions and 11 deletions

View File

@@ -2,8 +2,6 @@ namespace ChessCubing.App.Models.Users;
public sealed class AdminUpdateUserRequest public sealed class AdminUpdateUserRequest
{ {
public string Username { get; set; } = string.Empty;
public string? Email { get; set; } public string? Email { get; set; }
public string? FirstName { get; set; } public string? FirstName { get; set; }

View File

@@ -308,7 +308,11 @@
<div class="admin-form-grid admin-edit-form-grid"> <div class="admin-form-grid admin-edit-form-grid">
<label class="field"> <label class="field">
<span>Nom d'utilisateur</span> <span>Nom d'utilisateur</span>
<InputText @bind-Value="EditFormModel.Username" /> <InputText @bind-Value="EditFormModel.Username"
readonly
aria-readonly="true"
title="Le nom d'utilisateur ne peut pas etre modifie."
class="admin-readonly-field" />
<ValidationMessage For="@(() => EditFormModel.Username)" /> <ValidationMessage For="@(() => EditFormModel.Username)" />
</label> </label>
@@ -789,7 +793,6 @@
{ {
var payload = new AdminUpdateUserRequest var payload = new AdminUpdateUserRequest
{ {
Username = EditFormModel.Username ?? string.Empty,
Email = EditFormModel.Email, Email = EditFormModel.Email,
FirstName = EditFormModel.FirstName, FirstName = EditFormModel.FirstName,
LastName = EditFormModel.LastName, LastName = EditFormModel.LastName,

View File

@@ -70,8 +70,6 @@ public sealed class AdminUserDetailResponse
public sealed class AdminUpdateUserRequest public sealed class AdminUpdateUserRequest
{ {
public string Username { get; init; } = string.Empty;
public string? Email { get; init; } public string? Email { get; init; }
public string? FirstName { get; init; } public string? FirstName { get; init; }

View File

@@ -251,8 +251,9 @@ adminGroup.MapPut("/users/{subject}", async Task<IResult> (
{ {
try try
{ {
var existingIdentity = await keycloak.GetAdminUserAsync(subject, cancellationToken);
var normalized = NormalizeAdminUpdate(request); var normalized = NormalizeAdminUpdate(request);
var fallbackDisplayName = BuildIdentityDisplayNameFromParts(normalized.FirstName, normalized.LastName, normalized.Username); var fallbackDisplayName = BuildIdentityDisplayNameFromParts(normalized.FirstName, normalized.LastName, existingIdentity.Username);
var siteProfileRequest = new UpdateUserProfileRequest var siteProfileRequest = new UpdateUserProfileRequest
{ {
DisplayName = request.DisplayName, DisplayName = request.DisplayName,
@@ -268,7 +269,7 @@ adminGroup.MapPut("/users/{subject}", async Task<IResult> (
var updatedIdentity = await keycloak.UpdateAdminUserAsync( var updatedIdentity = await keycloak.UpdateAdminUserAsync(
subject, subject,
new AdminIdentityUserUpdateRequest( new AdminIdentityUserUpdateRequest(
normalized.Username, existingIdentity.Username,
normalized.Email, normalized.Email,
normalized.FirstName, normalized.FirstName,
normalized.LastName, normalized.LastName,
@@ -421,13 +422,11 @@ static AdminUserDetailResponse MapAdminDetail(AdminIdentityUser identity, UserPr
static NormalizedAdminUserUpdate NormalizeAdminUpdate(AdminUpdateUserRequest request) static NormalizedAdminUserUpdate NormalizeAdminUpdate(AdminUpdateUserRequest request)
{ {
var username = NormalizeRequiredValue(request.Username, "nom d'utilisateur", 120);
var email = NormalizeEmail(request.Email); var email = NormalizeEmail(request.Email);
var firstName = NormalizeOptionalValue(request.FirstName, "prenom", 120); var firstName = NormalizeOptionalValue(request.FirstName, "prenom", 120);
var lastName = NormalizeOptionalValue(request.LastName, "nom", 120); var lastName = NormalizeOptionalValue(request.LastName, "nom", 120);
return new NormalizedAdminUserUpdate( return new NormalizedAdminUserUpdate(
username,
email, email,
firstName, firstName,
lastName, lastName,
@@ -575,7 +574,6 @@ static async Task SignInAsync(HttpContext httpContext, KeycloakUserInfo userInfo
} }
sealed record NormalizedAdminUserUpdate( sealed record NormalizedAdminUserUpdate(
string Username,
string? Email, string? Email,
string? FirstName, string? FirstName,
string? LastName, string? LastName,

View File

@@ -1868,6 +1868,14 @@ body.site-menu-hidden .site-menu-shell {
min-height: 3.3rem; min-height: 3.3rem;
} }
.admin-edit-modal-card input[readonly],
.admin-readonly-field {
color: rgba(255, 255, 255, 0.86);
background: rgba(255, 255, 255, 0.025);
border-color: rgba(255, 255, 255, 0.12);
cursor: default;
}
.admin-edit-modal-card .profile-feedback { .admin-edit-modal-card .profile-feedback {
margin-bottom: 0.55rem; margin-bottom: 0.55rem;
padding: 0.65rem 0.8rem; padding: 0.65rem 0.8rem;