Skip to content

Commit

Permalink
Merge branch 'main' into deletion-of-files-tokens-and-relationship-te…
Browse files Browse the repository at this point in the history
…mplates
  • Loading branch information
MH321Productions committed Nov 6, 2024
2 parents 1221a52 + 37c0c55 commit b8fc0fe
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<DevicesConfiguration.InfrastructureConfiguration>(configuration.GetSection("Infrastructure").Bind);

var infrastructureConfiguration = services.BuildServiceProvider().GetRequiredService<IOptions<DevicesConfiguration.InfrastructureConfiguration>>().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<ISignatureHelper, SignatureHelper>(_ => SignatureHelper.CreateEd25519WithRawKeyFormat());
Expand Down
7 changes: 2 additions & 5 deletions Applications/AdminApi/src/AdminApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,9 +95,7 @@ static void ConfigureServices(IServiceCollection services, IConfiguration config

services.AddSingleton<ApiKeyValidator>();

services
.ConfigureAndValidate<AdminConfiguration>(configuration.Bind)
.ConfigureAndValidate<ApplicationOptions>(options => configuration.GetSection("Modules:Devices:Application").Bind(options));
services.ConfigureAndValidate<AdminConfiguration>(configuration.Bind);

#pragma warning disable ASP0000 // We retrieve the Configuration via IOptions here so that it is validated
var parsedConfiguration = services.BuildServiceProvider().GetRequiredService<IOptions<AdminConfiguration>>().Value;
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Applications/AdminCli/src/AdminCli/ServiceLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static IServiceCollection ConfigureServices(string dbProvider, string db
options.AddApplicationStore<CustomOpenIddictEntityFrameworkCoreApplicationStore>();
});

services.AddApplication();
services.AddApplicationWithoutIdentityDeletion();

services.AddSingleton<IQuotaChecker, AlwaysSuccessQuotaChecker>();

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"papaparse": "^5.4.1",
"prettier": "3.3.3",
"typescript": "5.6.3",
"webpack": "5.95.0",
"webpack": "5.96.1",
"webpack-cli": "5.1.4",
"webpack-glob-entries": "1.0.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageReference Include="Testcontainers.PostgreSql" Version="3.10.0" />
<PackageReference Include="Testcontainers.PostgreSql" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<PackageReference Include="FluentValidation" Version="11.10.0" />
<PackageReference Include="MediatR" Version="12.4.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="ReHackt.Extensions.Options.Validation" Version="8.0.3" />
</ItemGroup>


Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023 j&s-soft GmbH
Copyright 2024 j&s-soft AG

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApplicationOptions>(applicationConfiguration.Bind);

applicationConfiguration.GetSection("IdentityDeletion").Bind(IdentityDeletionConfiguration.Instance);

services.AddApplicationWithoutIdentityDeletion();
}

public static void AddApplicationWithoutIdentityDeletion(this IServiceCollection services)
{
services.AddMediatR(c => c
.RegisterServicesFromAssemblyContaining<RegisterDeviceCommand>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ public async Task<ApproveDeletionProcessResponse> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,53 +31,56 @@ 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)
{
_logger.NoApprovalReminderSent();
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);
Expand Down
Loading

0 comments on commit b8fc0fe

Please sign in to comment.