@RenderBody() diff --git a/SS14.Web/Views/Shared/_LoginPartial.cshtml b/SS14.Web/Views/Shared/_LoginPartial.cshtml index 0a437cc7..bf8dac14 100644 --- a/SS14.Web/Views/Shared/_LoginPartial.cshtml +++ b/SS14.Web/Views/Shared/_LoginPartial.cshtml @@ -1,7 +1,6 @@ @using Microsoft.AspNetCore.Identity @using SS14.Auth.Shared.Data @inject SignInManager SignInManager -@inject UserManager UserManager \ No newline at end of file + From e3fdc0ae480ba049e87924d6d67355bba2dbd61a Mon Sep 17 00:00:00 2001 From: juliangiebel Date: Sat, 3 Oct 2026 01:05:25 +0200 Subject: [PATCH 05/14] Address reviews --- .../Data/Migrations/20260629110044_UserDeletionQueue.cs | 2 +- SS14.Auth.Shared/Data/SpaceUserManager.cs | 2 +- SS14.Auth.Shared/Data/UserDeletionQueueEntry.cs | 2 +- SS14.Auth/Jobs/DeleteMarkedUsersJob.cs | 9 +++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/SS14.Auth.Shared/Data/Migrations/20260629110044_UserDeletionQueue.cs b/SS14.Auth.Shared/Data/Migrations/20260629110044_UserDeletionQueue.cs index 949f5797..0780005e 100644 --- a/SS14.Auth.Shared/Data/Migrations/20260629110044_UserDeletionQueue.cs +++ b/SS14.Auth.Shared/Data/Migrations/20260629110044_UserDeletionQueue.cs @@ -14,7 +14,7 @@ protected override void Up(MigrationBuilder migrationBuilder) columns: table => new { SpaceUserId = table.Column(type: "uuid", nullable: false), - QueuedOn = table.Column(type: "timestamp with time zone", nullable: true, defaultValueSql: "now()") + QueuedOn = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()") }, constraints: table => { diff --git a/SS14.Auth.Shared/Data/SpaceUserManager.cs b/SS14.Auth.Shared/Data/SpaceUserManager.cs index 76ec31d2..da9e0de0 100644 --- a/SS14.Auth.Shared/Data/SpaceUserManager.cs +++ b/SS14.Auth.Shared/Data/SpaceUserManager.cs @@ -61,7 +61,7 @@ public async Task FindByNameOrEmailAsync(string nameOrEmail) /// The user to be queued for deletion. public void QueueDeletion(SpaceUser user) { - dbContext.UserDeletionQueue.Add(new UserDeletionQueueEntry {SpaceUserId = user.Id, QueuedOn = DateTime.UtcNow }); + dbContext.UserDeletionQueue.Add(new UserDeletionQueueEntry { SpaceUserId = user.Id, QueuedOn = DateTime.UtcNow }); dbContext.SaveChanges(); } diff --git a/SS14.Auth.Shared/Data/UserDeletionQueueEntry.cs b/SS14.Auth.Shared/Data/UserDeletionQueueEntry.cs index 8a27ec54..59238113 100644 --- a/SS14.Auth.Shared/Data/UserDeletionQueueEntry.cs +++ b/SS14.Auth.Shared/Data/UserDeletionQueueEntry.cs @@ -6,5 +6,5 @@ namespace SS14.Auth.Shared.Data; public class UserDeletionQueueEntry { [Required] public Guid SpaceUserId { get; set; } - public DateTime? QueuedOn { get; set; } + public DateTime QueuedOn { get; set; } } diff --git a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs index 708e3106..397223d6 100644 --- a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs +++ b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs @@ -5,24 +5,26 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Quartz; +using SS14.Auth.Shared.Config; using SS14.Auth.Shared.Data; namespace SS14.Auth.Jobs; public sealed class DeleteMarkedUsersJob( ApplicationDbContext dbContext, - IConfiguration configuration, + IOptions configuration, UserManager userManager, ILogger logger) : IJob { public async Task Execute(IJobExecutionContext context) { - var gracePeriod = configuration.GetValue("AccountConfiguration:UserDeletionGracePeriodDays"); + var gracePeriod = configuration.Value.UserDeletionGracePeriodDays; var entries = await dbContext.UserDeletionQueue .Where(e => e.QueuedOn < DateTime.UtcNow.AddDays(-gracePeriod)) - .ToListAsync(); + .ToListAsync(context.CancellationToken); foreach (var entry in entries) { var user = await userManager.FindByIdAsync(entry.SpaceUserId.ToString()); @@ -36,7 +38,6 @@ public async Task Execute(IJobExecutionContext context) var result = await userManager.DeleteAsync(user); if (!result.Succeeded) logger.LogError("Failed to delete user {Id} marked for deletion.", entry.SpaceUserId); - } await dbContext.SaveChangesAsync(); From 97701f3d9a34da6949f101f00d905753e4828d64 Mon Sep 17 00:00:00 2001 From: juliangiebel Date: Sat, 3 Oct 2026 01:39:09 +0200 Subject: [PATCH 06/14] Implement sending an email to support containing a list of deleted accounts --- SS14.Auth/Jobs/DeleteMarkedUsersJob.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs index 397223d6..2585c21b 100644 --- a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs +++ b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs @@ -1,14 +1,15 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Quartz; using SS14.Auth.Shared.Config; using SS14.Auth.Shared.Data; +using SS14.Auth.Shared.Emails; namespace SS14.Auth.Jobs; @@ -16,6 +17,7 @@ public sealed class DeleteMarkedUsersJob( ApplicationDbContext dbContext, IOptions configuration, UserManager userManager, + EmailSender emailSender, ILogger logger) : IJob { public async Task Execute(IJobExecutionContext context) @@ -25,6 +27,9 @@ public async Task Execute(IJobExecutionContext context) var entries = await dbContext.UserDeletionQueue .Where(e => e.QueuedOn < DateTime.UtcNow.AddDays(-gracePeriod)) .ToListAsync(context.CancellationToken); + + var deletedAccounts = new List<(Guid, string?)>(); + foreach (var entry in entries) { var user = await userManager.FindByIdAsync(entry.SpaceUserId.ToString()); @@ -38,8 +43,20 @@ public async Task Execute(IJobExecutionContext context) var result = await userManager.DeleteAsync(user); if (!result.Succeeded) logger.LogError("Failed to delete user {Id} marked for deletion.", entry.SpaceUserId); + deletedAccounts.Add((entry.SpaceUserId, user.UserName)); } await dbContext.SaveChangesAsync(); + + if (deletedAccounts.Count == 0) + return; + + // Email support@spacestation14.com a list of the deleted accounts so we can manually delete them from the forum and the game db + // Remove this once the gdpr deletion flow is fully automated + await emailSender.SendEmailAsync( + "support@spacestation14.com", + "Processed account deletions", + $"Deleted {deletedAccounts.Count} accounts:\n{string.Join("\n", deletedAccounts.Select(x => $"{x.Item2} | {x.Item1}"))}"); + } } From 29d76b9bf9fe39472db7d6bfaae21e5c98325766 Mon Sep 17 00:00:00 2001 From: juliangiebel Date: Sat, 3 Oct 2026 11:12:19 +0200 Subject: [PATCH 07/14] Move deletion queue email to ModelShared.cs --- SS14.Auth.Shared/ModelShared.cs | 17 +++++++++++++++++ SS14.Auth/Jobs/DeleteMarkedUsersJob.cs | 9 ++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/SS14.Auth.Shared/ModelShared.cs b/SS14.Auth.Shared/ModelShared.cs index 155367eb..19a854c4 100644 --- a/SS14.Auth.Shared/ModelShared.cs +++ b/SS14.Auth.Shared/ModelShared.cs @@ -1,3 +1,6 @@ +using System; +using System.Collections.Generic; +using System.Linq; using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; @@ -25,6 +28,20 @@ await emailSender.SendEmailAsync( $"\n

If the above link is not working, try this one {HtmlEncoder.Default.Encode(callbackUrl)} + /// Email support@spacestation14.com a list of the deleted accounts so we can manually delete them from the forum and the game db + /// Remove this once the gdpr deletion flow is fully automated + /// + /// The email sender instance used for sending + /// The list of usernames and ids of the deleted accounts + public static async Task SendUserDeletionQueueEmail(IEmailSender emailSender, List<(Guid, string)> deletedAccounts) + { + await emailSender.SendEmailAsync( + "support@spacestation14.com", + "Processed account deletions", + $"Deleted {deletedAccounts.Count} accounts:\n{string.Join("\n", deletedAccounts.Select(x => $"{x.Item2} | {x.Item1}"))}"); + } + public static SpaceUser CreateNewUser(string userName, string email, ISystemClock systemClock) { return new SpaceUser {UserName = userName, Email = email, CreatedTime = systemClock.UtcNow}; diff --git a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs index 2585c21b..13811171 100644 --- a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs +++ b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Quartz; +using SS14.Auth.Shared; using SS14.Auth.Shared.Config; using SS14.Auth.Shared.Data; using SS14.Auth.Shared.Emails; @@ -51,12 +52,6 @@ public async Task Execute(IJobExecutionContext context) if (deletedAccounts.Count == 0) return; - // Email support@spacestation14.com a list of the deleted accounts so we can manually delete them from the forum and the game db - // Remove this once the gdpr deletion flow is fully automated - await emailSender.SendEmailAsync( - "support@spacestation14.com", - "Processed account deletions", - $"Deleted {deletedAccounts.Count} accounts:\n{string.Join("\n", deletedAccounts.Select(x => $"{x.Item2} | {x.Item1}"))}"); - + await ModelShared.SendUserDeletionQueueEmail(emailSender, deletedAccounts); } } From 562734726659111f8e702592dccba07496aa3321 Mon Sep 17 00:00:00 2001 From: juliangiebel Date: Sat, 3 Oct 2026 20:50:42 +0200 Subject: [PATCH 08/14] Address reviews --- SS14.Auth.Shared/Data/DeletedUser.cs | 1 + ...dUserDeletionPropergatedColumn.Designer.cs | 1827 +++++++++++++++++ ...184718_AddUserDeletionPropergatedColumn.cs | 48 + .../ApplicationDbContextModelSnapshot.cs | 5 +- SS14.Auth.Shared/ModelShared.cs | 8 + SS14.Auth/Jobs/DeleteMarkedUsersJob.cs | 4 + .../Admin/Pages/Users/ConfirmDelete.cshtml.cs | 1 - .../Account/Manage/DeletePersonalData.cshtml | 7 + 8 files changed, 1899 insertions(+), 2 deletions(-) create mode 100644 SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.Designer.cs create mode 100644 SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.cs diff --git a/SS14.Auth.Shared/Data/DeletedUser.cs b/SS14.Auth.Shared/Data/DeletedUser.cs index 800ca8e3..99b4f192 100644 --- a/SS14.Auth.Shared/Data/DeletedUser.cs +++ b/SS14.Auth.Shared/Data/DeletedUser.cs @@ -6,4 +6,5 @@ public sealed class DeletedUser { public Guid SpaceUserId { get; set; } public DateTime DeletedOn { get; set; } + public bool DeletionPropagated { get; set; } } diff --git a/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.Designer.cs b/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.Designer.cs new file mode 100644 index 00000000..efe67fdf --- /dev/null +++ b/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.Designer.cs @@ -0,0 +1,1827 @@ +// +using System; +using System.Net; +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using SS14.Auth.Shared.Data; + +#nullable disable + +namespace SS14.Auth.Shared.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20261003184718_AddUserDeletionPropergatedColumn")] + partial class AddUserDeletionPropergatedColumn + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResource", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AllowedAccessTokenSigningAlgorithms") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("DisplayName") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Enabled") + .HasColumnType("boolean"); + + b.Property("LastAccessed") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("NonEditable") + .HasColumnType("boolean"); + + b.Property("ShowInDiscoveryDocument") + .HasColumnType("boolean"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("ApiResources", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResourceClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApiResourceId") + .HasColumnType("integer"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.HasKey("Id"); + + b.HasIndex("ApiResourceId"); + + b.ToTable("ApiResourceClaims", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResourceProperty", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApiResourceId") + .HasColumnType("integer"); + + b.Property("Key") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("Value") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.HasKey("Id"); + + b.HasIndex("ApiResourceId"); + + b.ToTable("ApiResourceProperties", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResourceScope", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApiResourceId") + .HasColumnType("integer"); + + b.Property("Scope") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.HasKey("Id"); + + b.HasIndex("ApiResourceId"); + + b.ToTable("ApiResourceScopes", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResourceSecret", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApiResourceId") + .HasColumnType("integer"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("Expiration") + .HasColumnType("timestamp with time zone"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("Value") + .IsRequired() + .HasMaxLength(4000) + .HasColumnType("character varying(4000)"); + + b.HasKey("Id"); + + b.HasIndex("ApiResourceId"); + + b.ToTable("ApiResourceSecrets", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiScope", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("DisplayName") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Emphasize") + .HasColumnType("boolean"); + + b.Property("Enabled") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Required") + .HasColumnType("boolean"); + + b.Property("ShowInDiscoveryDocument") + .HasColumnType("boolean"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("ApiScopes", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiScopeClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ScopeId") + .HasColumnType("integer"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.HasKey("Id"); + + b.HasIndex("ScopeId"); + + b.ToTable("ApiScopeClaims", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiScopeProperty", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Key") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("ScopeId") + .HasColumnType("integer"); + + b.Property("Value") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.HasKey("Id"); + + b.HasIndex("ScopeId"); + + b.ToTable("ApiScopeProperties", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AbsoluteRefreshTokenLifetime") + .HasColumnType("integer"); + + b.Property("AccessTokenLifetime") + .HasColumnType("integer"); + + b.Property("AccessTokenType") + .HasColumnType("integer"); + + b.Property("AllowAccessTokensViaBrowser") + .HasColumnType("boolean"); + + b.Property("AllowOfflineAccess") + .HasColumnType("boolean"); + + b.Property("AllowPlainTextPkce") + .HasColumnType("boolean"); + + b.Property("AllowRememberConsent") + .HasColumnType("boolean"); + + b.Property("AllowedIdentityTokenSigningAlgorithms") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("AlwaysIncludeUserClaimsInIdToken") + .HasColumnType("boolean"); + + b.Property("AlwaysSendClientClaims") + .HasColumnType("boolean"); + + b.Property("AuthorizationCodeLifetime") + .HasColumnType("integer"); + + b.Property("BackChannelLogoutSessionRequired") + .HasColumnType("boolean"); + + b.Property("BackChannelLogoutUri") + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("ClientClaimsPrefix") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("ClientId") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("ClientName") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("ClientUri") + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("ConsentLifetime") + .HasColumnType("integer"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("DeviceCodeLifetime") + .HasColumnType("integer"); + + b.Property("EnableLocalLogin") + .HasColumnType("boolean"); + + b.Property("Enabled") + .HasColumnType("boolean"); + + b.Property("FrontChannelLogoutSessionRequired") + .HasColumnType("boolean"); + + b.Property("FrontChannelLogoutUri") + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("IdentityTokenLifetime") + .HasColumnType("integer"); + + b.Property("IncludeJwtId") + .HasColumnType("boolean"); + + b.Property("LastAccessed") + .HasColumnType("timestamp with time zone"); + + b.Property("LogoUri") + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("NonEditable") + .HasColumnType("boolean"); + + b.Property("PairWiseSubjectSalt") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("ProtocolType") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("RefreshTokenExpiration") + .HasColumnType("integer"); + + b.Property("RefreshTokenUsage") + .HasColumnType("integer"); + + b.Property("RequireClientSecret") + .HasColumnType("boolean"); + + b.Property("RequireConsent") + .HasColumnType("boolean"); + + b.Property("RequirePkce") + .HasColumnType("boolean"); + + b.Property("RequireRequestObject") + .HasColumnType("boolean"); + + b.Property("SlidingRefreshTokenLifetime") + .HasColumnType("integer"); + + b.Property("UpdateAccessTokenClaimsOnRefresh") + .HasColumnType("boolean"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.Property("UserCodeType") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("UserSsoLifetime") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ClientId") + .IsUnique(); + + b.ToTable("Clients", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("Value") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("ClientClaims", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientCorsOrigin", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Origin") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("character varying(150)"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("ClientCorsOrigins", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientGrantType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("GrantType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("ClientGrantTypes", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientIdPRestriction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Provider") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("ClientIdPRestrictions", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientPostLogoutRedirectUri", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("PostLogoutRedirectUri") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("ClientPostLogoutRedirectUris", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientProperty", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Key") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("Value") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("ClientProperties", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientRedirectUri", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("RedirectUri") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("ClientRedirectUris", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientScope", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Scope") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("ClientScopes", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientSecret", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("Expiration") + .HasColumnType("timestamp with time zone"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("Value") + .IsRequired() + .HasMaxLength(4000) + .HasColumnType("character varying(4000)"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("ClientSecrets", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.DeviceFlowCodes", b => + { + b.Property("UserCode") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("ClientId") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Data") + .IsRequired() + .HasMaxLength(50000) + .HasColumnType("character varying(50000)"); + + b.Property("Description") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("DeviceCode") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Expiration") + .IsRequired() + .HasColumnType("timestamp with time zone"); + + b.Property("SessionId") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("SubjectId") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.HasKey("UserCode"); + + b.HasIndex("DeviceCode") + .IsUnique(); + + b.HasIndex("Expiration"); + + b.ToTable("DeviceCodes", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.IdentityResource", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("DisplayName") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Emphasize") + .HasColumnType("boolean"); + + b.Property("Enabled") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("NonEditable") + .HasColumnType("boolean"); + + b.Property("Required") + .HasColumnType("boolean"); + + b.Property("ShowInDiscoveryDocument") + .HasColumnType("boolean"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("IdentityResources", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.IdentityResourceClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("IdentityResourceId") + .HasColumnType("integer"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.HasKey("Id"); + + b.HasIndex("IdentityResourceId"); + + b.ToTable("IdentityResourceClaims", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.IdentityResourceProperty", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("IdentityResourceId") + .HasColumnType("integer"); + + b.Property("Key") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("Value") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.HasKey("Id"); + + b.HasIndex("IdentityResourceId"); + + b.ToTable("IdentityResourceProperties", "IS4"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.PersistedGrant", b => + { + b.Property("Key") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("ClientId") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("ConsumedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Data") + .IsRequired() + .HasMaxLength(50000) + .HasColumnType("character varying(50000)"); + + b.Property("Description") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Expiration") + .HasColumnType("timestamp with time zone"); + + b.Property("SessionId") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("SubjectId") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Key"); + + b.HasIndex("Expiration"); + + b.HasIndex("SubjectId", "ClientId", "Type"); + + b.HasIndex("SubjectId", "SessionId", "Type"); + + b.ToTable("PersistedGrants", "IS4"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FriendlyName") + .HasColumnType("text"); + + b.Property("Xml") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("DataProtectionKeys"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.AccountLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Actor") + .HasColumnType("uuid"); + + b.Property("ActorAddress") + .HasColumnType("inet"); + + b.Property("Data") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("SpaceUserId") + .HasColumnType("uuid"); + + b.Property("Time") + .HasColumnType("timestamp with time zone"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("SpaceUserId"); + + b.ToTable("AccountLogs"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.AuthHash", b => + { + b.Property("AuthHashId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("AuthHashId")); + + b.Property("Expires") + .HasColumnType("timestamp with time zone"); + + b.Property("Hash") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("HwidId") + .HasColumnType("bigint"); + + b.Property("SpaceUserId") + .HasColumnType("uuid"); + + b.HasKey("AuthHashId"); + + b.HasIndex("HwidId"); + + b.HasIndex("SpaceUserId"); + + b.HasIndex("Hash", "SpaceUserId") + .IsUnique(); + + b.ToTable("AuthHashes"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.BurnerEmail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Domain") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("Domain") + .IsUnique(); + + b.ToTable("BurnerEmails"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.DeletedUser", b => + { + b.Property("SpaceUserId") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DeletedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("DeletionPropagated") + .HasColumnType("boolean"); + + b.HasKey("SpaceUserId"); + + b.HasIndex("DeletedOn"); + + b.ToTable("DeletedUserIds"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.Hwid", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientData") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("TypeCode") + .HasColumnType("integer"); + + b.Property("Value") + .IsRequired() + .HasColumnType("bytea"); + + b.HasKey("Id"); + + b.HasIndex("ClientData") + .IsUnique(); + + b.ToTable("Hwids"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.HwidUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FirstSeen") + .HasColumnType("timestamp with time zone"); + + b.Property("HwidId") + .HasColumnType("bigint"); + + b.Property("SpaceUserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SpaceUserId"); + + b.HasIndex("HwidId", "SpaceUserId") + .IsUnique(); + + b.ToTable("HwidUsers"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.LoginSession", b => + { + b.Property("LoginSessionId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("LoginSessionId")); + + b.Property("Expires") + .HasColumnType("timestamp with time zone"); + + b.Property("SpaceUserId") + .HasColumnType("uuid"); + + b.Property("Token") + .IsRequired() + .HasColumnType("bytea"); + + b.HasKey("LoginSessionId"); + + b.HasIndex("SpaceUserId"); + + b.HasIndex("Token") + .IsUnique(); + + b.ToTable("ActiveSessions"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.PastAccountName", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ChangeTime") + .HasColumnType("timestamp with time zone"); + + b.Property("PastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("SpaceUserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SpaceUserId"); + + b.ToTable("PastAccountNames"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.PatreonWebhookLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Content") + .HasColumnType("jsonb"); + + b.Property("Time") + .HasColumnType("timestamp with time zone"); + + b.Property("Trigger") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("PatreonWebhookLogs"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.Patron", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CurrentTier") + .HasColumnType("text"); + + b.Property("PatreonId") + .IsRequired() + .HasColumnType("text"); + + b.Property("SpaceUserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("PatreonId") + .IsUnique(); + + b.HasIndex("SpaceUserId") + .IsUnique(); + + b.ToTable("Patrons"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.SpaceRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.SpaceUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AdminLocked") + .HasColumnType("boolean"); + + b.Property("AdminNotes") + .IsRequired() + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LastUsernameChange") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.UserDeletionQueueEntry", b => + { + b.Property("SpaceUserId") + .HasColumnType("uuid"); + + b.Property("QueuedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.HasKey("SpaceUserId"); + + b.ToTable("UserDeletionQueue"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.UserOAuthClient", b => + { + b.Property("UserOAuthClientId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("UserOAuthClientId")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("SpaceUserId") + .HasColumnType("uuid"); + + b.HasKey("UserOAuthClientId"); + + b.HasIndex("ClientId") + .IsUnique(); + + b.HasIndex("SpaceUserId"); + + b.ToTable("UserOAuthClients"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.WhitelistEmail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Domain") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("Domain") + .IsUnique(); + + b.ToTable("WhitelistEmails"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResourceClaim", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.ApiResource", "ApiResource") + .WithMany("UserClaims") + .HasForeignKey("ApiResourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApiResource"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResourceProperty", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.ApiResource", "ApiResource") + .WithMany("Properties") + .HasForeignKey("ApiResourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApiResource"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResourceScope", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.ApiResource", "ApiResource") + .WithMany("Scopes") + .HasForeignKey("ApiResourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApiResource"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResourceSecret", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.ApiResource", "ApiResource") + .WithMany("Secrets") + .HasForeignKey("ApiResourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApiResource"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiScopeClaim", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.ApiScope", "Scope") + .WithMany("UserClaims") + .HasForeignKey("ScopeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Scope"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiScopeProperty", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.ApiScope", "Scope") + .WithMany("Properties") + .HasForeignKey("ScopeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Scope"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientClaim", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.Client", "Client") + .WithMany("Claims") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientCorsOrigin", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.Client", "Client") + .WithMany("AllowedCorsOrigins") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientGrantType", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.Client", "Client") + .WithMany("AllowedGrantTypes") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientIdPRestriction", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.Client", "Client") + .WithMany("IdentityProviderRestrictions") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientPostLogoutRedirectUri", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.Client", "Client") + .WithMany("PostLogoutRedirectUris") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientProperty", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.Client", "Client") + .WithMany("Properties") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientRedirectUri", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.Client", "Client") + .WithMany("RedirectUris") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientScope", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.Client", "Client") + .WithMany("AllowedScopes") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ClientSecret", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.Client", "Client") + .WithMany("ClientSecrets") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.IdentityResourceClaim", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.IdentityResource", "IdentityResource") + .WithMany("UserClaims") + .HasForeignKey("IdentityResourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("IdentityResource"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.IdentityResourceProperty", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.IdentityResource", "IdentityResource") + .WithMany("Properties") + .HasForeignKey("IdentityResourceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("IdentityResource"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("SS14.Auth.Shared.Data.SpaceRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("SS14.Auth.Shared.Data.SpaceRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.AccountLog", b => + { + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", "SpaceUser") + .WithMany("AccountLogs") + .HasForeignKey("SpaceUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("SpaceUser"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.AuthHash", b => + { + b.HasOne("SS14.Auth.Shared.Data.Hwid", "Hwid") + .WithMany() + .HasForeignKey("HwidId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", "SpaceUser") + .WithMany("AuthHashes") + .HasForeignKey("SpaceUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Hwid"); + + b.Navigation("SpaceUser"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.HwidUser", b => + { + b.HasOne("SS14.Auth.Shared.Data.Hwid", "Hwid") + .WithMany("Users") + .HasForeignKey("HwidId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", "SpaceUser") + .WithMany() + .HasForeignKey("SpaceUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Hwid"); + + b.Navigation("SpaceUser"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.LoginSession", b => + { + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", "SpaceUser") + .WithMany("LoginSessions") + .HasForeignKey("SpaceUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("SpaceUser"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.PastAccountName", b => + { + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", "SpaceUser") + .WithMany("PastAccountNames") + .HasForeignKey("SpaceUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("SpaceUser"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.Patron", b => + { + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", "SpaceUser") + .WithOne("Patron") + .HasForeignKey("SS14.Auth.Shared.Data.Patron", "SpaceUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("SpaceUser"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.UserDeletionQueueEntry", b => + { + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", null) + .WithOne() + .HasForeignKey("SS14.Auth.Shared.Data.UserDeletionQueueEntry", "SpaceUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.UserOAuthClient", b => + { + b.HasOne("IdentityServer4.EntityFramework.Entities.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SS14.Auth.Shared.Data.SpaceUser", "SpaceUser") + .WithMany() + .HasForeignKey("SpaceUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("SpaceUser"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResource", b => + { + b.Navigation("Properties"); + + b.Navigation("Scopes"); + + b.Navigation("Secrets"); + + b.Navigation("UserClaims"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiScope", b => + { + b.Navigation("Properties"); + + b.Navigation("UserClaims"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.Client", b => + { + b.Navigation("AllowedCorsOrigins"); + + b.Navigation("AllowedGrantTypes"); + + b.Navigation("AllowedScopes"); + + b.Navigation("Claims"); + + b.Navigation("ClientSecrets"); + + b.Navigation("IdentityProviderRestrictions"); + + b.Navigation("PostLogoutRedirectUris"); + + b.Navigation("Properties"); + + b.Navigation("RedirectUris"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.IdentityResource", b => + { + b.Navigation("Properties"); + + b.Navigation("UserClaims"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.Hwid", b => + { + b.Navigation("Users"); + }); + + modelBuilder.Entity("SS14.Auth.Shared.Data.SpaceUser", b => + { + b.Navigation("AccountLogs"); + + b.Navigation("AuthHashes"); + + b.Navigation("LoginSessions"); + + b.Navigation("PastAccountNames"); + + b.Navigation("Patron"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.cs b/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.cs new file mode 100644 index 00000000..9b39ec43 --- /dev/null +++ b/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.cs @@ -0,0 +1,48 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SS14.Auth.Shared.Data.Migrations +{ + public partial class AddUserDeletionPropergatedColumn : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "QueuedOn", + table: "UserDeletionQueue", + type: "timestamp with time zone", + nullable: false, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldNullable: true, + oldDefaultValueSql: "now()"); + + migrationBuilder.AddColumn( + name: "DeletionPropagated", + table: "DeletedUserIds", + type: "boolean", + nullable: false, + defaultValue: false); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "DeletionPropagated", + table: "DeletedUserIds"); + + migrationBuilder.AlterColumn( + name: "QueuedOn", + table: "UserDeletionQueue", + type: "timestamp with time zone", + nullable: true, + defaultValueSql: "now()", + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone", + oldDefaultValueSql: "now()"); + } + } +} diff --git a/SS14.Auth.Shared/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/SS14.Auth.Shared/Data/Migrations/ApplicationDbContextModelSnapshot.cs index 786f776e..2e07848b 100644 --- a/SS14.Auth.Shared/Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/SS14.Auth.Shared/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1093,6 +1093,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("timestamp with time zone") .HasDefaultValueSql("now()"); + b.Property("DeletionPropagated") + .HasColumnType("boolean"); + b.HasKey("SpaceUserId"); b.HasIndex("DeletedOn"); @@ -1353,7 +1356,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("SpaceUserId") .HasColumnType("uuid"); - b.Property("QueuedOn") + b.Property("QueuedOn") .ValueGeneratedOnAdd() .HasColumnType("timestamp with time zone") .HasDefaultValueSql("now()"); diff --git a/SS14.Auth.Shared/ModelShared.cs b/SS14.Auth.Shared/ModelShared.cs index 19a854c4..5cf8b9d7 100644 --- a/SS14.Auth.Shared/ModelShared.cs +++ b/SS14.Auth.Shared/ModelShared.cs @@ -42,6 +42,14 @@ await emailSender.SendEmailAsync( $"Deleted {deletedAccounts.Count} accounts:\n{string.Join("\n", deletedAccounts.Select(x => $"{x.Item2} | {x.Item1}"))}"); } + public static async Task SendDeletionFailedEmail(EmailSender emailSender, Guid entrySpaceUserId) + { + await emailSender.SendEmailAsync( + "support@spacestation14.com", + "Failed to delete account", + $"Failed to delete account with id {entrySpaceUserId}"); + } + public static SpaceUser CreateNewUser(string userName, string email, ISystemClock systemClock) { return new SpaceUser {UserName = userName, Email = email, CreatedTime = systemClock.UtcNow}; diff --git a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs index 13811171..20889532 100644 --- a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs +++ b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs @@ -43,7 +43,11 @@ public async Task Execute(IJobExecutionContext context) var result = await userManager.DeleteAsync(user); if (!result.Succeeded) + { logger.LogError("Failed to delete user {Id} marked for deletion.", entry.SpaceUserId); + await ModelShared.SendDeletionFailedEmail(emailSender, entry.SpaceUserId); + } + deletedAccounts.Add((entry.SpaceUserId, user.UserName)); } diff --git a/SS14.Web/Areas/Admin/Pages/Users/ConfirmDelete.cshtml.cs b/SS14.Web/Areas/Admin/Pages/Users/ConfirmDelete.cshtml.cs index 952c799e..68186e2a 100644 --- a/SS14.Web/Areas/Admin/Pages/Users/ConfirmDelete.cshtml.cs +++ b/SS14.Web/Areas/Admin/Pages/Users/ConfirmDelete.cshtml.cs @@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.EntityFrameworkCore; using SS14.Auth.Shared.Data; namespace SS14.Web.Areas.Admin.Pages.Users; diff --git a/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml b/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml index 6bc32cac..c8420ae4 100644 --- a/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml +++ b/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml @@ -10,6 +10,13 @@

@ViewData["Title"]

+ + + @if (await userManager.GetDaysUntilDeletionAsync(User) is {} timeSpan) {
From 6db1e24d0c74a6324b71d86c2961a6df80607e01 Mon Sep 17 00:00:00 2001 From: juliangiebel Date: Sat, 3 Oct 2026 20:51:42 +0200 Subject: [PATCH 09/14] Fix typo --- .../Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs b/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs index 9523665f..ce99b1e8 100644 --- a/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs +++ b/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs @@ -61,7 +61,7 @@ public async Task OnPostCancelAsync() _userManager.CancelQueuedDeletion(user); - _logger.LogInformation("User with ID '{UserId}' queued their deletion.", user.Id); + _logger.LogInformation("User with ID '{UserId}' canceled their deletion.", user.Id); StatusMessage = "Account deletion canceled."; return RedirectToPage(); From 99ae335cf4bdac6a91ab3b68f4db93971d20cd82 Mon Sep 17 00:00:00 2001 From: juliangiebel Date: Mon, 5 Oct 2026 16:19:27 +0200 Subject: [PATCH 10/14] Address reviews --- SS14.Auth.Shared/Data/SpaceUserManager.cs | 6 +++++- SS14.Auth.Shared/Data/UserDeletionQueueEntry.cs | 2 +- SS14.Auth.Shared/ModelShared.cs | 2 +- SS14.Auth/Jobs/DeleteMarkedUsersJob.cs | 3 ++- .../Pages/Account/Manage/DeletePersonalData.cshtml | 9 +++++++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/SS14.Auth.Shared/Data/SpaceUserManager.cs b/SS14.Auth.Shared/Data/SpaceUserManager.cs index da9e0de0..3b7da095 100644 --- a/SS14.Auth.Shared/Data/SpaceUserManager.cs +++ b/SS14.Auth.Shared/Data/SpaceUserManager.cs @@ -61,6 +61,9 @@ public async Task FindByNameOrEmailAsync(string nameOrEmail) /// The user to be queued for deletion. public void QueueDeletion(SpaceUser user) { + if (dbContext.UserDeletionQueue.Any(x => x.SpaceUserId == user.Id)) + return; + dbContext.UserDeletionQueue.Add(new UserDeletionQueueEntry { SpaceUserId = user.Id, QueuedOn = DateTime.UtcNow }); dbContext.SaveChanges(); } @@ -85,8 +88,9 @@ public void CancelQueuedDeletion(SpaceUser user) /// public override async Task DeleteAsync(SpaceUser user) { + var result = await base.DeleteAsync(user); dbContext.DeletedUserIds.Add(new DeletedUser { SpaceUserId = user.Id, DeletedOn = DateTime.UtcNow }); - return await base.DeleteAsync(user); + return result; } /// diff --git a/SS14.Auth.Shared/Data/UserDeletionQueueEntry.cs b/SS14.Auth.Shared/Data/UserDeletionQueueEntry.cs index 59238113..2084f34f 100644 --- a/SS14.Auth.Shared/Data/UserDeletionQueueEntry.cs +++ b/SS14.Auth.Shared/Data/UserDeletionQueueEntry.cs @@ -3,7 +3,7 @@ namespace SS14.Auth.Shared.Data; -public class UserDeletionQueueEntry +public sealed class UserDeletionQueueEntry { [Required] public Guid SpaceUserId { get; set; } public DateTime QueuedOn { get; set; } diff --git a/SS14.Auth.Shared/ModelShared.cs b/SS14.Auth.Shared/ModelShared.cs index 5cf8b9d7..2b82ef4a 100644 --- a/SS14.Auth.Shared/ModelShared.cs +++ b/SS14.Auth.Shared/ModelShared.cs @@ -42,7 +42,7 @@ await emailSender.SendEmailAsync( $"Deleted {deletedAccounts.Count} accounts:\n{string.Join("\n", deletedAccounts.Select(x => $"{x.Item2} | {x.Item1}"))}"); } - public static async Task SendDeletionFailedEmail(EmailSender emailSender, Guid entrySpaceUserId) + public static async Task SendDeletionFailedEmail(IEmailSender emailSender, Guid entrySpaceUserId) { await emailSender.SendEmailAsync( "support@spacestation14.com", diff --git a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs index 20889532..525ef5a1 100644 --- a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs +++ b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs @@ -19,7 +19,7 @@ public sealed class DeleteMarkedUsersJob( IOptions configuration, UserManager userManager, EmailSender emailSender, - ILogger logger) : IJob + ILogger logger) : IJob { public async Task Execute(IJobExecutionContext context) { @@ -46,6 +46,7 @@ public async Task Execute(IJobExecutionContext context) { logger.LogError("Failed to delete user {Id} marked for deletion.", entry.SpaceUserId); await ModelShared.SendDeletionFailedEmail(emailSender, entry.SpaceUserId); + return; } deletedAccounts.Add((entry.SpaceUserId, user.UserName)); diff --git a/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml b/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml index c8420ae4..5838d7e4 100644 --- a/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml +++ b/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml @@ -1,7 +1,10 @@ @page +@using Microsoft.Extensions.Options +@using SS14.Auth.Shared.Config @using SS14.Auth.Shared.Data @model DeletePersonalDataModel @inject SpaceUserManager userManager +@inject IOptions config @{ ViewData["Title"] = "Delete Personal Data"; ViewData["ActivePage"] = ManageNavPages.PersonalData; @@ -19,8 +22,10 @@ @if (await userManager.GetDaysUntilDeletionAsync(User) is {} timeSpan) { + var deletionTimeText = timeSpan.Days < 0 ? "soon" : $"in {timeSpan.Days} days"; +
- Your account is marked for deletion and will be deleted in @timeSpan.Days days.
+ Your account is marked for deletion and will be deleted @deletionTimeText
Cancel the deletion process by clicking the button below.
@@ -35,7 +40,7 @@ else From e6b36ba3119f6f1239c7cec6457606161fc3aa98 Mon Sep 17 00:00:00 2001 From: juliangiebel Date: Sat, 31 Oct 2026 18:13:16 +0100 Subject: [PATCH 11/14] Implement transactional emails for deletion queue --- SS14.Auth.Shared/Data/SpaceUserManager.cs | 8 ++--- SS14.Auth.Shared/ModelShared.cs | 31 +++++++++++++++++-- SS14.Auth.Shared/SS14.Auth.Shared.csproj | 1 + SS14.Auth/Jobs/DeleteMarkedUsersJob.cs | 16 ++++++++-- .../Account/Manage/DeletePersonalData.cshtml | 8 ++--- .../Manage/DeletePersonalData.cshtml.cs | 24 ++++++++++---- 6 files changed, 69 insertions(+), 19 deletions(-) diff --git a/SS14.Auth.Shared/Data/SpaceUserManager.cs b/SS14.Auth.Shared/Data/SpaceUserManager.cs index 3b7da095..4aae0fa5 100644 --- a/SS14.Auth.Shared/Data/SpaceUserManager.cs +++ b/SS14.Auth.Shared/Data/SpaceUserManager.cs @@ -59,27 +59,27 @@ public async Task FindByNameOrEmailAsync(string nameOrEmail) /// Adds the specified user to the deletion queue. ///
/// The user to be queued for deletion. - public void QueueDeletion(SpaceUser user) + public async Task QueueDeletion(SpaceUser user) { if (dbContext.UserDeletionQueue.Any(x => x.SpaceUserId == user.Id)) return; dbContext.UserDeletionQueue.Add(new UserDeletionQueueEntry { SpaceUserId = user.Id, QueuedOn = DateTime.UtcNow }); - dbContext.SaveChanges(); + await dbContext.SaveChangesAsync(); } /// /// Removes the specified user from the deletion queue if they are currently queued for deletion. /// /// The user to be removed from the deletion queue. - public void CancelQueuedDeletion(SpaceUser user) + public async Task CancelQueuedDeletion(SpaceUser user) { var entry = dbContext.UserDeletionQueue.FirstOrDefault(x => x.SpaceUserId == user.Id); if (entry == null) return; dbContext.UserDeletionQueue.Remove(entry); - dbContext.SaveChanges(); + await dbContext.SaveChangesAsync(); } /// diff --git a/SS14.Auth.Shared/ModelShared.cs b/SS14.Auth.Shared/ModelShared.cs index 2b82ef4a..4fa81a01 100644 --- a/SS14.Auth.Shared/ModelShared.cs +++ b/SS14.Auth.Shared/ModelShared.cs @@ -25,7 +25,7 @@ await emailSender.SendEmailAsync( "A password reset has been requested for your account.
" + $"If you did indeed request this, click here to reset your password.
" + "If you did not request this, simply ignore this email." + - $"\n

If the above link is not working, try this one {HtmlEncoder.Default.Encode(callbackUrl)}If the above link is not working, try this one {HtmlEncoder.Default.Encode(callbackUrl)}

"); } /// @@ -34,7 +34,7 @@ await emailSender.SendEmailAsync( /// /// The email sender instance used for sending /// The list of usernames and ids of the deleted accounts - public static async Task SendUserDeletionQueueEmail(IEmailSender emailSender, List<(Guid, string)> deletedAccounts) + public static async Task SendUserDeletionQueueEmail(IEmailSender emailSender, List<(Guid, string, string)> deletedAccounts) { await emailSender.SendEmailAsync( "support@spacestation14.com", @@ -50,6 +50,33 @@ await emailSender.SendEmailAsync( $"Failed to delete account with id {entrySpaceUserId}"); } + public static async Task SendDeletionQueuedEmail(IEmailSender emailSender, string email, DateTime deletionDate) + { + // i.E. "June 15, 2023" + var deletionDateString = deletionDate.ToString("MMMM dd, yyyy"); + + await emailSender.SendEmailAsync( + email, + "Account deletion queued", + $"We received a request to delete your Space Station 14 account. It will be permanently deleted on {deletionDateString}.
If you want to keep your account, you can cancel the deletion at any time by logging in at https://account.spacestation14.com
Once the deletion goes through, your account can't be recovered. This includes your login, any OAuth apps you've created an all first party data we keep on you."); + } + + public static async Task SendDeletionCanceledEmail(IEmailSender emailSender, string email) + { + await emailSender.SendEmailAsync( + email, + "Account deletion canceled", + "Your scheduled account deletion has been canceled. Your Space Station 14 account is safe and nothing has been removed."); + } + + public static async Task SendUserDeletedEmail(IEmailSender emailSender, string email) + { + await emailSender.SendEmailAsync( + email, + "Account deleted", + "Your Space Station 14 account has been permanently deleted.
This is the result of a deletion request
OR
/Your account was deleted by account support.
Your login and associated data has been removed, and you will no longer be able to sign in or play on servers using this account. This can't be undone, but you're welcome to create a new account at any time."); + } + public static SpaceUser CreateNewUser(string userName, string email, ISystemClock systemClock) { return new SpaceUser {UserName = userName, Email = email, CreatedTime = systemClock.UtcNow}; diff --git a/SS14.Auth.Shared/SS14.Auth.Shared.csproj b/SS14.Auth.Shared/SS14.Auth.Shared.csproj index 6acfab52..e27e9473 100644 --- a/SS14.Auth.Shared/SS14.Auth.Shared.csproj +++ b/SS14.Auth.Shared/SS14.Auth.Shared.csproj @@ -28,6 +28,7 @@ + diff --git a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs index 525ef5a1..3ff94aa0 100644 --- a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs +++ b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using JetBrains.Annotations; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; @@ -14,11 +15,12 @@ namespace SS14.Auth.Jobs; +[UsedImplicitly] public sealed class DeleteMarkedUsersJob( ApplicationDbContext dbContext, IOptions configuration, UserManager userManager, - EmailSender emailSender, + IEmailSender emailSender, ILogger logger) : IJob { public async Task Execute(IJobExecutionContext context) @@ -29,7 +31,7 @@ public async Task Execute(IJobExecutionContext context) .Where(e => e.QueuedOn < DateTime.UtcNow.AddDays(-gracePeriod)) .ToListAsync(context.CancellationToken); - var deletedAccounts = new List<(Guid, string?)>(); + var deletedAccounts = new List<(Guid, string?, string?)>(); foreach (var entry in entries) { @@ -41,6 +43,7 @@ public async Task Execute(IJobExecutionContext context) continue; } + var deletedAccount = (entry.SpaceUserId, user.UserName, user.Email); var result = await userManager.DeleteAsync(user); if (!result.Succeeded) { @@ -49,7 +52,7 @@ public async Task Execute(IJobExecutionContext context) return; } - deletedAccounts.Add((entry.SpaceUserId, user.UserName)); + deletedAccounts.Add(deletedAccount); } await dbContext.SaveChangesAsync(); @@ -58,5 +61,12 @@ public async Task Execute(IJobExecutionContext context) return; await ModelShared.SendUserDeletionQueueEmail(emailSender, deletedAccounts); + foreach (var (_, _, email) in deletedAccounts) + { + if (email == null) + continue; + + await ModelShared.SendUserDeletedEmail(emailSender, email); + } } } diff --git a/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml b/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml index 5838d7e4..300705a7 100644 --- a/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml +++ b/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml @@ -3,8 +3,8 @@ @using SS14.Auth.Shared.Config @using SS14.Auth.Shared.Data @model DeletePersonalDataModel -@inject SpaceUserManager userManager -@inject IOptions config +@inject SpaceUserManager UserManager +@inject IOptions Config @{ ViewData["Title"] = "Delete Personal Data"; ViewData["ActivePage"] = ManageNavPages.PersonalData; @@ -20,7 +20,7 @@
-@if (await userManager.GetDaysUntilDeletionAsync(User) is {} timeSpan) +@if (await UserManager.GetDaysUntilDeletionAsync(User) is {} timeSpan) { var deletionTimeText = timeSpan.Days < 0 ? "soon" : $"in {timeSpan.Days} days"; @@ -40,7 +40,7 @@ else diff --git a/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs b/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs index ce99b1e8..2a6d3434 100644 --- a/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs +++ b/SS14.Web/Areas/Identity/Pages/Account/Manage/DeletePersonalData.cshtml.cs @@ -1,13 +1,14 @@ - using System; using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using SS14.Auth.Shared; +using SS14.Auth.Shared.Config; using SS14.Auth.Shared.Data; -using SS14.Web.Data; +using SS14.Auth.Shared.Emails; namespace SS14.Web.Areas.Identity.Pages.Account.Manage { @@ -15,13 +16,19 @@ public class DeletePersonalDataModel : PageModel { private readonly SpaceUserManager _userManager; private readonly ILogger _logger; + private readonly IEmailSender _emailSender; + private readonly IOptions _configuration; public DeletePersonalDataModel( SpaceUserManager userManager, - ILogger logger) + ILogger logger, + IEmailSender emailSender, + IOptions configuration) { _userManager = userManager; _logger = logger; + _emailSender = emailSender; + _configuration = configuration; } [TempData] @@ -59,8 +66,9 @@ public async Task OnPostCancelAsync() return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } - _userManager.CancelQueuedDeletion(user); + await _userManager.CancelQueuedDeletion(user); + await ModelShared.SendDeletionCanceledEmail(_emailSender, user.Email); _logger.LogInformation("User with ID '{UserId}' canceled their deletion.", user.Id); StatusMessage = "Account deletion canceled."; @@ -86,8 +94,12 @@ public async Task OnPostDeleteAsync() } var userId = await _userManager.GetUserIdAsync(user); - _userManager.QueueDeletion(user); + await _userManager.QueueDeletion(user); + + var gracePeriod = _configuration.Value.UserDeletionGracePeriodDays; + var deletionDate = DateTime.UtcNow.AddDays(gracePeriod); + await ModelShared.SendDeletionQueuedEmail(_emailSender, user.Email, deletionDate); _logger.LogInformation("User with ID '{UserId}' queued their deletion.", userId); StatusMessage = "Account deletion queued."; From 4d0b20170810e6b9ec49dba4019bbf4f3f241a27 Mon Sep 17 00:00:00 2001 From: juliangiebel Date: Sat, 31 Oct 2026 18:13:35 +0100 Subject: [PATCH 12/14] Implement integration test for user deletion queue --- SS14.Auth.Shared/Data/ApplicationDbContext.cs | 2 +- SS14.Web.Tests/DeleteMarkedUsersJobTests.cs | 128 ++++++++++++++++++ SS14.Web.Tests/SS14.Web.Tests.csproj | 3 +- SS14.Web.Tests/Utils/RecordingEmailSender.cs | 20 +++ .../Utils/TestApplicationDbContext.cs | 23 ++++ .../Utils/TestJobExecutionContext.cs | 49 +++++++ SS14.Web.Tests/Utils/TestUserStore.cs | 98 ++++++++++++++ 7 files changed, 321 insertions(+), 2 deletions(-) create mode 100644 SS14.Web.Tests/DeleteMarkedUsersJobTests.cs create mode 100644 SS14.Web.Tests/Utils/RecordingEmailSender.cs create mode 100644 SS14.Web.Tests/Utils/TestApplicationDbContext.cs create mode 100644 SS14.Web.Tests/Utils/TestJobExecutionContext.cs create mode 100644 SS14.Web.Tests/Utils/TestUserStore.cs diff --git a/SS14.Auth.Shared/Data/ApplicationDbContext.cs b/SS14.Auth.Shared/Data/ApplicationDbContext.cs index 27aa73f9..c2b4d794 100644 --- a/SS14.Auth.Shared/Data/ApplicationDbContext.cs +++ b/SS14.Auth.Shared/Data/ApplicationDbContext.cs @@ -15,7 +15,7 @@ public class ApplicationDbContext : IdentityDbContext options) + public ApplicationDbContext(DbContextOptions options) : base(options) { } diff --git a/SS14.Web.Tests/DeleteMarkedUsersJobTests.cs b/SS14.Web.Tests/DeleteMarkedUsersJobTests.cs new file mode 100644 index 00000000..3d754cc5 --- /dev/null +++ b/SS14.Web.Tests/DeleteMarkedUsersJobTests.cs @@ -0,0 +1,128 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using NUnit.Framework; +using SS14.Auth.Jobs; +using SS14.Auth.Shared.Config; +using SS14.Auth.Shared.Data; +using SS14.Web.Tests.Utils; + +namespace SS14.Web.Tests; + +[TestFixture] +public sealed class TestDeleteMarkedUsersJob +{ + [Test] + public async Task ExecuteDeletesOnlyExpiredQueuedUsersAndSendsDeletionEmails() + { + await using var dbContext = CreateDbContext(); + + var expiredUser = new SpaceUser + { + Id = Guid.NewGuid(), + UserName = "expired-user", + NormalizedUserName = "EXPIRED-USER", + Email = "expired@example.com", + NormalizedEmail = "EXPIRED@EXAMPLE.COM", + EmailConfirmed = true, + CreatedTime = DateTimeOffset.UtcNow + }; + + var recentUser = new SpaceUser + { + Id = Guid.NewGuid(), + UserName = "recent-user", + NormalizedUserName = "RECENT-USER", + Email = "recent@example.com", + NormalizedEmail = "RECENT@EXAMPLE.COM", + EmailConfirmed = true, + CreatedTime = DateTimeOffset.UtcNow, + }; + + dbContext.Users.AddRange(expiredUser, recentUser); + dbContext.UserDeletionQueue.AddRange( + new UserDeletionQueueEntry + { + SpaceUserId = expiredUser.Id, + QueuedOn = DateTime.UtcNow.AddDays(-31), + }, + new UserDeletionQueueEntry + { + SpaceUserId = recentUser.Id, + QueuedOn = DateTime.UtcNow.AddDays(-1), + }); + + await dbContext.SaveChangesAsync(); + + var rawEmailSender = new RecordingEmailSender(); + var userManager = CreateUserManager(dbContext); + var job = new DeleteMarkedUsersJob( + dbContext, + Options.Create(new AccountConfiguration { UserDeletionGracePeriodDays = 30 }), + userManager, + rawEmailSender, + NullLogger.Instance); + + await job.Execute(new TestJobExecutionContext()); + + Assert.Multiple(() => + { + Assert.That(dbContext.Users.Any(u => u.Id == expiredUser.Id), Is.False); + Assert.That(dbContext.Users.Any(u => u.Id == recentUser.Id), Is.True); + + Assert.That(dbContext.DeletedUserIds.Any(u => u.SpaceUserId == expiredUser.Id), Is.True); + Assert.That(dbContext.DeletedUserIds.Any(u => u.SpaceUserId == recentUser.Id), Is.False); + + Assert.That(dbContext.UserDeletionQueue.Any(e => e.SpaceUserId == expiredUser.Id), Is.False); + Assert.That(dbContext.UserDeletionQueue.Any(e => e.SpaceUserId == recentUser.Id), Is.True); + + Assert.That( + rawEmailSender.SentEmails.Any(e => + e.Email == "expired@example.com" && + e.Subject == "Account deleted"), + Is.True); + + Assert.That( + rawEmailSender.SentEmails.Any(e => + e.Email == "support@spacestation14.com" && + e.Subject == "Processed account deletions" && + e.HtmlMessage.Contains(expiredUser.Id.ToString())), + Is.True); + + Assert.That( + rawEmailSender.SentEmails.Any(e => e.Email == "recent@example.com"), + Is.False); + }); + } + + private static TestApplicationDbContext CreateDbContext() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .Options; + + return new TestApplicationDbContext(options); + } + + private static SpaceUserManager CreateUserManager(ApplicationDbContext dbContext) + { + var store = new TestUserStore(dbContext); + + return new SpaceUserManager( + dbContext, + store, + Options.Create(new IdentityOptions()), + new PasswordHasher(), + [], + [], + new UpperInvariantLookupNormalizer(), + new IdentityErrorDescriber(), + null!, + NullLogger>.Instance, + Options.Create(new AccountConfiguration { UserDeletionGracePeriodDays = 30 })); + } +} diff --git a/SS14.Web.Tests/SS14.Web.Tests.csproj b/SS14.Web.Tests/SS14.Web.Tests.csproj index 3f97dfd6..713761ed 100644 --- a/SS14.Web.Tests/SS14.Web.Tests.csproj +++ b/SS14.Web.Tests/SS14.Web.Tests.csproj @@ -2,7 +2,7 @@ net8.0 - + enable false @@ -14,6 +14,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/SS14.Web.Tests/Utils/RecordingEmailSender.cs b/SS14.Web.Tests/Utils/RecordingEmailSender.cs new file mode 100644 index 00000000..3b330424 --- /dev/null +++ b/SS14.Web.Tests/Utils/RecordingEmailSender.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using SS14.Auth.Shared.Emails; + +namespace SS14.Web.Tests.Utils; + + +public sealed class RecordingEmailSender : IRawEmailSender +{ + public List SentEmails { get; } = []; + + public Task SendEmailAsync(string email, string subject, string htmlMessage) + { + SentEmails.Add(new SentEmail(email, subject, htmlMessage)); + return Task.CompletedTask; + } +} + +public sealed record SentEmail(string Email, string Subject, string HtmlMessage); + diff --git a/SS14.Web.Tests/Utils/TestApplicationDbContext.cs b/SS14.Web.Tests/Utils/TestApplicationDbContext.cs new file mode 100644 index 00000000..dc71d5e7 --- /dev/null +++ b/SS14.Web.Tests/Utils/TestApplicationDbContext.cs @@ -0,0 +1,23 @@ +using Microsoft.EntityFrameworkCore; +using SS14.Auth.Shared.Data; + +namespace SS14.Web.Tests.Utils; + +/// +/// Provides a specialized implementation of for testing purposes. +/// This context modifies the default entity configuration specific to tests by ignoring certain entities +/// and properties that are not relevant in the test scenarios. +/// This also ensures json properties don't break tests +/// +public sealed class TestApplicationDbContext(DbContextOptions options) : ApplicationDbContext(options) +{ + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); + + builder.Entity() + .Ignore(x => x.AccountLogs); + + builder.Ignore(); + } +} diff --git a/SS14.Web.Tests/Utils/TestJobExecutionContext.cs b/SS14.Web.Tests/Utils/TestJobExecutionContext.cs new file mode 100644 index 00000000..31881dbd --- /dev/null +++ b/SS14.Web.Tests/Utils/TestJobExecutionContext.cs @@ -0,0 +1,49 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Quartz; + +namespace SS14.Web.Tests.Utils; + +public sealed class TestJobExecutionContext : IJobExecutionContext +{ + public CancellationToken CancellationToken => CancellationToken.None; + + public object? Result { get; set; } + + public IScheduler Scheduler => throw new NotSupportedException(); + public ITrigger Trigger => throw new NotSupportedException(); + public ICalendar? Calendar => throw new NotSupportedException(); + public bool Recovering => false; + public TriggerKey RecoveringTriggerKey => throw new NotSupportedException(); + public int RefireCount => 0; + public JobDataMap MergedJobDataMap => new(); + public IJobDetail JobDetail => throw new NotSupportedException(); + public IJob JobInstance => throw new NotSupportedException(); + public DateTimeOffset FireTimeUtc => DateTimeOffset.UtcNow; + public DateTimeOffset? ScheduledFireTimeUtc => DateTimeOffset.UtcNow; + public DateTimeOffset? PreviousFireTimeUtc => null; + public DateTimeOffset? NextFireTimeUtc => null; + public string FireInstanceId => Guid.NewGuid().ToString(); + public object? RecoveringTriggerData => null; + public TimeSpan JobRunTime => TimeSpan.Zero; + public IDictionary Data => new Dictionary(); + + public Task SchedulerFailedOver() + { + return Task.CompletedTask; + } + + public TimeSpan? RemainingTime => null; + public void Put(object key, object objectValue) + { + Data[key] = objectValue; + } + + public object? Get(object key) + { + return Data.TryGetValue(key, out var value) ? value : null; + } +} diff --git a/SS14.Web.Tests/Utils/TestUserStore.cs b/SS14.Web.Tests/Utils/TestUserStore.cs new file mode 100644 index 00000000..110ef8fd --- /dev/null +++ b/SS14.Web.Tests/Utils/TestUserStore.cs @@ -0,0 +1,98 @@ +#nullable enable +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using SS14.Auth.Shared.Data; + +namespace SS14.Web.Tests.Utils; + +public sealed class TestUserStore(ApplicationDbContext dbContext) : IUserPasswordStore +{ + public void Dispose() + { + } + + public Task GetUserIdAsync(SpaceUser user, CancellationToken cancellationToken) + { + return Task.FromResult(user.Id.ToString()); + } + + public Task GetUserNameAsync(SpaceUser user, CancellationToken cancellationToken) + { + return Task.FromResult(user.UserName); + } + + public Task SetUserNameAsync(SpaceUser user, string? userName, CancellationToken cancellationToken) + { + user.UserName = userName; + return Task.CompletedTask; + } + + public Task GetNormalizedUserNameAsync(SpaceUser user, CancellationToken cancellationToken) + { + return Task.FromResult(user.NormalizedUserName); + } + + public Task SetNormalizedUserNameAsync(SpaceUser user, string? normalizedName, CancellationToken cancellationToken) + { + user.NormalizedUserName = normalizedName; + return Task.CompletedTask; + } + + public async Task CreateAsync(SpaceUser user, CancellationToken cancellationToken) + { + dbContext.Users.Add(user); + await dbContext.SaveChangesAsync(cancellationToken); + return IdentityResult.Success; + } + + public async Task UpdateAsync(SpaceUser user, CancellationToken cancellationToken) + { + dbContext.Users.Update(user); + await dbContext.SaveChangesAsync(cancellationToken); + return IdentityResult.Success; + } + + public async Task DeleteAsync(SpaceUser user, CancellationToken cancellationToken) + { + dbContext.Users.Remove(user); + + var queuedDeletion = await dbContext.UserDeletionQueue + .FirstOrDefaultAsync(e => e.SpaceUserId == user.Id, cancellationToken); + + if (queuedDeletion != null) + dbContext.UserDeletionQueue.Remove(queuedDeletion); + + await dbContext.SaveChangesAsync(cancellationToken); + return IdentityResult.Success; + } + + public Task FindByIdAsync(string userId, CancellationToken cancellationToken) + { + var id = Guid.Parse(userId); + return dbContext.Users.FirstOrDefaultAsync(u => u.Id == id, cancellationToken); + } + + public Task FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken) + { + return dbContext.Users.FirstOrDefaultAsync(u => u.NormalizedUserName == normalizedUserName, cancellationToken); + } + + public Task SetPasswordHashAsync(SpaceUser user, string? passwordHash, CancellationToken cancellationToken) + { + user.PasswordHash = passwordHash; + return Task.CompletedTask; + } + + public Task GetPasswordHashAsync(SpaceUser user, CancellationToken cancellationToken) + { + return Task.FromResult(user.PasswordHash); + } + + public Task HasPasswordAsync(SpaceUser user, CancellationToken cancellationToken) + { + return Task.FromResult(user.PasswordHash != null); + } +} From 5598bc1b7fcf345ea2ca07e18f95bb517c9ca5ec Mon Sep 17 00:00:00 2001 From: juliangiebel Date: Sat, 31 Oct 2026 19:06:01 +0100 Subject: [PATCH 13/14] Address reviews --- ...0261003184718_AddUserDeletionPropagatedColumn.Designer.cs} | 2 +- ...n.cs => 20261003184718_AddUserDeletionPropagatedColumn.cs} | 2 +- SS14.Auth.Shared/Data/SpaceUserManager.cs | 3 ++- SS14.Auth.Shared/ModelShared.cs | 4 ++-- SS14.Auth.Shared/SS14.Auth.Shared.csproj | 1 - SS14.Auth/Jobs/DeleteMarkedUsersJob.cs | 2 +- SS14.Web/Views/Shared/_Layout.cshtml | 3 ++- 7 files changed, 9 insertions(+), 8 deletions(-) rename SS14.Auth.Shared/Data/Migrations/{20261003184718_AddUserDeletionPropergatedColumn.Designer.cs => 20261003184718_AddUserDeletionPropagatedColumn.Designer.cs} (99%) rename SS14.Auth.Shared/Data/Migrations/{20261003184718_AddUserDeletionPropergatedColumn.cs => 20261003184718_AddUserDeletionPropagatedColumn.cs} (95%) diff --git a/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.Designer.cs b/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropagatedColumn.Designer.cs similarity index 99% rename from SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.Designer.cs rename to SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropagatedColumn.Designer.cs index efe67fdf..551c7207 100644 --- a/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.Designer.cs +++ b/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropagatedColumn.Designer.cs @@ -15,7 +15,7 @@ namespace SS14.Auth.Shared.Data.Migrations { [DbContext(typeof(ApplicationDbContext))] [Migration("20261003184718_AddUserDeletionPropergatedColumn")] - partial class AddUserDeletionPropergatedColumn + partial class AddUserDeletionPropagatedColumn { protected override void BuildTargetModel(ModelBuilder modelBuilder) { diff --git a/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.cs b/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropagatedColumn.cs similarity index 95% rename from SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.cs rename to SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropagatedColumn.cs index 9b39ec43..ef47373b 100644 --- a/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropergatedColumn.cs +++ b/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropagatedColumn.cs @@ -5,7 +5,7 @@ namespace SS14.Auth.Shared.Data.Migrations { - public partial class AddUserDeletionPropergatedColumn : Migration + public partial class AddUserDeletionPropagatedColumn : Migration { protected override void Up(MigrationBuilder migrationBuilder) { diff --git a/SS14.Auth.Shared/Data/SpaceUserManager.cs b/SS14.Auth.Shared/Data/SpaceUserManager.cs index 4aae0fa5..fa3eee4f 100644 --- a/SS14.Auth.Shared/Data/SpaceUserManager.cs +++ b/SS14.Auth.Shared/Data/SpaceUserManager.cs @@ -89,7 +89,8 @@ public async Task CancelQueuedDeletion(SpaceUser user) public override async Task DeleteAsync(SpaceUser user) { var result = await base.DeleteAsync(user); - dbContext.DeletedUserIds.Add(new DeletedUser { SpaceUserId = user.Id, DeletedOn = DateTime.UtcNow }); + if (result.Succeeded) + dbContext.DeletedUserIds.Add(new DeletedUser { SpaceUserId = user.Id, DeletedOn = DateTime.UtcNow }); return result; } diff --git a/SS14.Auth.Shared/ModelShared.cs b/SS14.Auth.Shared/ModelShared.cs index 4fa81a01..1a09d27b 100644 --- a/SS14.Auth.Shared/ModelShared.cs +++ b/SS14.Auth.Shared/ModelShared.cs @@ -58,7 +58,7 @@ public static async Task SendDeletionQueuedEmail(IEmailSender emailSender, strin await emailSender.SendEmailAsync( email, "Account deletion queued", - $"We received a request to delete your Space Station 14 account. It will be permanently deleted on {deletionDateString}.
If you want to keep your account, you can cancel the deletion at any time by logging in at https://account.spacestation14.com
Once the deletion goes through, your account can't be recovered. This includes your login, any OAuth apps you've created an all first party data we keep on you."); + $"We received a request to delete your Space Station 14 account. It will be permanently deleted on {deletionDateString}.
If you want to keep your account, you can cancel the deletion at any time by logging in at https://account.spacestation14.com
Once the deletion goes through, your account can't be recovered. This includes your login, any OAuth apps you've created and all first party data we keep on you."); } public static async Task SendDeletionCanceledEmail(IEmailSender emailSender, string email) @@ -74,7 +74,7 @@ public static async Task SendUserDeletedEmail(IEmailSender emailSender, string e await emailSender.SendEmailAsync( email, "Account deleted", - "Your Space Station 14 account has been permanently deleted.
This is the result of a deletion request
OR
/Your account was deleted by account support.
Your login and associated data has been removed, and you will no longer be able to sign in or play on servers using this account. This can't be undone, but you're welcome to create a new account at any time."); + "Your Space Station 14 account has been permanently deleted.
This is the result of a deletion request
OR
/Your account was deleted by account support.
Your login and associated data has been removed, and you will no longer be able to sign in or play on servers using this account. This can't be undone, but you're welcome to create a new account at any time."); } public static SpaceUser CreateNewUser(string userName, string email, ISystemClock systemClock) diff --git a/SS14.Auth.Shared/SS14.Auth.Shared.csproj b/SS14.Auth.Shared/SS14.Auth.Shared.csproj index e27e9473..6acfab52 100644 --- a/SS14.Auth.Shared/SS14.Auth.Shared.csproj +++ b/SS14.Auth.Shared/SS14.Auth.Shared.csproj @@ -28,7 +28,6 @@ - diff --git a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs index 3ff94aa0..26837425 100644 --- a/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs +++ b/SS14.Auth/Jobs/DeleteMarkedUsersJob.cs @@ -49,7 +49,7 @@ public async Task Execute(IJobExecutionContext context) { logger.LogError("Failed to delete user {Id} marked for deletion.", entry.SpaceUserId); await ModelShared.SendDeletionFailedEmail(emailSender, entry.SpaceUserId); - return; + continue; } deletedAccounts.Add(deletedAccount); diff --git a/SS14.Web/Views/Shared/_Layout.cshtml b/SS14.Web/Views/Shared/_Layout.cshtml index 313f2935..dc0b5775 100644 --- a/SS14.Web/Views/Shared/_Layout.cshtml +++ b/SS14.Web/Views/Shared/_Layout.cshtml @@ -44,8 +44,9 @@ @if (await UserManager.GetDaysUntilDeletionAsync(User) is { } timeSpan) { + var deletionTimeText = timeSpan.Days < 0 ? "soon" : $"in {timeSpan.Days} days"; } From 260b85bca3e2a394b9f631cb9b9e0e61d0e08b13 Mon Sep 17 00:00:00 2001 From: juliangiebel Date: Sun, 1 Nov 2026 11:59:51 +0100 Subject: [PATCH 14/14] Address Reviews --- .../20261003184718_AddUserDeletionPropagatedColumn.Designer.cs | 2 +- SS14.Auth.Shared/ModelShared.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropagatedColumn.Designer.cs b/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropagatedColumn.Designer.cs index 551c7207..4727557b 100644 --- a/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropagatedColumn.Designer.cs +++ b/SS14.Auth.Shared/Data/Migrations/20261003184718_AddUserDeletionPropagatedColumn.Designer.cs @@ -14,7 +14,7 @@ namespace SS14.Auth.Shared.Data.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20261003184718_AddUserDeletionPropergatedColumn")] + [Migration("20261003184718_AddUserDeletionPropagatedColumn")] partial class AddUserDeletionPropagatedColumn { protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/SS14.Auth.Shared/ModelShared.cs b/SS14.Auth.Shared/ModelShared.cs index 1a09d27b..f01e903b 100644 --- a/SS14.Auth.Shared/ModelShared.cs +++ b/SS14.Auth.Shared/ModelShared.cs @@ -74,7 +74,7 @@ public static async Task SendUserDeletedEmail(IEmailSender emailSender, string e await emailSender.SendEmailAsync( email, "Account deleted", - "Your Space Station 14 account has been permanently deleted.
This is the result of a deletion request
OR
/Your account was deleted by account support.
Your login and associated data has been removed, and you will no longer be able to sign in or play on servers using this account. This can't be undone, but you're welcome to create a new account at any time."); + "Your Space Station 14 account has been permanently deleted.
This is the result of a deletion request
OR
Your account was deleted by account support.
Your login and associated data has been removed, and you will no longer be able to sign in or play on servers using this account. This can't be undone, but you're welcome to create a new account at any time."); } public static SpaceUser CreateNewUser(string userName, string email, ISystemClock systemClock)