mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
Rewords additional code comments as complete sentences
This commit is contained in:
1 parent
36e43b7999
commit
871644b3c9
23 files changed
+171
-140
No files matched your search
+7
-6
@@ -1,14 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -49,17 +50,17 @@ public class GetPermissionsQueryHandler : IQueryHandler<GetPermissionsQuery, Res
|
||||
/// </returns>
|
||||
public async Task<Result<IEnumerable<PermissionResponse>>> HandleAsync(GetPermissionsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// an authenticated request must always carry a user identity
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// only admins can see the list of authorization permissions
|
||||
// Only admins can see the list of authorization permissions.
|
||||
bool isAdmin = await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (!isAdmin)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Result<IEnumerable<PermissionEntity>> getPermissionsResult = await _unitOfWork.PermissionRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getPermissionsResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
Result<PaginatedResultDto<PermissionEntity>> getPermissionsResult = await _unitOfWork.PermissionRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return getPermissionsResult.Match(value => Result.From(value.Data.ToResponses()), errors => errors);
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
@@ -10,6 +9,7 @@ using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -57,18 +57,19 @@ public class GetRolePermissionsQueryHandler : IQueryHandler<GetRolePermissionsQu
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// an authenticated request must always carry a user identity
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// only admins can see the list of authorization roles
|
||||
// Only admins can see the list of authorization roles.
|
||||
bool isAdmin = await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (!isAdmin)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
// get the role from the repository and return its role permissions
|
||||
Result<RoleEntity?> getRoleResult = await _roleRepository.GetByIdAsync(request.RoleId, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// Get the role from the repository and return its role permissions.
|
||||
Result<RoleEntity?> getRoleResult = await _roleRepository.GetByIdAsync(request.RoleId, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getRoleResult.IsFailure)
|
||||
return getRoleResult.Errors;
|
||||
else if (getRoleResult.Value is null)
|
||||
|
||||
+8
-5
@@ -1,14 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -49,17 +51,18 @@ public class GetRolesQueryHandler : IQueryHandler<GetRolesQuery, Result<IEnumera
|
||||
/// </returns>
|
||||
public async Task<Result<IEnumerable<RoleResponse>>> HandleAsync(GetRolesQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// an authenticated request must always carry a user identity
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// only admins can see the list of authorization roles
|
||||
// Only admins can see the list of authorization roles.
|
||||
bool isAdmin = await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (!isAdmin)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Result<IEnumerable<RoleEntity>> getRolesResult = await _roleRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getRolesResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
|
||||
Result<PaginatedResultDto<RoleEntity>> getRolesResult = await _roleRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return getRolesResult.Match(value => Result.From(value.Data.ToResponses()), errors => errors);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Contracts.Responses.UsersManagement;
|
||||
using System.Collections.Generic;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -38,10 +38,10 @@ public class CheckInitializationQueryHandler : IQueryHandler<CheckInitialization
|
||||
/// </returns>
|
||||
public async Task<InitializationResponse> HandleAsync(CheckInitializationQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// if the repository reports an error, or there are no users, the application has not been initialized
|
||||
Result<IEnumerable<UserEntity>> selectUsersResult = await _unitOfWork.UserRepository.GetAllAsync(cancellationToken);
|
||||
// If the repository reports an error, or there are no users, the application has not been initialized.
|
||||
Result<PaginatedResultDto<UserEntity>> selectUsersResult = await _unitOfWork.UserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken);
|
||||
if (!selectUsersResult.IsFailure)
|
||||
return new InitializationResponse(selectUsersResult.Value.Any());
|
||||
return new InitializationResponse(selectUsersResult.Value.Data.Any());
|
||||
return new InitializationResponse(false);
|
||||
}
|
||||
}
|
||||
+9
-7
@@ -4,6 +4,8 @@ using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
@@ -53,24 +55,24 @@ public class GetLibrariesQueryHandler : IQueryHandler<GetLibrariesQuery, Result<
|
||||
/// </returns>
|
||||
public async Task<Result<LibraryResponse[]>> HandleAsync(GetLibrariesQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// an authenticated request must always carry a user identity
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// get the libraries from the repository
|
||||
Result<IEnumerable<LibraryEntity>> getLibrariesResult = await _unitOfWork.LibraryRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
// Get the libraries from the repository.
|
||||
Result<PaginatedResultDto<LibraryEntity>> getLibrariesResult = await _unitOfWork.LibraryRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getLibrariesResult.IsFailure)
|
||||
return getLibrariesResult.Errors;
|
||||
|
||||
// admins can see all libraries
|
||||
// Admins can see all libraries.
|
||||
if (await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false))
|
||||
return Result.From(getLibrariesResult.Value.Select(library => library.ToResponse()).ToArray());
|
||||
return Result.From(getLibrariesResult.Value.Data.Select(library => library.ToResponse()).ToArray());
|
||||
else
|
||||
{
|
||||
// for regular users, only take the libraries that belong to them
|
||||
LibraryResponse[] userLibraries = [.. getLibrariesResult.Value
|
||||
// For regular users, only take the libraries that belong to them.
|
||||
LibraryResponse[] userLibraries = [.. getLibrariesResult.Value.Data
|
||||
.Where(library => library.UserId == userId)
|
||||
.Select(library => library.ToResponse())];
|
||||
|
||||
|
||||
+2
-2
@@ -53,14 +53,14 @@ public class GetPluginSettingsQueryHandler : IQueryHandler<GetPluginSettingsQuer
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
Result<PluginEntity?> getPluginResult = await _unitOfWork.PluginRepository.GetByIdAsync(query.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
Result<PluginEntity?> getPluginResult = await _unitOfWork.PluginRepository.GetByIdAsync(query.PluginId, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginResult.IsFailure)
|
||||
return getPluginResult.Errors;
|
||||
PluginEntity? pluginEntity = getPluginResult.Value;
|
||||
if (pluginEntity is null)
|
||||
return Errors.Plugins.PluginNotFound;
|
||||
|
||||
// the schema comes from the loaded plugin, the current values from the storage medium
|
||||
// The schema comes from the loaded plugin, the current values from the storage medium.
|
||||
IPlugin? loadedPlugin = _pluginManager.GetPlugin(query.PluginId);
|
||||
IReadOnlyList<PluginSettingDescriptorResponse> schema = loadedPlugin is not null
|
||||
? loadedPlugin.GetSettingsSchema().Select(setting => setting.ToResponse()).ToList()
|
||||
|
||||
+6
-4
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Mapping.Themes;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -41,14 +43,14 @@ public class GetThemesQueryHandler : IQueryHandler<GetThemesQuery, Result<IReadO
|
||||
/// </returns>
|
||||
public async Task<Result<IReadOnlyList<ThemeResponse>>> HandleAsync(GetThemesQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<IEnumerable<ThemeEntity>> getThemesResult = await _unitOfWork.ThemeRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
Result<PaginatedResultDto<ThemeEntity>> getThemesResult = await _unitOfWork.ThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getThemesResult.IsFailure)
|
||||
return getThemesResult.Errors;
|
||||
|
||||
// deleted bundled themes are returned as well, so the administration page can offer to restore them
|
||||
return Result.From<IReadOnlyList<ThemeResponse>>([.. getThemesResult.Value
|
||||
// Deleted bundled themes are returned as well, so the administration page can offer to restore them.
|
||||
return Result.From<IReadOnlyList<ThemeResponse>>([.. getThemesResult.Value.Data
|
||||
.OrderBy(theme => theme.IsDeleted)
|
||||
// the shipped bundled themes are listed before the user themes, so the defaults stay the most visible
|
||||
// The shipped bundled themes are listed before the user themes, so the defaults stay the most visible.
|
||||
.ThenByDescending(theme => theme.InstallSource == ThemeInstallSource.Bundled)
|
||||
.ThenBy(theme => theme.Name, StringComparer.OrdinalIgnoreCase)
|
||||
.Select(theme => theme.ToResponse())]);
|
||||
|
||||
+6
-4
@@ -4,6 +4,8 @@ using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
@@ -50,17 +52,17 @@ public class GetUsersQueryHandler : IQueryHandler<GetUsersQuery, Result<IEnumera
|
||||
/// </returns>
|
||||
public async Task<Result<IEnumerable<UserResponse>>> HandleAsync(GetUsersQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// an authenticated request must always carry a user identity
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// only admins can see the list of users
|
||||
// Only admins can see the list of users.
|
||||
bool isAdmin = await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (!isAdmin)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
Result<IEnumerable<UserEntity>> getRolesResult = await _unitOfWork.UserRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getRolesResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
Result<PaginatedResultDto<UserEntity>> getRolesResult = await _unitOfWork.UserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return getRolesResult.Match(value => Result.From(value.Data.ToResponses()), errors => errors);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user