mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Adds authorization roles administrator dashboard
This commit is contained in:
1 parent
290af03c83
commit
1df31515fb
191 files changed
+6189
-806
No files matched your search
@@ -0,0 +1,15 @@
|
||||
namespace Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Class for the collection of routes defined in this API.
|
||||
/// </summary>
|
||||
public static partial class ApiRoutes
|
||||
{
|
||||
/// <summary>
|
||||
/// Routes for the Permissions route.
|
||||
/// </summary>
|
||||
public static class Permissions
|
||||
{
|
||||
public const string GET_PERMISSIONS = "/permissions";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Class for the collection of routes defined in this API.
|
||||
/// </summary>
|
||||
public static partial class ApiRoutes
|
||||
{
|
||||
/// <summary>
|
||||
/// Routes for the Roles route.
|
||||
/// </summary>
|
||||
public static class Roles
|
||||
{
|
||||
public const string GET_ROLE_PERMISSIONS_BY_ROLE_ID = "/roles/{roleId}/permissions";
|
||||
public const string GET_ROLES = "/roles";
|
||||
public const string CREATE_ROLE = "/roles";
|
||||
public const string UPDATE_ROLE = "/roles";
|
||||
public const string DELETE_ROLE = "/roles/{roleId}";
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Core.Admin.Authorization.Permissions.Queries.GetPermissions;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Permissions.GetPermissions;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/permissions</c> route.
|
||||
/// </summary>
|
||||
public class GetPermissionsEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPermissionsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public GetPermissionsEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Permissions.GET_PERMISSIONS);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of authorization permissions.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<PermissionResponse>> result = await _sender.Send(new GetPermissionsQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Permissions.GetPermissions;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetPermissionsEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPermissionsEndpointSummary : Summary<GetPermissionsEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPermissionsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetPermissionsEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the collection of authorization permissions.";
|
||||
Description = "Gets the entire list of authorization permissions.";
|
||||
|
||||
Response(200, "The authorization permissions are returned.",
|
||||
example: new[] {
|
||||
new PermissionResponse(Id: Guid.NewGuid(), AuthorizationPermission.CanViewUsers),
|
||||
new PermissionResponse(Id: Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers),
|
||||
new PermissionResponse(Id: Guid.NewGuid(), AuthorizationPermission.CanRegisterUsers)
|
||||
});
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/permissions"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/permissions"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/permissions"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the current user is not an Admin.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/permissions",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.AddRole;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/roles</c> route.
|
||||
/// </summary>
|
||||
public class AddRoleEndpoint : BaseEndpoint<AddRoleRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddRoleEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public AddRoleEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.POST);
|
||||
Routes(ApiRoutes.Roles.CREATE_ROLE);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new authorization role.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the authorization role to be created.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(AddRoleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<RolePermissionsResponse> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.DTO.Authentication;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.AddRole;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="AddRoleEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddRoleEndpointSummary : Summary<AddRoleEndpoint, AddRoleRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddRoleEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public AddRoleEndpointSummary()
|
||||
{
|
||||
Summary = "Adds a new authorization role.";
|
||||
Description = "Creates a new authorization role and returns its details.";
|
||||
|
||||
ExampleRequest = new AddRoleRequest(
|
||||
RoleName: "Editor",
|
||||
Permissions: [
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
]
|
||||
);
|
||||
|
||||
RequestParam(r => r.RoleName, "The name of the role. Required.");
|
||||
RequestParam(r => r.Permissions, "The collection or permissions of the role. Required.");
|
||||
|
||||
ResponseParam<RolePermissionsResponse>(r => r.Role, "The authorization role entity.");
|
||||
ResponseParam<RolePermissionsResponse>(r => r.Permissions, "The list of permissions of the role entity.");
|
||||
|
||||
|
||||
Response(200, "The authorization role was successfully created.", example:
|
||||
new RolePermissionsResponse(
|
||||
Role: new RoleDto(Id: Guid.NewGuid(), "Editor"),
|
||||
Permissions: [new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers), new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanViewUsers)]
|
||||
));
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/roles"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/roles"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/roles"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the current user is not an Admin.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/roles",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed due to a conflict, role already exists.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "RoleAlreadyExists",
|
||||
instance = "/api/v1/roles",
|
||||
traceId = "00-f8784de7cb2d70b81b2529893068bee7-4779e0404fe5f554-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/roles",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"RoleNameCannotBeNull",
|
||||
"RoleNameCannotBeEmpty",
|
||||
"PermissionsListCannotBeNull",
|
||||
"PermissionsListCannotBeEmpty",
|
||||
"PermissionIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.DeleteRole;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/roles</c> route.
|
||||
/// </summary>
|
||||
public class DeleteRoleEndpoint : BaseEndpoint<DeleteRoleRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteRoleEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public DeleteRoleEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.DELETE);
|
||||
Routes(ApiRoutes.Roles.DELETE_ROLE);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an authorization role.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Id of the authorization role to be deleted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(DeleteRoleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<Deleted> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.NoContent(), Problem);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.GetRolePermissions;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/roles/{roleId}/permissions</c> route.
|
||||
/// </summary>
|
||||
public class GetRolePermissionsEndpoint : BaseEndpoint<GetRolePermissionsRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRolePermissionsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public GetRolePermissionsEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Roles.GET_ROLE_PERMISSIONS_BY_ROLE_ID);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of authorization permissions of a role identified by Id.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the id of the role for which to get the list of permissions.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetRolePermissionsRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<RolePermissionsResponse> result = await _sender.Send(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.GetRolePermissions;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetRolePermissionsEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetRolePermissionsEndpointSummary : Summary<GetRolePermissionsEndpoint, GetRolePermissionsRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRolePermissionsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetRolePermissionsEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the collection of authorization permissions of a role.";
|
||||
Description = "Gets the entire list of authorization permissions of a role.";
|
||||
|
||||
ExampleRequest = new GetRolePermissionsRequest(
|
||||
RoleId: Guid.NewGuid()
|
||||
);
|
||||
|
||||
RequestParam(r => r.RoleId, "The Id of authorization role. Required.");
|
||||
|
||||
Response(200, "The authorization permissions are returned.",
|
||||
example: new[] {
|
||||
new PermissionResponse(Id: Guid.NewGuid(), AuthorizationPermission.CanViewUsers),
|
||||
new PermissionResponse(Id: Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers),
|
||||
new PermissionResponse(Id: Guid.NewGuid(), AuthorizationPermission.CanRegisterUsers)
|
||||
});
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/roles/{roleId}/permissions"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/roles/{roleId}/permissions"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/roles/{roleId}/permissions"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the current user is not an Admin.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/roles/{roleId}/permissions",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the requested authorization role does not exist.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "RoleNotFound",
|
||||
instance = "/api/v1/roles/{roleId}/permissions",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/roles/{roleId}/permissions",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"RoleIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.GetRoles;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/roles</c> route.
|
||||
/// </summary>
|
||||
public class GetRolesEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRolesEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public GetRolesEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Roles.GET_ROLES);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of authorization roles.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<RoleResponse>> result = await _sender.Send(new GetRolesQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.GetRoles;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetRolesEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPermissionsEndpointSummary : Summary<GetRolesEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPermissionsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetPermissionsEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the collection of authorization roles.";
|
||||
Description = "Gets the entire list of authorization roles.";
|
||||
|
||||
Response(200, "The authorization roles are returned.",
|
||||
example: new[] {
|
||||
new RoleResponse(Id: Guid.NewGuid(), "Admin")
|
||||
});
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/roles"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/roles"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/roles"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the current user is not an Admin.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/roles",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.UpdateRole;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/roles</c> route.
|
||||
/// </summary>
|
||||
public class UpdateRoleEndpoint : BaseEndpoint<UpdateRoleRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateRoleEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public UpdateRoleEndpoint(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.PUT);
|
||||
Routes(ApiRoutes.Roles.UPDATE_ROLE);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing authorization role.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the authorization role to be updated.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(UpdateRoleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<RolePermissionsResponse> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.DTO.Authentication;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.UpdateRole;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="UpdateRoleEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateRoleEndpointSummary : Summary<UpdateRoleEndpoint, UpdateRoleRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateRoleEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public UpdateRoleEndpointSummary()
|
||||
{
|
||||
Summary = "Updates an existing authorization role.";
|
||||
Description = "Updates an existing authorization role and returns its details.";
|
||||
|
||||
ExampleRequest = new UpdateRoleRequest(
|
||||
RoleId: Guid.NewGuid(),
|
||||
RoleName: "Editor",
|
||||
Permissions: [
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
]
|
||||
);
|
||||
|
||||
RequestParam(r => r.RoleId, "The Id of the role. Required.");
|
||||
RequestParam(r => r.RoleName, "The name of the role. Required.");
|
||||
RequestParam(r => r.Permissions, "The collection or permissions of the role. Required.");
|
||||
|
||||
ResponseParam<RolePermissionsResponse>(r => r.Role, "The authorization role entity.");
|
||||
ResponseParam<RolePermissionsResponse>(r => r.Permissions, "The list of permissions of the role entity.");
|
||||
|
||||
|
||||
Response(200, "The authorization role was successfully updated.", example:
|
||||
new RolePermissionsResponse(
|
||||
Role: new RoleDto(Id: Guid.NewGuid(), "Editor"),
|
||||
Permissions: [new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers), new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanViewUsers)]
|
||||
));
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/roles"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/roles"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/roles"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the current user is not an Admin.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Failure",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/roles",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the provided role does not exist.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "RoleNotFound",
|
||||
instance = "/api/v1/roles",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/roles",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"RoleNameCannotBeNull",
|
||||
"RoleNameCannotBeEmpty",
|
||||
"PermissionsListCannotBeNull",
|
||||
"PermissionsListCannotBeEmpty",
|
||||
"PermissionIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class AddLibraryEndpoint : BaseEndpoint<AddLibraryRequest, IResult>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(AddLibraryRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// retrieve the currently authenticated user, and send it with the request
|
||||
// retrieve the currently authenticated user, and send it with the request // TODO: replace with current user service
|
||||
string? user = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
ErrorOr<LibraryResponse> result = await _sender.Send(request.ToCommand(Guid.Parse(user!)), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1{ApiRoutes.Libraries.ADD_LIBRARY}/{result.Value.Id}", result.Value), Problem);
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.GetBook;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBook;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/books/{id}</c> route.
|
||||
+3
-3
@@ -43,13 +43,13 @@ public class GetAuthorizationEndpoint : BaseEndpoint<GetAuthorizationRequest, IR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the authentication roles and permissions of an account.
|
||||
/// Gets the authorization roles and permissions of an account.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the account for which to get the authentication roles and permissions.</param>
|
||||
/// <param name="request">The request containing the account for which to get the authorization roles and permissions.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetAuthorizationRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<GetAuthorizationResponse> result = await _sender.Send(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
ErrorOr<AuthorizationResponse> result = await _sender.Send(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -31,9 +31,9 @@ public class GetAuthorizationEndpointSummary : Summary<GetAuthorizationEndpoint,
|
||||
RequestParam(r => r.UserId, "The Id of the user for whom to get the authorization. Required.");
|
||||
|
||||
Response(200, "The authorization roles and permissions of the account are returned.",
|
||||
example: new GetAuthorizationResponse(
|
||||
example: new AuthorizationResponse(
|
||||
UserId: Guid.NewGuid(),
|
||||
Roles: new HashSet<AuthorizationRole>() { AuthorizationRole.Admin },
|
||||
Roles: new HashSet<string>() { "Admin" },
|
||||
Permissions: new HashSet<AuthorizationPermission>() { AuthorizationPermission.CanRegisterUsers, AuthorizationPermission.CanDeleteUsers }
|
||||
));
|
||||
|
||||
|
||||
Reference in new issue
Block a user