mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 07: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
+4
-4
@@ -40,15 +40,15 @@ public class LibraryOwnershipPolicy : ILibraryOwnershipPolicy
|
||||
if (context is not LibraryOwnershipPolicyContext libraryContext)
|
||||
return false;
|
||||
|
||||
// admins can access any media library
|
||||
Result<UserEntity?> getUserResult = await _unitOfWork.UserRepository.GetByIdAsync(userId, cancellationToken).ConfigureAwait(false);
|
||||
// Admins can access any media library.
|
||||
Result<UserEntity?> getUserResult = await _unitOfWork.UserRepository.GetByIdAsync(userId, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsFailure || getUserResult.Value is null)
|
||||
return false;
|
||||
if (getUserResult.Value.UserRole?.Role.RoleName == "Admin")
|
||||
return true;
|
||||
|
||||
// regular users can only access the media libraries they own
|
||||
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(libraryContext.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
// Regular users can only access the media libraries they own.
|
||||
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(libraryContext.LibraryId, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsFailure || getLibraryResult.Value is null)
|
||||
return false;
|
||||
return getLibraryResult.Value.UserId == userId;
|
||||
|
||||
@@ -41,11 +41,11 @@ public class Over18Policy : IOver18Policy
|
||||
/// <returns><see langword="true"/> if the policy evaluation succeeds, <see langword="false"/> otherwise.</returns>
|
||||
public async Task<bool> EvaluateAsync(Guid userId, PolicyContext? context, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<UserEntity?> getUserResult = await _unitOfWork.UserRepository.GetByIdAsync(userId, cancellationToken).ConfigureAwait(false);
|
||||
Result<UserEntity?> getUserResult = await _unitOfWork.UserRepository.GetByIdAsync(userId, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsFailure || getUserResult.Value is null)
|
||||
return false;
|
||||
|
||||
// TODO: uncomment when Date of Birth is implemented for users registration
|
||||
// TODO: uncomment when Date of Birth is implemented for users registration.
|
||||
//if (!getUserResult.Value.DateOfBirth.HasValue)
|
||||
// return false;
|
||||
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
@@ -26,16 +27,16 @@ internal static class ScanFailurePublisher
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public static async Task PublishAsync(IServiceScopeFactory serviceScopeFactory, LibraryId libraryId, MediaLibraryScanCompositeId compositeKey, Exception exception, CancellationToken cancellationToken)
|
||||
{
|
||||
// failure reporting is best-effort, a failure to report the failure must not crash the job processing
|
||||
// Failure reporting is best-effort, a failure to report the failure must not crash the job processing.
|
||||
try
|
||||
{
|
||||
await using AsyncServiceScope asyncServiceScope = serviceScopeFactory.CreateAsyncScope();
|
||||
IDomainEventPublisher domainEventPublisher = asyncServiceScope.ServiceProvider.GetService<IDomainEventPublisher>()!;
|
||||
await domainEventPublisher.PublishAsync(new LibraryScanFailedDomainEvent(Guid.NewGuid(), libraryId, compositeKey, DateTime.UtcNow, exception.Message), cancellationToken).ConfigureAwait(false);
|
||||
await domainEventPublisher.PublishAsync(new LibraryScanFailedDomainEvent(Guid.NewGuid(), libraryId, compositeKey, DateTime.UtcNow, Optional<string>.FromNullable(exception.Message)), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// the failure reporting is best-effort, as the exception cannot be reported if the reporting itself fails
|
||||
// The failure reporting is best-effort, as the exception cannot be reported if the reporting itself fails.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,21 +108,21 @@ internal sealed class PluginInstaller : IPluginInstaller
|
||||
{
|
||||
using ZipArchive zipArchive = new(archive);
|
||||
Directory.CreateDirectory(_pluginsDirectory);
|
||||
bool foundAssembly = false;
|
||||
bool isAssemblyFound = false;
|
||||
foreach (ZipArchiveEntry entry in zipArchive.Entries)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
string? safeFileName = GetSafeFileName(entry.FullName);
|
||||
if (safeFileName is null || !string.Equals(Path.GetExtension(safeFileName), ".dll", StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
foundAssembly = true;
|
||||
isAssemblyFound = true;
|
||||
string destinationPath = Path.Combine(_pluginsDirectory, safeFileName);
|
||||
await using Stream entryStream = entry.Open();
|
||||
await using FileStream outputStream = new(destinationPath, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
await entryStream.CopyToAsync(outputStream, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (!foundAssembly)
|
||||
if (!isAssemblyFound)
|
||||
return Errors.Plugins.PluginArchiveContainsNoAssemblies;
|
||||
return Result.Success;
|
||||
}
|
||||
@@ -135,8 +135,8 @@ internal sealed class PluginInstaller : IPluginInstaller
|
||||
/// <returns>The bare file name, or <see langword="null"/> when the path contains no usable file name.</returns>
|
||||
private static string? GetSafeFileName(string path)
|
||||
{
|
||||
// a backslash is not a directory separator on non-Windows platforms, so it is normalized to '/' first,
|
||||
// after which Path.GetFileName can strip any directory component on every platform
|
||||
// A backslash is not a directory separator on non-Windows platforms, so it is normalized to '/' first,
|
||||
// after which Path.GetFileName can strip any directory component on every platform.
|
||||
string fileName = Path.GetFileName(path.Replace('\\', '/'));
|
||||
return fileName is "" or "." or ".." ? null : fileName;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user