backend + web: Add admin account lifecycle management
This commit is contained in:
1 parent
fcf7cd0596
commit
91d0c06c83
25 files changed
+1148
-97
No files matched your search
@@ -52,6 +52,12 @@ public sealed record AdminUserDto(
|
||||
public string FullName => $"{FirstName} {LastName}";
|
||||
}
|
||||
|
||||
public sealed record AdminUserDetailsDto(int Id, string Email, string FirstName, string LastName, string? Phone,
|
||||
string Role, bool IsActive, bool EmailConfirmed, bool EmailNotificationsEnabled, bool? VerificationEmailSent = null);
|
||||
|
||||
public sealed record SaveAdminUserRequest(string Email, string FirstName, string LastName, string? Phone,
|
||||
string Role, bool IsActive, bool EmailConfirmed, bool EmailNotificationsEnabled, string? Password);
|
||||
|
||||
/// <summary>Stránkovaný seznam z API: <c>{ items, totalCount, page, pageSize }</c>.</summary>
|
||||
public sealed record PagedResult<T>(IReadOnlyList<T> Items, int TotalCount, int Page, int PageSize)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
@@ -42,16 +43,52 @@ public sealed class HelpdeskApiClient(HttpClient http)
|
||||
|
||||
public async Task ChangeUserRoleAsync(int id, string role, CancellationToken ct)
|
||||
{
|
||||
using var response = await http.PutAsJsonAsync($"admin/users/{id.ToString(CultureInfo.InvariantCulture)}/role", new { role }, ct);
|
||||
using var response = await http.PutAsJsonAsync(AdminUserPath(id) + "/role", new { role }, ct);
|
||||
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||
}
|
||||
|
||||
public async Task SetUserActiveAsync(int id, bool isActive, CancellationToken ct)
|
||||
{
|
||||
using var response = await http.PutAsJsonAsync($"admin/users/{id.ToString(CultureInfo.InvariantCulture)}/active", new { isActive }, ct);
|
||||
using var response = await http.PutAsJsonAsync(AdminUserPath(id) + "/active", new { isActive }, ct);
|
||||
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||
}
|
||||
|
||||
public async Task<AdminUserDetailsDto> GetAdminUserAsync(int id, CancellationToken ct)
|
||||
{
|
||||
using var response = await http.GetAsync(AdminUserPath(id), ct);
|
||||
return await ApiResponse.ReadAsync<AdminUserDetailsDto>(response, ct);
|
||||
}
|
||||
|
||||
public async Task<AdminUserDetailsDto?> SaveAdminUserAsync(int? id, SaveAdminUserRequest request, CancellationToken ct)
|
||||
{
|
||||
using var response = id is int userId
|
||||
? await http.PutAsJsonAsync(AdminUserPath(userId), request, ct)
|
||||
: await http.PostAsJsonAsync("admin/users", request, ct);
|
||||
return response.StatusCode == HttpStatusCode.NoContent
|
||||
? null
|
||||
: await ApiResponse.ReadAsync<AdminUserDetailsDto>(response, ct);
|
||||
}
|
||||
|
||||
public async Task SendAdminUserEmailConfirmationAsync(int id, CancellationToken ct)
|
||||
{
|
||||
using var response = await http.PostAsync(AdminUserPath(id) + "/email-confirmation", null, ct);
|
||||
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||
}
|
||||
|
||||
public async Task DeleteAdminUserAsync(int id, CancellationToken ct)
|
||||
{
|
||||
using var response = await http.DeleteAsync(AdminUserPath(id), ct);
|
||||
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||
}
|
||||
|
||||
public async Task UpdateAdminUsersAsync(int[] userIds, string action, string? role, CancellationToken ct)
|
||||
{
|
||||
using var response = await http.PostAsJsonAsync("admin/users/bulk", new { userIds, action, role }, ct);
|
||||
await ApiResponse.EnsureSuccessAsync(response, ct);
|
||||
}
|
||||
|
||||
private static string AdminUserPath(int id) => $"admin/users/{id.ToString(CultureInfo.InvariantCulture)}";
|
||||
|
||||
public async Task<PagedResult<IssueSummary>> GetIssuesAsync(IssueListQuery query, CancellationToken ct)
|
||||
{
|
||||
var parameters = new Dictionary<string, string?>
|
||||
|
||||
Reference in new issue
Block a user