Adds authorization permissions administrator dashboard

This commit is contained in:
BinaryAlley committed 2024-12-22 19:17:47 +02:00
1 parent 152cb48050
commit 583b8db865
106 files changed
+5916 -2085

No files matched your search

@@ -8,6 +8,7 @@ using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.CompilerServices;
@@ -206,7 +207,12 @@ public class ApiHttpClient : IApiHttpClient
string content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
// if the response is successful, deserialize the content to TResponse and return it
if (response.IsSuccessStatusCode)
{
// handle empty content case
if (string.IsNullOrEmpty(content))
return default!;
return JsonSerializer.Deserialize<TResponse>(content, _jsonOptions)!;
}
else
{
ProblemDetailsModel? problemDetails = null;
@@ -52,7 +52,7 @@ public class AuthorizationService : IAuthorizationService
public async Task<bool> IsInRoleAsync(string role, CancellationToken cancellationToken)
{
GetAuthorizationResponse authorization = await GetUserAuthorizationAsync(cancellationToken).ConfigureAwait(false);
return authorization.Roles.Contains(role);
return authorization.Role == role;
}
/// <summary>
@@ -75,7 +75,7 @@ public class AuthorizationService : IAuthorizationService
{
GetAuthorizationResponse authorization = await GetUserAuthorizationAsync(CancellationToken.None);
if (requirement.Roles?.Length > 0 && !requirement.Roles.Any(role => authorization.Roles?.Contains(role) == true))
if (requirement.Roles?.Length > 0 && !requirement.Roles.Any(role => authorization.Role?.Contains(role) == true))
return false;
if (requirement.Permissions?.Length > 0 && !requirement.Permissions.Any(permission => authorization.Permissions.Contains(permission)))
@@ -10,11 +10,11 @@ namespace Lumina.Presentation.Web.Common.Models.Authorization;
/// Represents the response model for an account authorization request.
/// </summary>
/// <param name="UserId">The Id of the user for whom the authorization is retrieved.</param>
/// <param name="Roles">The collection of roles associated to the user.</param>
/// <param name="Role">The role associated to the user.</param>
/// <param name="Permissions">The collection of permissions associated to the user.</param>
[DebuggerDisplay("UserId: {UserId}")]
public record GetAuthorizationResponse(
Guid UserId,
string[] Roles,
string? Role,
AuthorizationPermission[] Permissions
);
@@ -1,15 +1,13 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Enums.Authorization;
using System;
#endregion
namespace Lumina.Presentation.Web.Common.Models.Authorization;
/// <summary>
/// Represents a model for an authorization role.
/// Represents a model for an authorization role with its permissions.
/// </summary>
/// <param name="Id">The Id of the authorization role.</param>
/// <param name="Role">The authorization role.</param>
/// <param name="Permissions">The permissions of the authorization role.</param>
public record RolePermissionsModel(
RoleModel Role,
PermissionModel[] Permissions
@@ -10,7 +10,7 @@ namespace Lumina.Presentation.Web.Common.Models.Authorization;
/// </summary>
/// <param name="RoleId">The Id of the role.</param>
/// <param name="RoleName">The name of the role.</param>
/// <param name="Permissions">The collection or permissions of the role.</param>
/// <param name="Permissions">The collection of Ids of the permissions of the role.</param>
public record UpdateRoleRequestModel(
Guid RoleId,
string? RoleName,
@@ -0,0 +1,18 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Presentation.Web.Common.Models.Authorization;
/// <summary>
/// Represents the request model for updating the authorization role and permissions of a user.
/// </summary>
/// <param name="RoleId">The Id of the user.</param>
/// <param name="RoleId">The Id of the role.</param>
/// <param name="Permissions">The collection of Ids of the permissions of the user.</param>
public record UpdateUserRoleAndPermissionsRequestModel(
Guid UserId,
Guid? RoleId,
List<Guid>? Permissions
);
@@ -0,0 +1,15 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Models.UsersManagement;
#endregion
namespace Lumina.Presentation.Web.Common.Models.Authorization;
/// <summary>
/// Represents a model for a user with its authorization permissions.
/// </summary>
/// <param name="User">The user.</param>
/// <param name="Permissions">The authorization permissions of the user.</param>
public record UserPermissionsModel(
UserModel User,
PermissionModel[] Permissions
);