From ad9bb882efe8d0241b15827406badbbd5fe75caa Mon Sep 17 00:00:00 2001 From: Timo Notheisen <65653426+tnotheis@users.noreply.github.com> Date: Mon, 4 Nov 2024 07:23:12 +0100 Subject: [PATCH] Make identity deletion periods configurable (#928) * feat: make identity deletion periods configurable * fix: make tests pass * fix: make secondsUntilApprovalPeriodEnds and secondsUntilGracePeriodEnds at most 0 * refactor: try it with decimal dates instead of seconds * chore: upgrade ReHackt.Extensions.Options.Validation to 8.0.3 * fix: configure InfrastructureOption for Devices in AdminApi * feat: revert change regarding DeletionProcessApprovedNotification * fix: configuration issue * refactor: change name and reformat code * fix: change type of reminder config properties "DaysBeforeEndOf..." to double --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .../DevicesServiceCollectionExtensions.cs | 14 ++++-- Applications/AdminApi/src/AdminApi/Program.cs | 7 +-- .../AdminCli/src/AdminCli/ServiceLocator.cs | 2 +- .../BuildingBlocks.Application.csproj | 1 + .../IServiceCollectionExtensions.cs | 13 ++++- .../ApproveDeletionProcess/Handler.cs | 7 ++- .../Handler.cs | 23 +++++---- .../Handler.cs | 33 +++++++------ .../src/Devices.ConsumerApi/DevicesModule.cs | 4 +- .../IdentityDeletionConfiguration.cs | 48 ++++++------------- .../Identities/IdentityDeletionProcess.cs | 4 +- .../TestDataGenerator.cs | 2 +- .../ApproveDeletionProcess/HandlerTests.cs | 5 +- .../UpdateDeletionProcesses/HandlerTests.cs | 2 +- .../Identities/DeletionStartedTests.cs | 4 +- .../Tags.ConsumerApi/Tags.ConsumerApi.csproj | 2 +- 16 files changed, 87 insertions(+), 84 deletions(-) diff --git a/Applications/AdminApi/src/AdminApi/Extensions/DevicesServiceCollectionExtensions.cs b/Applications/AdminApi/src/AdminApi/Extensions/DevicesServiceCollectionExtensions.cs index 8414fda3d5..e2573e1cc1 100644 --- a/Applications/AdminApi/src/AdminApi/Extensions/DevicesServiceCollectionExtensions.cs +++ b/Applications/AdminApi/src/AdminApi/Extensions/DevicesServiceCollectionExtensions.cs @@ -3,20 +3,24 @@ using Backbone.Crypto.Implementations; using Backbone.Modules.Devices.Application.Extensions; using Backbone.Modules.Devices.Infrastructure.Persistence; +using Microsoft.Extensions.Options; namespace Backbone.AdminApi.Extensions; public static class DevicesServiceCollectionExtensions { - public static IServiceCollection AddDevices(this IServiceCollection services, - DevicesConfiguration configuration) + public static IServiceCollection AddDevices(this IServiceCollection services, IConfiguration configuration) { - services.AddApplication(); + services.AddApplication(configuration.GetSection("Application")); + + services.ConfigureAndValidate(configuration.GetSection("Infrastructure").Bind); + + var infrastructureConfiguration = services.BuildServiceProvider().GetRequiredService>().Value; services.AddDatabase(options => { - options.Provider = configuration.Infrastructure.SqlDatabase.Provider; - options.ConnectionString = configuration.Infrastructure.SqlDatabase.ConnectionString; + options.Provider = infrastructureConfiguration.SqlDatabase.Provider; + options.ConnectionString = infrastructureConfiguration.SqlDatabase.ConnectionString; }); services.AddSingleton(_ => SignatureHelper.CreateEd25519WithRawKeyFormat()); diff --git a/Applications/AdminApi/src/AdminApi/Program.cs b/Applications/AdminApi/src/AdminApi/Program.cs index da9fcfad53..8fe5f79377 100644 --- a/Applications/AdminApi/src/AdminApi/Program.cs +++ b/Applications/AdminApi/src/AdminApi/Program.cs @@ -11,7 +11,6 @@ using Backbone.BuildingBlocks.Application.QuotaCheck; using Backbone.BuildingBlocks.Infrastructure.Persistence.Database; using Backbone.Infrastructure.EventBus; -using Backbone.Modules.Devices.Application; using Backbone.Modules.Devices.Infrastructure.OpenIddict; using Backbone.Modules.Devices.Infrastructure.Persistence.Database; using Backbone.Modules.Devices.Infrastructure.PushNotifications; @@ -96,9 +95,7 @@ static void ConfigureServices(IServiceCollection services, IConfiguration config services.AddSingleton(); - services - .ConfigureAndValidate(configuration.Bind) - .ConfigureAndValidate(options => configuration.GetSection("Modules:Devices:Application").Bind(options)); + services.ConfigureAndValidate(configuration.Bind); #pragma warning disable ASP0000 // We retrieve the Configuration via IOptions here so that it is validated var parsedConfiguration = services.BuildServiceProvider().GetRequiredService>().Value; @@ -110,7 +107,7 @@ static void ConfigureServices(IServiceCollection services, IConfiguration config .AddCustomFluentValidation() .AddCustomIdentity(environment) .AddDatabase(parsedConfiguration.Infrastructure.SqlDatabase) - .AddDevices(parsedConfiguration.Modules.Devices) + .AddDevices(configuration.GetSection("Modules:Devices")) .AddQuotas(parsedConfiguration.Modules.Quotas) .AddChallenges(parsedConfiguration.Modules.Challenges) .AddHealthChecks(); diff --git a/Applications/AdminCli/src/AdminCli/ServiceLocator.cs b/Applications/AdminCli/src/AdminCli/ServiceLocator.cs index 4660d81aea..305e18be69 100644 --- a/Applications/AdminCli/src/AdminCli/ServiceLocator.cs +++ b/Applications/AdminCli/src/AdminCli/ServiceLocator.cs @@ -38,7 +38,7 @@ private static IServiceCollection ConfigureServices(string dbProvider, string db options.AddApplicationStore(); }); - services.AddApplication(); + services.AddApplicationWithoutIdentityDeletion(); services.AddSingleton(); diff --git a/BuildingBlocks/src/BuildingBlocks.Application/BuildingBlocks.Application.csproj b/BuildingBlocks/src/BuildingBlocks.Application/BuildingBlocks.Application.csproj index 883b0fdfba..547196c2cb 100644 --- a/BuildingBlocks/src/BuildingBlocks.Application/BuildingBlocks.Application.csproj +++ b/BuildingBlocks/src/BuildingBlocks.Application/BuildingBlocks.Application.csproj @@ -4,6 +4,7 @@ + diff --git a/Modules/Devices/src/Devices.Application/Extensions/IServiceCollectionExtensions.cs b/Modules/Devices/src/Devices.Application/Extensions/IServiceCollectionExtensions.cs index 662cf365b8..cf5d46ee29 100644 --- a/Modules/Devices/src/Devices.Application/Extensions/IServiceCollectionExtensions.cs +++ b/Modules/Devices/src/Devices.Application/Extensions/IServiceCollectionExtensions.cs @@ -3,14 +3,25 @@ using Backbone.BuildingBlocks.Application.MediatR; using Backbone.Modules.Devices.Application.Devices.Commands.RegisterDevice; using Backbone.Modules.Devices.Application.Devices.Queries.ListDevices; +using Backbone.Modules.Devices.Domain.Entities.Identities; using FluentValidation; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace Backbone.Modules.Devices.Application.Extensions; public static class IServiceCollectionExtensions { - public static void AddApplication(this IServiceCollection services) + public static void AddApplication(this IServiceCollection services, IConfiguration applicationConfiguration) + { + services.ConfigureAndValidate(applicationConfiguration.Bind); + + applicationConfiguration.GetSection("IdentityDeletion").Bind(IdentityDeletionConfiguration.Instance); + + services.AddApplicationWithoutIdentityDeletion(); + } + + public static void AddApplicationWithoutIdentityDeletion(this IServiceCollection services) { services.AddMediatR(c => c .RegisterServicesFromAssemblyContaining() diff --git a/Modules/Devices/src/Devices.Application/Identities/Commands/ApproveDeletionProcess/Handler.cs b/Modules/Devices/src/Devices.Application/Identities/Commands/ApproveDeletionProcess/Handler.cs index 783ab08181..7fbc879ea0 100644 --- a/Modules/Devices/src/Devices.Application/Identities/Commands/ApproveDeletionProcess/Handler.cs +++ b/Modules/Devices/src/Devices.Application/Identities/Commands/ApproveDeletionProcess/Handler.cs @@ -38,8 +38,11 @@ public async Task Handle(ApproveDeletionProcessC await _identitiesRepository.Update(identity, cancellationToken); - var daysUntilDeletion = deletionProcess.GracePeriodEndsAt?.DaysUntilDate() ?? - throw new Exception($"Expected '{nameof(deletionProcess.GracePeriodEndsAt)}' to be set but found 'null' instead."); + if (deletionProcess.GracePeriodEndsAt == null) + throw new Exception($"Expected '{nameof(deletionProcess.GracePeriodEndsAt)}' to be set but found 'null' instead."); + + var daysUntilDeletion = deletionProcess.GracePeriodEndsAt.Value.DaysUntilDate(); + await _notificationSender.SendNotification(identity.Address, new DeletionProcessApprovedNotification(daysUntilDeletion), cancellationToken); return new ApproveDeletionProcessResponse(deletionProcess); diff --git a/Modules/Devices/src/Devices.Application/Identities/Commands/SendDeletionProcessApprovalReminders/Handler.cs b/Modules/Devices/src/Devices.Application/Identities/Commands/SendDeletionProcessApprovalReminders/Handler.cs index 2d0546f6b4..3eaa7ea4b0 100644 --- a/Modules/Devices/src/Devices.Application/Identities/Commands/SendDeletionProcessApprovalReminders/Handler.cs +++ b/Modules/Devices/src/Devices.Application/Identities/Commands/SendDeletionProcessApprovalReminders/Handler.cs @@ -31,7 +31,7 @@ public async Task Handle(SendDeletionProcessApprovalRemindersCommand request, Ca foreach (var identity in identities) { var deletionProcess = identity.GetDeletionProcessInStatus(DeletionProcessStatus.WaitingForApproval) ?? throw new NotFoundException(nameof(IdentityDeletionProcess)); - var daysUntilApprovalPeriodEnds = (deletionProcess.ApprovalPeriodEndsAt - SystemTime.UtcNow).Days; + var daysUntilApprovalPeriodEnds = (deletionProcess.ApprovalPeriodEndsAt - SystemTime.UtcNow).TotalDays; if (deletionProcess.ApprovalReminder3SentAt != null) { @@ -39,45 +39,48 @@ public async Task Handle(SendDeletionProcessApprovalRemindersCommand request, Ca continue; } - if (daysUntilApprovalPeriodEnds <= IdentityDeletionConfiguration.ApprovalReminder3.Time) + if (daysUntilApprovalPeriodEnds <= IdentityDeletionConfiguration.Instance.ApprovalReminder3.DaysBeforeEndOfApprovalPeriod) { await SendReminder3(identity, daysUntilApprovalPeriodEnds, deletionProcess.Id, cancellationToken); continue; } if (deletionProcess.ApprovalReminder2SentAt != null) continue; - if (daysUntilApprovalPeriodEnds <= IdentityDeletionConfiguration.ApprovalReminder2.Time) + if (daysUntilApprovalPeriodEnds <= IdentityDeletionConfiguration.Instance.ApprovalReminder2.DaysBeforeEndOfApprovalPeriod) { await SendReminder2(identity, daysUntilApprovalPeriodEnds, deletionProcess.Id, cancellationToken); continue; } - if (deletionProcess.ApprovalReminder1SentAt == null && daysUntilApprovalPeriodEnds <= IdentityDeletionConfiguration.ApprovalReminder1.Time) + if (deletionProcess.ApprovalReminder1SentAt == null && daysUntilApprovalPeriodEnds <= IdentityDeletionConfiguration.Instance.ApprovalReminder1.DaysBeforeEndOfApprovalPeriod) { await SendReminder1(identity, daysUntilApprovalPeriodEnds, deletionProcess.Id, cancellationToken); } } } - private async Task SendReminder3(Identity identity, int daysUntilApprovalPeriodEnds, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) + private async Task SendReminder3(Identity identity, double daysUntilApprovalPeriodEnds, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) { - await _pushNotificationSender.SendNotification(identity.Address, new DeletionProcessWaitingForApprovalReminderPushNotification(daysUntilApprovalPeriodEnds), cancellationToken); + await _pushNotificationSender.SendNotification(identity.Address, new DeletionProcessWaitingForApprovalReminderPushNotification((int)Math.Ceiling(daysUntilApprovalPeriodEnds)), + cancellationToken); identity.DeletionProcessApprovalReminder3Sent(); await _identitiesRepository.Update(identity, cancellationToken); _logger.ApprovalReminder3Sent(deletionProcessId); } - private async Task SendReminder2(Identity identity, int daysUntilApprovalPeriodEnds, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) + private async Task SendReminder2(Identity identity, double daysUntilApprovalPeriodEnds, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) { - await _pushNotificationSender.SendNotification(identity.Address, new DeletionProcessWaitingForApprovalReminderPushNotification(daysUntilApprovalPeriodEnds), cancellationToken); + await _pushNotificationSender.SendNotification(identity.Address, new DeletionProcessWaitingForApprovalReminderPushNotification((int)Math.Ceiling(daysUntilApprovalPeriodEnds)), + cancellationToken); identity.DeletionProcessApprovalReminder2Sent(); await _identitiesRepository.Update(identity, cancellationToken); _logger.ApprovalReminder2Sent(deletionProcessId); } - private async Task SendReminder1(Identity identity, int daysUntilApprovalPeriodEnds, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) + private async Task SendReminder1(Identity identity, double daysUntilApprovalPeriodEnds, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) { - await _pushNotificationSender.SendNotification(identity.Address, new DeletionProcessWaitingForApprovalReminderPushNotification(daysUntilApprovalPeriodEnds), cancellationToken); + await _pushNotificationSender.SendNotification(identity.Address, new DeletionProcessWaitingForApprovalReminderPushNotification((int)Math.Ceiling(daysUntilApprovalPeriodEnds)), + cancellationToken); identity.DeletionProcessApprovalReminder1Sent(); await _identitiesRepository.Update(identity, cancellationToken); _logger.ApprovalReminder1Sent(deletionProcessId); diff --git a/Modules/Devices/src/Devices.Application/Identities/Commands/SendDeletionProcessGracePeriodReminders/Handler.cs b/Modules/Devices/src/Devices.Application/Identities/Commands/SendDeletionProcessGracePeriodReminders/Handler.cs index 04cb94e211..c381ff56ba 100644 --- a/Modules/Devices/src/Devices.Application/Identities/Commands/SendDeletionProcessGracePeriodReminders/Handler.cs +++ b/Modules/Devices/src/Devices.Application/Identities/Commands/SendDeletionProcessGracePeriodReminders/Handler.cs @@ -31,7 +31,7 @@ public async Task Handle(SendDeletionProcessGracePeriodRemindersCommand request, foreach (var identity in identities) { var deletionProcess = identity.GetDeletionProcessInStatus(DeletionProcessStatus.Approved) ?? throw new NotFoundException(nameof(IdentityDeletionProcess)); - var daysToDeletion = (deletionProcess.GracePeriodEndsAt!.Value - SystemTime.UtcNow).Days; + var daysUntilDeletion = (deletionProcess.GracePeriodEndsAt!.Value - SystemTime.UtcNow).TotalDays; if (deletionProcess.GracePeriodReminder3SentAt != null) { @@ -39,45 +39,50 @@ public async Task Handle(SendDeletionProcessGracePeriodRemindersCommand request, continue; } - if (daysToDeletion <= IdentityDeletionConfiguration.GracePeriodNotification3.Time) + if (daysUntilDeletion <= IdentityDeletionConfiguration.Instance.GracePeriodNotification3.DaysBeforeEndOfGracePeriod) { - await SendReminder3(identity, daysToDeletion, deletionProcess.Id, cancellationToken); + await SendReminder3(identity, daysUntilDeletion, deletionProcess.Id, cancellationToken); continue; } - if (deletionProcess.GracePeriodReminder2SentAt != null) continue; - if (daysToDeletion <= IdentityDeletionConfiguration.GracePeriodNotification2.Time) + if (deletionProcess.GracePeriodReminder2SentAt != null) + continue; + + if (daysUntilDeletion <= IdentityDeletionConfiguration.Instance.GracePeriodNotification2.DaysBeforeEndOfGracePeriod) { - await SendReminder2(identity, daysToDeletion, deletionProcess.Id, cancellationToken); + await SendReminder2(identity, daysUntilDeletion, deletionProcess.Id, cancellationToken); continue; } - if (deletionProcess.GracePeriodReminder1SentAt == null && daysToDeletion <= IdentityDeletionConfiguration.GracePeriodNotification1.Time) + if (deletionProcess.GracePeriodReminder1SentAt != null) + continue; + + if (daysUntilDeletion <= IdentityDeletionConfiguration.Instance.GracePeriodNotification1.DaysBeforeEndOfGracePeriod) { - await SendReminder1(identity, daysToDeletion, deletionProcess.Id, cancellationToken); + await SendReminder1(identity, daysUntilDeletion, deletionProcess.Id, cancellationToken); } } } - private async Task SendReminder3(Identity identity, int daysToDeletion, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) + private async Task SendReminder3(Identity identity, double daysUntilGracePeriodEnds, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) { - await _pushSender.SendNotification(identity.Address, new DeletionProcessGracePeriodReminderPushNotification(daysToDeletion), cancellationToken); + await _pushSender.SendNotification(identity.Address, new DeletionProcessGracePeriodReminderPushNotification((int)Math.Ceiling(daysUntilGracePeriodEnds)), cancellationToken); identity.DeletionGracePeriodReminder3Sent(); await _identitiesRepository.Update(identity, cancellationToken); _logger.Reminder3Sent(deletionProcessId); } - private async Task SendReminder2(Identity identity, int daysToDeletion, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) + private async Task SendReminder2(Identity identity, double daysUntilGracePeriodEnds, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) { - await _pushSender.SendNotification(identity.Address, new DeletionProcessGracePeriodReminderPushNotification(daysToDeletion), cancellationToken); + await _pushSender.SendNotification(identity.Address, new DeletionProcessGracePeriodReminderPushNotification((int)Math.Ceiling(daysUntilGracePeriodEnds)), cancellationToken); identity.DeletionGracePeriodReminder2Sent(); await _identitiesRepository.Update(identity, cancellationToken); _logger.Reminder2Sent(deletionProcessId); } - private async Task SendReminder1(Identity identity, int daysToDeletion, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) + private async Task SendReminder1(Identity identity, double daysUntilGracePeriodEnds, IdentityDeletionProcessId deletionProcessId, CancellationToken cancellationToken) { - await _pushSender.SendNotification(identity.Address, new DeletionProcessGracePeriodReminderPushNotification(daysToDeletion), cancellationToken); + await _pushSender.SendNotification(identity.Address, new DeletionProcessGracePeriodReminderPushNotification((int)Math.Ceiling(daysUntilGracePeriodEnds)), cancellationToken); identity.DeletionGracePeriodReminder1Sent(); await _identitiesRepository.Update(identity, cancellationToken); _logger.Reminder1Sent(deletionProcessId); diff --git a/Modules/Devices/src/Devices.ConsumerApi/DevicesModule.cs b/Modules/Devices/src/Devices.ConsumerApi/DevicesModule.cs index 7f8c733b6f..a4a31a573a 100644 --- a/Modules/Devices/src/Devices.ConsumerApi/DevicesModule.cs +++ b/Modules/Devices/src/Devices.ConsumerApi/DevicesModule.cs @@ -3,7 +3,6 @@ using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; using Backbone.Crypto.Abstractions; using Backbone.Crypto.Implementations; -using Backbone.Modules.Devices.Application; using Backbone.Modules.Devices.Application.Extensions; using Backbone.Modules.Devices.Infrastructure.Persistence; using Backbone.Modules.Devices.Infrastructure.Persistence.Database; @@ -21,12 +20,11 @@ public class DevicesModule : AbstractModule public override void ConfigureServices(IServiceCollection services, IConfigurationSection configuration) { - services.ConfigureAndValidate(options => configuration.GetSection("Application").Bind(options)); services.ConfigureAndValidate(configuration.Bind); var parsedConfiguration = services.BuildServiceProvider().GetRequiredService>().Value; - services.AddApplication(); + services.AddApplication(configuration.GetSection("Application")); services.AddDatabase(options => { diff --git a/Modules/Devices/src/Devices.Domain/Entities/Identities/IdentityDeletionConfiguration.cs b/Modules/Devices/src/Devices.Domain/Entities/Identities/IdentityDeletionConfiguration.cs index 4d7c40174f..d641c5a0e0 100644 --- a/Modules/Devices/src/Devices.Domain/Entities/Identities/IdentityDeletionConfiguration.cs +++ b/Modules/Devices/src/Devices.Domain/Entities/Identities/IdentityDeletionConfiguration.cs @@ -1,47 +1,27 @@ namespace Backbone.Modules.Devices.Domain.Entities.Identities; -public class IdentityDeletionConfiguration +public record IdentityDeletionConfiguration { - public static int LengthOfApprovalPeriod => 7; - public static int LengthOfGracePeriod => 14; + public static IdentityDeletionConfiguration Instance { get; private set; } = new(); - public static GracePeriodNotificationConfiguration GracePeriodNotification1 { get; } = new() - { - Time = 12 - }; + public double LengthOfApprovalPeriodInDays { get; set; } = 7; + public double LengthOfGracePeriodInDays { get; set; } = 14; - public static GracePeriodNotificationConfiguration GracePeriodNotification2 { get; } = new() - { - Time = 10 - }; + public GracePeriodNotificationConfiguration GracePeriodNotification1 { get; set; } = new() { DaysBeforeEndOfGracePeriod = 12 }; + public GracePeriodNotificationConfiguration GracePeriodNotification2 { get; set; } = new() { DaysBeforeEndOfGracePeriod = 10 }; + public GracePeriodNotificationConfiguration GracePeriodNotification3 { get; set; } = new() { DaysBeforeEndOfGracePeriod = 5 }; - public static GracePeriodNotificationConfiguration GracePeriodNotification3 { get; } = new() - { - Time = 5 - }; - - public static ApprovalReminderNotificationConfiguration ApprovalReminder1 { get; } = new() - { - Time = 6 - }; - - public static ApprovalReminderNotificationConfiguration ApprovalReminder2 { get; } = new() - { - Time = 4 - }; - - public static ApprovalReminderNotificationConfiguration ApprovalReminder3 { get; } = new() - { - Time = 2 - }; + public ApprovalReminderNotificationConfiguration ApprovalReminder1 { get; set; } = new() { DaysBeforeEndOfApprovalPeriod = 6 }; + public ApprovalReminderNotificationConfiguration ApprovalReminder2 { get; set; } = new() { DaysBeforeEndOfApprovalPeriod = 4 }; + public ApprovalReminderNotificationConfiguration ApprovalReminder3 { get; set; } = new() { DaysBeforeEndOfApprovalPeriod = 2 }; } -public class GracePeriodNotificationConfiguration +public class ApprovalReminderNotificationConfiguration { - public int Time { get; init; } + public double DaysBeforeEndOfApprovalPeriod { get; set; } } -public class ApprovalReminderNotificationConfiguration +public class GracePeriodNotificationConfiguration { - public int Time { get; init; } + public double DaysBeforeEndOfGracePeriod { get; set; } } diff --git a/Modules/Devices/src/Devices.Domain/Entities/Identities/IdentityDeletionProcess.cs b/Modules/Devices/src/Devices.Domain/Entities/Identities/IdentityDeletionProcess.cs index 9af51b8bfa..95461b382f 100644 --- a/Modules/Devices/src/Devices.Domain/Entities/Identities/IdentityDeletionProcess.cs +++ b/Modules/Devices/src/Devices.Domain/Entities/Identities/IdentityDeletionProcess.cs @@ -48,7 +48,7 @@ private IdentityDeletionProcess(IdentityAddress createdBy, DeviceId createdByDev public IReadOnlyList AuditLog => _auditLog; public DeletionProcessStatus Status { get; private set; } public DateTime CreatedAt { get; } - public DateTime ApprovalPeriodEndsAt => CreatedAt.AddDays(IdentityDeletionConfiguration.LengthOfApprovalPeriod); + public DateTime ApprovalPeriodEndsAt => CreatedAt.AddDays(IdentityDeletionConfiguration.Instance.LengthOfApprovalPeriodInDays); public DateTime? ApprovalReminder1SentAt { get; private set; } public DateTime? ApprovalReminder2SentAt { get; private set; } @@ -153,7 +153,7 @@ private void ApproveInternally(IdentityAddress address, DeviceId createdByDevice { ApprovedAt = SystemTime.UtcNow; ApprovedByDevice = createdByDevice; - GracePeriodEndsAt = SystemTime.UtcNow.AddDays(IdentityDeletionConfiguration.LengthOfGracePeriod); + GracePeriodEndsAt = SystemTime.UtcNow.AddDays(IdentityDeletionConfiguration.Instance.LengthOfGracePeriodInDays); ChangeStatus(DeletionProcessStatus.Approved, address, address); } diff --git a/Modules/Devices/test/Devices.Application.Tests/TestDataGenerator.cs b/Modules/Devices/test/Devices.Application.Tests/TestDataGenerator.cs index bcfe13c3a4..20009db623 100644 --- a/Modules/Devices/test/Devices.Application.Tests/TestDataGenerator.cs +++ b/Modules/Devices/test/Devices.Application.Tests/TestDataGenerator.cs @@ -76,7 +76,7 @@ public static IdentityDeletionProcess CreateDeletingDeletionProcessFor(Identity { var deletionProcess = identity.StartDeletionProcessAsOwner(deviceId); - SystemTime.Set(SystemTime.UtcNow.AddDays(IdentityDeletionConfiguration.LengthOfGracePeriod + 1)); + SystemTime.Set(SystemTime.UtcNow.AddDays(IdentityDeletionConfiguration.Instance.LengthOfGracePeriodInDays)); identity.DeletionStarted(); SystemTime.UndoSet(); diff --git a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/ApproveDeletionProcess/HandlerTests.cs b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/ApproveDeletionProcess/HandlerTests.cs index 217f66f241..1589163c46 100644 --- a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/ApproveDeletionProcess/HandlerTests.cs +++ b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/ApproveDeletionProcess/HandlerTests.cs @@ -33,7 +33,7 @@ public async Task Happy_path() A.CallTo(() => mockIdentitiesRepository.FindByAddress(identity.Address, A._, A._)) .Returns(identity); - var mockPushNotificationSender = A.Dummy(); + var mockPushNotificationSender = A.Fake(); var handler = CreateHandler(mockIdentitiesRepository, fakeUserContext, mockPushNotificationSender); @@ -52,7 +52,8 @@ public async Task Happy_path() .MustHaveHappenedOnceExactly(); A.CallTo(() => mockPushNotificationSender.SendNotification(identity.Address, - A.That.Matches(n => n.DaysUntilDeletion == IdentityDeletionConfiguration.LengthOfGracePeriod), A._) + A.That.Matches(n => n.DaysUntilDeletion == IdentityDeletionConfiguration.Instance.LengthOfGracePeriodInDays), + A._) ).MustHaveHappenedOnceExactly(); response.Id.Should().Be(deletionProcess.Id); diff --git a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateDeletionProcesses/HandlerTests.cs b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateDeletionProcesses/HandlerTests.cs index dfe8dc7bd7..8889229c70 100644 --- a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateDeletionProcesses/HandlerTests.cs +++ b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateDeletionProcesses/HandlerTests.cs @@ -52,7 +52,7 @@ public async Task Deletion_process_started_successfully() var anIdentity = identities.First(); anIdentity.StartDeletionProcessAsOwner(anIdentity.Devices.First().Id); - SystemTime.Set(SystemTime.UtcNow.AddDays(IdentityDeletionConfiguration.LengthOfGracePeriod + 1)); + SystemTime.Set(SystemTime.UtcNow.AddDays(IdentityDeletionConfiguration.Instance.LengthOfGracePeriodInDays)); var handler = CreateHandler(identitiesRepository); diff --git a/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionStartedTests.cs b/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionStartedTests.cs index 3feee3a912..4f00553800 100644 --- a/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionStartedTests.cs +++ b/Modules/Devices/test/Devices.Domain.Tests/Identities/DeletionStartedTests.cs @@ -13,7 +13,7 @@ public void DeletionStarted_sets_status_and_creates_valid_DeletionProcess() // Arrange var identity = CreateIdentityWithApprovedDeletionProcess(); - SystemTime.Set(SystemTime.UtcNow.AddDays(IdentityDeletionConfiguration.LengthOfGracePeriod).AddDays(1)); // past deletion grace period + SystemTime.Set(SystemTime.UtcNow.AddDays(IdentityDeletionConfiguration.Instance.LengthOfGracePeriodInDays).AddDays(1)); // past deletion grace period // Act identity.DeletionStarted(); @@ -69,7 +69,7 @@ public void Raises_domain_events() //Arrange var activeIdentity = TestDataGenerator.CreateIdentityWithApprovedDeletionProcess(); - SystemTime.Set(SystemTime.UtcNow.AddDays(IdentityDeletionConfiguration.LengthOfGracePeriod).AddDays(1)); + SystemTime.Set(SystemTime.UtcNow.AddDays(IdentityDeletionConfiguration.Instance.LengthOfGracePeriodInDays).AddDays(1)); //Act activeIdentity.DeletionStarted(); diff --git a/Modules/Tags/src/Tags.ConsumerApi/Tags.ConsumerApi.csproj b/Modules/Tags/src/Tags.ConsumerApi/Tags.ConsumerApi.csproj index 70e3ad5aab..6e4bfc38c0 100644 --- a/Modules/Tags/src/Tags.ConsumerApi/Tags.ConsumerApi.csproj +++ b/Modules/Tags/src/Tags.ConsumerApi/Tags.ConsumerApi.csproj @@ -6,6 +6,6 @@ - +