mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 05: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
-1
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Mediator;
|
||||
using System;
|
||||
|
||||
+5
-5
@@ -62,11 +62,11 @@ public class AddLibraryCommandHandler : IRequestHandler<AddLibraryCommand, Error
|
||||
return insertLibraryResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
// retrieve the newly saved media library from the persistence medium and return it
|
||||
ErrorOr<LibraryEntity?> retrievedLibraryResult = await libraryRepository.GetByIdAsync(createLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (retrievedLibraryResult.IsError)
|
||||
return retrievedLibraryResult.Errors;
|
||||
if (retrievedLibraryResult.Value is null)
|
||||
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(createLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsError)
|
||||
return getLibraryResult.Errors;
|
||||
if (getLibraryResult.Value is null)
|
||||
return Errors.Persistence.ErrorPersistingMediaLibrary;
|
||||
return retrievedLibraryResult.Value.ToResponse();
|
||||
return getLibraryResult.Value.ToResponse();
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -46,13 +46,13 @@ public class UpdateLibraryCommandHandler : IRequestHandler<UpdateLibraryCommand,
|
||||
{
|
||||
// get a library repository
|
||||
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
|
||||
ErrorOr<LibraryEntity?> resultGetLibrary = await libraryRepository.GetByIdAsync(request.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (resultGetLibrary.IsError)
|
||||
return resultGetLibrary.Errors;
|
||||
else if (resultGetLibrary.Value is null)
|
||||
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(request.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsError)
|
||||
return getLibraryResult.Errors;
|
||||
else if (getLibraryResult.Value is null)
|
||||
return DomainErrors.Library.LibraryNotFound;
|
||||
// if the user that made the request is not an Admin or is not the owner of the library, they do not have the right to update it
|
||||
if (resultGetLibrary.Value.UserId != request.CurrentUserId) // TODO: after implementing the Admin role, add that permission check here too
|
||||
if (getLibraryResult.Value.UserId != request.CurrentUserId) // TODO: after implementing the Admin role, add that permission check here too
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
// create a domain library object
|
||||
@@ -75,11 +75,11 @@ public class UpdateLibraryCommandHandler : IRequestHandler<UpdateLibraryCommand,
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// retrieve the updated media library from the persistence medium and return it
|
||||
ErrorOr<LibraryEntity?> retrievedLibraryResult = await libraryRepository.GetByIdAsync(createLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (retrievedLibraryResult.IsError)
|
||||
return retrievedLibraryResult.Errors;
|
||||
if (retrievedLibraryResult.Value is null)
|
||||
ErrorOr<LibraryEntity?> getCreatedLibraryResult = await libraryRepository.GetByIdAsync(createLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getCreatedLibraryResult.IsError)
|
||||
return getCreatedLibraryResult.Errors;
|
||||
if (getCreatedLibraryResult.Value is null)
|
||||
return ApplicationErrors.Persistence.ErrorPersistingMediaLibrary;
|
||||
return retrievedLibraryResult.Value.ToResponse();
|
||||
return getCreatedLibraryResult.Value.ToResponse();
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Queries;
|
||||
/// Query for getting a media library by its Id.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the media library to get.</param>
|
||||
/// <param name="UserId">The Id os the user requesting the media library.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
/// <param name="UserId">The Id of the user requesting the media library.</param>
|
||||
[DebuggerDisplay("Id: {Id}")]
|
||||
public record GetLibraryQuery(
|
||||
Guid Id,
|
||||
Guid UserId
|
||||
|
||||
+6
-6
@@ -42,14 +42,14 @@ public class GetLibraryQueryHandler : IRequestHandler<GetLibraryQuery, ErrorOr<L
|
||||
public async ValueTask<ErrorOr<LibraryResponse>> Handle(GetLibraryQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
|
||||
ErrorOr<LibraryEntity?> resultGetLibrary = await libraryRepository.GetByIdAsync(request.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (resultGetLibrary.IsError)
|
||||
return resultGetLibrary.Errors;
|
||||
else if (resultGetLibrary.Value is null)
|
||||
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(request.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsError)
|
||||
return getLibraryResult.Errors;
|
||||
else if (getLibraryResult.Value is null)
|
||||
return DomainErrors.Library.LibraryNotFound;
|
||||
// if the user that requested the library is not an Admin or is not the owner of the library, they do not have the right to view it
|
||||
if (resultGetLibrary.Value.UserId != request.UserId) // TODO: after implementing the Admin role, add that permission check here too
|
||||
if (getLibraryResult.Value.UserId != request.UserId) // TODO: after implementing the Admin role, add that permission check here too
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
return resultGetLibrary.Value.ToResponse();
|
||||
return getLibraryResult.Value.ToResponse();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user