From f463703f796916d06496be9f483f0e146cb89799 Mon Sep 17 00:00:00 2001 From: VILLAN3LL3 Date: Fri, 17 May 2024 17:51:35 +0200 Subject: [PATCH 1/3] fixed sonar issues --- .sonarlint/Orso.Arpa.Api.json | 4 ++++ Orso.Arpa.Api/Program.cs | 3 ++- Orso.Arpa.Api/Startup.cs | 7 +++--- .../SwaggerAuthorizeOperationFilter.cs | 22 +++++++++---------- .../Commands/AddProjectToAppointment.cs | 6 ++--- .../Commands/AddRoomToAppointment.cs | 6 ++--- .../Commands/AddSectionToAppointment.cs | 10 ++++----- .../SendAppointmentChangedNotification.cs | 7 +++--- ...intmentParticipationsForMusicianProfile.cs | 11 +++++----- .../Queries/ListMyAppointments.cs | 5 ++++- .../AddDocumentToMyMusicianProfile.cs | 2 +- .../Commands/AddStakeholderGroupToPerson.cs | 6 ++--- .../ProjectDomain/Commands/AddRoleToUrl.cs | 6 ++--- ...ProjectParticipationChangedNotification.cs | 10 ++++----- .../UserDomain/Commands/RegisterUser.cs | 8 +++---- .../Repositories/ArpaUserManager.cs | 11 +++++----- .../_General/Errors/SystemStartException.cs | 11 ++++++++++ .../EmailConfirmationTokenProvider.cs | 2 +- .../PipelineBehaviors/RequestLogger.cs | 2 +- .../RequestPerformanceBehavior.cs | 4 ++-- Orso.Arpa.Mail/TemplateParser.cs | 7 +++++- Orso.Arpa.Persistence/DataSeeder.cs | 2 +- 22 files changed, 89 insertions(+), 63 deletions(-) create mode 100644 .sonarlint/Orso.Arpa.Api.json create mode 100644 Orso.Arpa.Domain/_General/Errors/SystemStartException.cs diff --git a/.sonarlint/Orso.Arpa.Api.json b/.sonarlint/Orso.Arpa.Api.json new file mode 100644 index 000000000..991f26e98 --- /dev/null +++ b/.sonarlint/Orso.Arpa.Api.json @@ -0,0 +1,4 @@ +{ + "sonarCloudOrganization": "orso-co", + "projectKey": "orso-co_Orso.Arpa.Api" +} \ No newline at end of file diff --git a/Orso.Arpa.Api/Program.cs b/Orso.Arpa.Api/Program.cs index bd90dd560..0943a39f1 100644 --- a/Orso.Arpa.Api/Program.cs +++ b/Orso.Arpa.Api/Program.cs @@ -6,6 +6,7 @@ using NLog.Web; using Orso.Arpa.Api.Middleware; using Orso.Arpa.Api.ModelBinding; +using Orso.Arpa.Domain._General.Errors; using LogLevel = Microsoft.Extensions.Logging.LogLevel; namespace Orso.Arpa.Api @@ -28,7 +29,7 @@ public static void Main(string[] args) catch (Exception exception) { logger.Error(exception, "Stopped program because of exception"); - throw; + throw new SystemStartException("Stopped program because of exception", exception); } finally { diff --git a/Orso.Arpa.Api/Startup.cs b/Orso.Arpa.Api/Startup.cs index 9690fc2e1..8807620d9 100644 --- a/Orso.Arpa.Api/Startup.cs +++ b/Orso.Arpa.Api/Startup.cs @@ -92,6 +92,7 @@ using Orso.Arpa.Application.UserApplication.Services; using Orso.Arpa.Application.VenueApplication.Interfaces; using Orso.Arpa.Application.VenueApplication.Services; +using Orso.Arpa.Domain._General.Errors; using Orso.Arpa.Domain.AuditLogDomain.Model; using Orso.Arpa.Domain.General.Configuration; using Orso.Arpa.Domain.General.Interfaces; @@ -626,7 +627,7 @@ protected virtual void EnsureDatabaseMigrations(IApplicationBuilder app) { ILogger logger = services.GetRequiredService>(); logger.LogError(ex, "An error occured during database migration"); - throw; + throw new SystemStartException("An error occured during database migration", ex); } } @@ -642,8 +643,8 @@ protected void PreloadTranslationsFromDb(IApplicationBuilder app) catch (Exception ex) { ILogger logger = services.GetRequiredService>(); - logger.LogError(ex, "Error during localization of data"); - throw; + logger.LogError(ex, "Error during preload of localization data from database"); + throw new SystemStartException("Error during preload of localization data from database", ex); } } } diff --git a/Orso.Arpa.Api/Swagger/SwaggerAuthorizeOperationFilter.cs b/Orso.Arpa.Api/Swagger/SwaggerAuthorizeOperationFilter.cs index d49df256a..db6e88be9 100644 --- a/Orso.Arpa.Api/Swagger/SwaggerAuthorizeOperationFilter.cs +++ b/Orso.Arpa.Api/Swagger/SwaggerAuthorizeOperationFilter.cs @@ -31,14 +31,7 @@ private static void HandleRoleAttributes(OpenApiOperation operation, IEnumerable operation.Responses.Add("403 a", new OpenApiResponse { Description = $"If current user does not have the role of '{string.Join(", ", roleAttributes)}'", - Content = new Dictionary() - { - { "application/json", new OpenApiMediaType() { Schema = new OpenApiSchema() { Type = "object", Properties = new Dictionary() { - { "title", new OpenApiSchema() { Type = "string" } }, - { "description", new OpenApiSchema() {Type="string" } }, - { "status", new OpenApiSchema() { Type = "integer" } } - } } } } - } + Content = CreateContent() }); } } @@ -55,16 +48,21 @@ private static void HandlePolicyAttributes(OpenApiOperation operation, IEnumerab operation.Responses.Add("403 b", new OpenApiResponse { Description = $"If current user does not meet policy '{string.Join(", ", policyAttributes)}'", - Content = new Dictionary() + Content = CreateContent() + }); + } + } + + private static Dictionary CreateContent() + { + return new Dictionary() { { "application/json", new OpenApiMediaType() { Schema = new OpenApiSchema() { Type = "object", Properties = new Dictionary() { { "title", new OpenApiSchema() { Type = "string" } }, { "description", new OpenApiSchema() {Type="string" } }, { "status", new OpenApiSchema() { Type = "integer" } } } } } } - } - }); - } + }; } } } diff --git a/Orso.Arpa.Domain/AppointmentDomain/Commands/AddProjectToAppointment.cs b/Orso.Arpa.Domain/AppointmentDomain/Commands/AddProjectToAppointment.cs index c4cfaffa2..192fecfc0 100644 --- a/Orso.Arpa.Domain/AppointmentDomain/Commands/AddProjectToAppointment.cs +++ b/Orso.Arpa.Domain/AppointmentDomain/Commands/AddProjectToAppointment.cs @@ -70,10 +70,10 @@ public Handler( public async Task Handle(Command request, CancellationToken cancellationToken) { - Appointment existingAppointment = await _arpaContext.Appointments.FindAsync(new object[] { request.Id }, cancellationToken); - Project existingProject = await _arpaContext.Projects.FindAsync(new object[] { request.ProjectId }, cancellationToken); + Appointment existingAppointment = await _arpaContext.Appointments.FindAsync([request.Id], cancellationToken); + Project existingProject = await _arpaContext.Projects.FindAsync([request.ProjectId], cancellationToken); - _arpaContext.ProjectAppointments.Add(new ProjectAppointment(null, existingProject, existingAppointment)); + await _arpaContext.ProjectAppointments.AddAsync(new ProjectAppointment(null, existingProject, existingAppointment), cancellationToken); if (await _arpaContext.SaveChangesAsync(cancellationToken) > 0) { diff --git a/Orso.Arpa.Domain/AppointmentDomain/Commands/AddRoomToAppointment.cs b/Orso.Arpa.Domain/AppointmentDomain/Commands/AddRoomToAppointment.cs index 790038b6d..df218627e 100644 --- a/Orso.Arpa.Domain/AppointmentDomain/Commands/AddRoomToAppointment.cs +++ b/Orso.Arpa.Domain/AppointmentDomain/Commands/AddRoomToAppointment.cs @@ -70,12 +70,12 @@ public Handler( public async Task Handle(Command request, CancellationToken cancellationToken) { - Appointment existingAppointment = await _arpaContext.Appointments.FindAsync(new object[] { request.Id }, cancellationToken); - Room existingRoom = await _arpaContext.Rooms.FindAsync(new object[] { request.RoomId }, cancellationToken); + Appointment existingAppointment = await _arpaContext.Appointments.FindAsync([request.Id], cancellationToken); + Room existingRoom = await _arpaContext.Rooms.FindAsync([request.RoomId], cancellationToken); var appointmentRoom = new AppointmentRoom(null, existingAppointment, existingRoom); - _arpaContext.AppointmentRooms.Add(appointmentRoom); + await _arpaContext.AppointmentRooms.AddAsync(appointmentRoom, cancellationToken); if (await _arpaContext.SaveChangesAsync(cancellationToken) > 0) { diff --git a/Orso.Arpa.Domain/AppointmentDomain/Commands/AddSectionToAppointment.cs b/Orso.Arpa.Domain/AppointmentDomain/Commands/AddSectionToAppointment.cs index 335c5a989..a976d9e70 100644 --- a/Orso.Arpa.Domain/AppointmentDomain/Commands/AddSectionToAppointment.cs +++ b/Orso.Arpa.Domain/AppointmentDomain/Commands/AddSectionToAppointment.cs @@ -51,8 +51,8 @@ public Validator(IArpaContext arpaContext) RuleFor(d => d.SectionId) .EntityExists(arpaContext) - .MustAsync(async (dto, sectionId, cancellation) => !(await arpaContext.SectionAppointments - .AnyAsync(sa => sa.SectionId == sectionId && sa.AppointmentId == dto.Id, cancellation))) + .MustAsync(async (dto, sectionId, cancellation) => !await arpaContext.SectionAppointments + .AnyAsync(sa => sa.SectionId == sectionId && sa.AppointmentId == dto.Id, cancellation)) .WithMessage("The section is already linked to the appointment"); } } @@ -68,10 +68,10 @@ public Handler( public async Task Handle(Command request, CancellationToken cancellationToken) { - Appointment existingAppointment = await _arpaContext.Appointments.FindAsync(new object[] { request.Id }, cancellationToken); - Section existingSection = await _arpaContext.Sections.FindAsync(new object[] { request.SectionId }, cancellationToken); + Appointment existingAppointment = await _arpaContext.Appointments.FindAsync([request.Id], cancellationToken); + Section existingSection = await _arpaContext.Sections.FindAsync([request.SectionId], cancellationToken); - _arpaContext.SectionAppointments.Add(new SectionAppointment(null, existingSection, existingAppointment)); + await _arpaContext.SectionAppointments.AddAsync(new SectionAppointment(null, existingSection, existingAppointment), cancellationToken); if (await _arpaContext.SaveChangesAsync(cancellationToken) > 0) { diff --git a/Orso.Arpa.Domain/AppointmentDomain/Commands/SendAppointmentChangedNotification.cs b/Orso.Arpa.Domain/AppointmentDomain/Commands/SendAppointmentChangedNotification.cs index 46b07a7d5..61193c48b 100644 --- a/Orso.Arpa.Domain/AppointmentDomain/Commands/SendAppointmentChangedNotification.cs +++ b/Orso.Arpa.Domain/AppointmentDomain/Commands/SendAppointmentChangedNotification.cs @@ -81,7 +81,8 @@ public async Task Handle(Command request, CancellationToken cancellationTo .Select(a => a.Id) .ToListAsync(cancellationToken); - if(personIds.Count == 0) { + if (personIds.Count == 0) + { throw new ValidationException([new ValidationFailure(nameof(request.AppointmentId), "No persons are eligible for this appointment. Cannot send email to empty recipient list.")]); } @@ -101,8 +102,8 @@ public async Task Handle(Command request, CancellationToken cancellationTo ClubPhoneNumber = _clubConfiguration.Phone, AppointmentName = appointment.ToString(), DateAndTime = $"{appointment.StartTime.ToGermanDateTimeString()} - {appointment.EndTime.ToGermanTimeString()}", - PublicDetails = appointment.PublicDetails ?? "- ohne -", - Venue = appointment.Venue?.ToString() ?? "- ohne -", + PublicDetails = appointment.PublicDetails, + Venue = appointment.Venue?.ToString(), ArpaUrl = _jwtConfiguration.Audience, Status = appointment.Status.ToString(), Sections = string.Join(", ", appointment.SectionAppointments.Select(sa => sa.Section.ToString())) diff --git a/Orso.Arpa.Domain/AppointmentDomain/Queries/ListAppointmentParticipationsForMusicianProfile.cs b/Orso.Arpa.Domain/AppointmentDomain/Queries/ListAppointmentParticipationsForMusicianProfile.cs index 4c7e621a3..a9cd42b60 100644 --- a/Orso.Arpa.Domain/AppointmentDomain/Queries/ListAppointmentParticipationsForMusicianProfile.cs +++ b/Orso.Arpa.Domain/AppointmentDomain/Queries/ListAppointmentParticipationsForMusicianProfile.cs @@ -47,26 +47,27 @@ public Handler(IArpaContext arpaContext) public async Task> Handle(Query request, CancellationToken cancellationToken) { - Guid personId = (await _arpaContext.FindAsync(new object[] { request.MusicianProfileId }, cancellationToken)).PersonId; + Guid personId = (await _arpaContext.FindAsync([request.MusicianProfileId], cancellationToken)).PersonId; IQueryable appointmentParticipations = _arpaContext.AppointmentParticipations .Where(ap => ap.PersonId.Equals(personId)); - if (appointmentParticipations.Any() && request.StartTime.HasValue) + if (await appointmentParticipations.AnyAsync(cancellationToken) && request.StartTime.HasValue) { var normalizedTime = new DateTime(request.StartTime.Value.Ticks, DateTimeKind.Unspecified); appointmentParticipations = appointmentParticipations.Where(ap => ap.Appointment.StartTime.Equals(normalizedTime)); } - if (appointmentParticipations.Any() && request.EndTime.HasValue) + if (await appointmentParticipations.AnyAsync(cancellationToken) && request.EndTime.HasValue) { var normalizedTime = new DateTime(request.EndTime.Value.Ticks, DateTimeKind.Unspecified); appointmentParticipations = appointmentParticipations.Where(ap => ap.Appointment.EndTime.Equals(normalizedTime)); } - if (appointmentParticipations.Any() && request.ProjectId.HasValue) + if (await appointmentParticipations.AnyAsync(cancellationToken) && request.ProjectId.HasValue) { - appointmentParticipations = appointmentParticipations.Where(ap => ap.Appointment.ProjectAppointments.Any(pa => pa.ProjectId.Equals(request.ProjectId))); + appointmentParticipations = appointmentParticipations.Where(ap => + ap.Appointment.ProjectAppointments.Any(pa => pa.ProjectId.Equals(request.ProjectId))); } return await appointmentParticipations.ToListAsync(cancellationToken); diff --git a/Orso.Arpa.Domain/AppointmentDomain/Queries/ListMyAppointments.cs b/Orso.Arpa.Domain/AppointmentDomain/Queries/ListMyAppointments.cs index 29492e314..683605dd2 100644 --- a/Orso.Arpa.Domain/AppointmentDomain/Queries/ListMyAppointments.cs +++ b/Orso.Arpa.Domain/AppointmentDomain/Queries/ListMyAppointments.cs @@ -58,7 +58,10 @@ public Handler(IArpaContext arpaContext, IDateTimeProvider dateTimeProvider) .Where(appointment => appointmentIds.Contains(appointment.Id) && appointment.EndTime > _dateTimeProvider.GetUtcNow()) .OrderBy(p => p.StartTime); - return (await userAppointments.Skip(request.Offset ?? 0).Take(request.Limit ?? count).ToListAsync(cancellationToken), userAppointments.Count()); + return ( + await userAppointments.Skip(request.Offset ?? 0).Take(request.Limit ?? count).ToListAsync(cancellationToken), + await userAppointments.CountAsync(cancellationToken) + ); } } } diff --git a/Orso.Arpa.Domain/MusicianProfileDomain/Commands/AddDocumentToMyMusicianProfile.cs b/Orso.Arpa.Domain/MusicianProfileDomain/Commands/AddDocumentToMyMusicianProfile.cs index f6f09669f..6909237c5 100644 --- a/Orso.Arpa.Domain/MusicianProfileDomain/Commands/AddDocumentToMyMusicianProfile.cs +++ b/Orso.Arpa.Domain/MusicianProfileDomain/Commands/AddDocumentToMyMusicianProfile.cs @@ -49,7 +49,7 @@ public async Task Handle(Command request, CancellationToken cancellationTo { var availableDocument = new MusicianProfileDocument(request.Id, request.DocumentId); - _arpaContext.MusicianProfileDocuments.Add(availableDocument); + await _arpaContext.MusicianProfileDocuments.AddAsync(availableDocument, cancellationToken); if (await _arpaContext.SaveChangesAsync(cancellationToken) > 0) { diff --git a/Orso.Arpa.Domain/PersonDomain/Commands/AddStakeholderGroupToPerson.cs b/Orso.Arpa.Domain/PersonDomain/Commands/AddStakeholderGroupToPerson.cs index c17040a8b..b756feac9 100644 --- a/Orso.Arpa.Domain/PersonDomain/Commands/AddStakeholderGroupToPerson.cs +++ b/Orso.Arpa.Domain/PersonDomain/Commands/AddStakeholderGroupToPerson.cs @@ -59,12 +59,12 @@ public Handler( public async Task Handle(Command request, CancellationToken cancellationToken) { - Person existingPerson = await _arpaContext.Persons.FindAsync(new object[] { request.Id }, cancellationToken); - Section existingSection = await _arpaContext.Sections.FindAsync(new object[] { request.StakeholderGroupId }, cancellationToken); + Person existingPerson = await _arpaContext.Persons.FindAsync([request.Id], cancellationToken); + Section existingSection = await _arpaContext.Sections.FindAsync([request.StakeholderGroupId], cancellationToken); var personSection = new PersonSection(null, existingPerson, existingSection); - _ = _arpaContext.Set().Add(personSection); + _ = await _arpaContext.Set().AddAsync(personSection); return await _arpaContext.SaveChangesAsync(cancellationToken) > 0 ? Unit.Value diff --git a/Orso.Arpa.Domain/ProjectDomain/Commands/AddRoleToUrl.cs b/Orso.Arpa.Domain/ProjectDomain/Commands/AddRoleToUrl.cs index 75c87738b..f8c7a2114 100644 --- a/Orso.Arpa.Domain/ProjectDomain/Commands/AddRoleToUrl.cs +++ b/Orso.Arpa.Domain/ProjectDomain/Commands/AddRoleToUrl.cs @@ -56,7 +56,7 @@ public Validator(IArpaContext arpaContext, RoleManager roleManager) .WithErrorCode("404") .WithMessage("Role could not be found.") - .MustAsync(async (dto, roleId, cancellation) => !(await arpaContext.EntityExistsAsync(ar => ar.RoleId == roleId && ar.UrlId == dto.UrlId, cancellation))) + .MustAsync(async (dto, roleId, cancellation) => !await arpaContext.EntityExistsAsync(ar => ar.RoleId == roleId && ar.UrlId == dto.UrlId, cancellation)) .WithMessage("The role is already linked to the url") .MustAsync(async (roleId, cancellation) => !await roleManager.Roles.AnyAsync(r => r.Id == roleId && r.Name == RoleNames.Admin, cancellation)) @@ -79,12 +79,12 @@ public Handler( public async Task Handle(Command request, CancellationToken cancellationToken) { - Url existingUrl = await _arpaContext.Urls.FindAsync(new object[] { request.UrlId }, cancellationToken); + Url existingUrl = await _arpaContext.Urls.FindAsync([request.UrlId], cancellationToken); Role existingRole = await _roleManager.Roles.SingleAsync(r => r.Id == request.RoleId, cancellationToken); var urlRole = new UrlRole(null, existingUrl, existingRole); - _arpaContext.UrlRoles.Add(urlRole); + await _arpaContext.UrlRoles.AddAsync(urlRole, cancellationToken); if (await _arpaContext.SaveChangesAsync(cancellationToken) > 0) { diff --git a/Orso.Arpa.Domain/ProjectDomain/Notifications/ProjectParticipationChangedNotification.cs b/Orso.Arpa.Domain/ProjectDomain/Notifications/ProjectParticipationChangedNotification.cs index 239f13a9d..d798cb7ae 100644 --- a/Orso.Arpa.Domain/ProjectDomain/Notifications/ProjectParticipationChangedNotification.cs +++ b/Orso.Arpa.Domain/ProjectDomain/Notifications/ProjectParticipationChangedNotification.cs @@ -88,13 +88,13 @@ public async Task Handle(ProjectParticipationChangedNotification notification, C var template = new ProjectParticipationChangedByStaffTemplate { ArpaLogo = _jwtConfiguration.ArpaLogo, - CommentByStaff = notification.ProjectParticipation.CommentByStaffInner ?? "- ohne -", - Comment = notification.ProjectParticipation.CommentByPerformerInner ?? "- ohne -", + CommentByStaff = notification.ProjectParticipation.CommentByStaffInner, + Comment = notification.ProjectParticipation.CommentByPerformerInner, DisplayName = musician.DisplayName, - ParticipationStatusInner = notification.ProjectParticipation.ParticipationStatusInner?.ToString() ?? "- ohne -", - ParticipationStatusInternal = notification.ProjectParticipation.ParticipationStatusInternal?.ToString() ?? "- ohne -", + ParticipationStatusInner = notification.ProjectParticipation.ParticipationStatusInner?.ToString(), + ParticipationStatusInternal = notification.ProjectParticipation.ParticipationStatusInternal?.ToString(), - InvitationStatus = notification.ProjectParticipation?.InvitationStatus?.ToString() ?? "- ohne -", + InvitationStatus = notification.ProjectParticipation?.InvitationStatus?.ToString(), ProjectName = notification.ProjectParticipation.Project.ToString(), ClubAddress = _clubConfiguration.Address, diff --git a/Orso.Arpa.Domain/UserDomain/Commands/RegisterUser.cs b/Orso.Arpa.Domain/UserDomain/Commands/RegisterUser.cs index 56956d599..06d8275c7 100644 --- a/Orso.Arpa.Domain/UserDomain/Commands/RegisterUser.cs +++ b/Orso.Arpa.Domain/UserDomain/Commands/RegisterUser.cs @@ -101,7 +101,7 @@ public async Task Handle(Command request, CancellationToken cancellationTo break; default: throw new ValidationException( - new ValidationFailure[] { new(nameof(Command.Email), "Multiple persons found with this email address. Registration aborted. Please contact your system admin.") }); + [new(nameof(Command.Email), "Multiple persons found with this email address. Registration aborted. Please contact your system admin.")]); } var user = new User @@ -119,13 +119,13 @@ public async Task Handle(Command request, CancellationToken cancellationTo throw new IdentityException("Problem creating user", result.Errors); } - _arpaContext.Set().AddRange(request.StakeholderGroupIds.Select(sg => new PersonSection(null, person.Id, sg))); - _ = _arpaContext.Set().Add(new ContactDetail(null, new CreateContactDetail.Command + await _arpaContext.Set().AddRangeAsync(request.StakeholderGroupIds.Select(sg => new PersonSection(null, person.Id, sg)), cancellationToken); + _ = await _arpaContext.Set().AddAsync(new ContactDetail(null, new CreateContactDetail.Command { Key = ContactDetailKey.EMail, PersonId = person.Id, Value = request.Email, - })); + }), cancellationToken); return (await _arpaContext.SaveChangesAsync(cancellationToken)) < request.StakeholderGroupIds.Count + 1 ? throw new AffectedRowCountMismatchException(nameof(PersonSection)) diff --git a/Orso.Arpa.Domain/UserDomain/Repositories/ArpaUserManager.cs b/Orso.Arpa.Domain/UserDomain/Repositories/ArpaUserManager.cs index fa62e54b1..123ed2178 100644 --- a/Orso.Arpa.Domain/UserDomain/Repositories/ArpaUserManager.cs +++ b/Orso.Arpa.Domain/UserDomain/Repositories/ArpaUserManager.cs @@ -26,7 +26,7 @@ public ArpaUserManager( ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, IServiceProvider services, - ILogger> logger) : base( + ILogger logger) : base( store, optionsAccessor, passwordHasher, @@ -41,7 +41,8 @@ public ArpaUserManager( public async Task FindUserByUsernameOrEmailAsync(string usernameOrEmail) { - if (string.IsNullOrWhiteSpace(usernameOrEmail)) { + if (string.IsNullOrWhiteSpace(usernameOrEmail)) + { return null; } return usernameOrEmail.Contains('@') ? await FindByEmailAsync(usernameOrEmail) : await FindByNameAsync(usernameOrEmail); @@ -63,10 +64,10 @@ public override async Task DeleteAsync(User user) { if (await CheckIfLastAdminWillBeRemovedAsync(user.Id)) { - throw new ValidationException(new ValidationFailure[] - { + throw new ValidationException( + [ new ValidationFailure(nameof(user.UserName), "The operation is not allowed because it would remove the last administrator") - }); + ]); } IdentityResult result = await base.DeleteAsync(user); diff --git a/Orso.Arpa.Domain/_General/Errors/SystemStartException.cs b/Orso.Arpa.Domain/_General/Errors/SystemStartException.cs new file mode 100644 index 000000000..525fd8099 --- /dev/null +++ b/Orso.Arpa.Domain/_General/Errors/SystemStartException.cs @@ -0,0 +1,11 @@ +using System; + +namespace Orso.Arpa.Domain._General.Errors +{ + public class SystemStartException : Exception + { + public SystemStartException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/Orso.Arpa.Infrastructure/Authentication/EmailConfirmationTokenProvider.cs b/Orso.Arpa.Infrastructure/Authentication/EmailConfirmationTokenProvider.cs index b876ec886..33b2c7e98 100644 --- a/Orso.Arpa.Infrastructure/Authentication/EmailConfirmationTokenProvider.cs +++ b/Orso.Arpa.Infrastructure/Authentication/EmailConfirmationTokenProvider.cs @@ -9,7 +9,7 @@ public class EmailConfirmationTokenProvider : DataProtectorTokenProvider< { public EmailConfirmationTokenProvider(IDataProtectionProvider dataProtectionProvider, IOptions options, - ILogger> logger) + ILogger> logger) : base(dataProtectionProvider, options, logger) { } diff --git a/Orso.Arpa.Infrastructure/PipelineBehaviors/RequestLogger.cs b/Orso.Arpa.Infrastructure/PipelineBehaviors/RequestLogger.cs index 7919394e0..636777960 100644 --- a/Orso.Arpa.Infrastructure/PipelineBehaviors/RequestLogger.cs +++ b/Orso.Arpa.Infrastructure/PipelineBehaviors/RequestLogger.cs @@ -11,7 +11,7 @@ public class RequestLogger : IRequestPreProcessor private readonly ILogger _logger; private readonly IUserAccessor _userAccessor; - public RequestLogger(ILogger logger, IUserAccessor userAccessor) + public RequestLogger(ILogger> logger, IUserAccessor userAccessor) { _logger = logger; _userAccessor = userAccessor; diff --git a/Orso.Arpa.Infrastructure/PipelineBehaviors/RequestPerformanceBehavior.cs b/Orso.Arpa.Infrastructure/PipelineBehaviors/RequestPerformanceBehavior.cs index 484bc065a..faa4b1f70 100644 --- a/Orso.Arpa.Infrastructure/PipelineBehaviors/RequestPerformanceBehavior.cs +++ b/Orso.Arpa.Infrastructure/PipelineBehaviors/RequestPerformanceBehavior.cs @@ -10,11 +10,11 @@ namespace Orso.Arpa.Infrastructure.PipelineBehaviors public class RequestPerformanceBehaviour : IPipelineBehavior where TRequest : IRequest { private readonly Stopwatch _timer; - private readonly ILogger _logger; + private readonly ILogger> _logger; private readonly IUserAccessor _userAccessor; public RequestPerformanceBehaviour( - ILogger logger, + ILogger> logger, IUserAccessor userAccessor) { _timer = new Stopwatch(); diff --git a/Orso.Arpa.Mail/TemplateParser.cs b/Orso.Arpa.Mail/TemplateParser.cs index 5c34d56a6..60b3565d8 100644 --- a/Orso.Arpa.Mail/TemplateParser.cs +++ b/Orso.Arpa.Mail/TemplateParser.cs @@ -28,7 +28,12 @@ public string Parse(ITemplate templateData) { continue; } - builder.Replace("{{" + propertyInfo.Name + "}}", (string)propertyInfo.GetValue(templateData)); + var value = (string)propertyInfo.GetValue(templateData); + if (string.IsNullOrWhiteSpace(value)) + { + value = "- ohne -"; + } + builder.Replace("{{" + propertyInfo.Name + "}}", value); } return builder.ToString(); diff --git a/Orso.Arpa.Persistence/DataSeeder.cs b/Orso.Arpa.Persistence/DataSeeder.cs index ecf3babee..75bfb6886 100644 --- a/Orso.Arpa.Persistence/DataSeeder.cs +++ b/Orso.Arpa.Persistence/DataSeeder.cs @@ -51,7 +51,7 @@ private async Task SeedViewsAndFunctionsAsync() var sqlDirectory = Path.Combine(AppContext.BaseDirectory, "SqlStatements"); foreach (var sqlFile in Directory.EnumerateFiles(sqlDirectory, "*.sql").OrderBy(filename => filename)) { - var sqlStatement = File.ReadAllText(Path.Combine(sqlDirectory, sqlFile)); + var sqlStatement = await File.ReadAllTextAsync(Path.Combine(sqlDirectory, sqlFile)); _ = await _arpaContext.ExecuteSqlAsync(sqlStatement); } } From f128c1d95596cfa9c9da8d4f8d9ee5715a0e0a0e Mon Sep 17 00:00:00 2001 From: VILLAN3LL3 Date: Fri, 17 May 2024 17:57:53 +0200 Subject: [PATCH 2/3] fixed build error --- Tests/Orso.Arpa.Tests.Shared/Identity/FakeUserManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Orso.Arpa.Tests.Shared/Identity/FakeUserManager.cs b/Tests/Orso.Arpa.Tests.Shared/Identity/FakeUserManager.cs index 168b6c81f..c5bd8e387 100644 --- a/Tests/Orso.Arpa.Tests.Shared/Identity/FakeUserManager.cs +++ b/Tests/Orso.Arpa.Tests.Shared/Identity/FakeUserManager.cs @@ -29,7 +29,7 @@ public FakeUserManager() Substitute.For(), Substitute.For(), Substitute.For(), - Substitute.For>>()) + Substitute.For>()) { } public override IQueryable Users From 71e9ca537a08ce696e0be0f3867b4fb7ef7db72d Mon Sep 17 00:00:00 2001 From: VILLAN3LL3 Date: Fri, 17 May 2024 18:03:13 +0200 Subject: [PATCH 3/3] added missing cancellationtoken --- .../PersonDomain/Commands/AddStakeholderGroupToPerson.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Orso.Arpa.Domain/PersonDomain/Commands/AddStakeholderGroupToPerson.cs b/Orso.Arpa.Domain/PersonDomain/Commands/AddStakeholderGroupToPerson.cs index b756feac9..469265a85 100644 --- a/Orso.Arpa.Domain/PersonDomain/Commands/AddStakeholderGroupToPerson.cs +++ b/Orso.Arpa.Domain/PersonDomain/Commands/AddStakeholderGroupToPerson.cs @@ -64,7 +64,7 @@ public async Task Handle(Command request, CancellationToken cancellationTo var personSection = new PersonSection(null, existingPerson, existingSection); - _ = await _arpaContext.Set().AddAsync(personSection); + _ = await _arpaContext.Set().AddAsync(personSection, cancellationToken); return await _arpaContext.SaveChangesAsync(cancellationToken) > 0 ? Unit.Value