Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Preserve email claims when user is deleted (#345)

Leendert de Borsta92f0740990f
diff --git a/src/AliasVault.Admin/Main/Pages/Users/Delete.razor b/src/AliasVault.Admin/Main/Pages/Users/Delete.razor
index fdeb53398..0046ae3b8 100644
--- a/src/AliasVault.Admin/Main/Pages/Users/Delete.razor
+++ b/src/AliasVault.Admin/Main/Pages/Users/Delete.razor
@@ -1,5 +1,6 @@
@page "/users/{id}/delete"
@inherits MainBase
+@inject ILogger<Delete> Logger
<LayoutPageTitle>Delete user</LayoutPageTitle>
@@ -79,6 +80,9 @@ else
GlobalLoadingSpinner.Show();
+ // Add log entry.
+ Logger.LogWarning("Deleted user {UserName} ({UserId}).", Obj.UserName, Obj.Id);
+
DbContext.AliasVaultUsers.Remove(Obj);
await DbContext.SaveChangesAsync();
diff --git a/src/AliasVault.Admin/appsettings.Development.json b/src/AliasVault.Admin/appsettings.Development.json
index e43f4b93e..26d77a8ac 100644
--- a/src/AliasVault.Admin/appsettings.Development.json
+++ b/src/AliasVault.Admin/appsettings.Development.json
@@ -1,8 +1,9 @@
{
- "Logging": {
- "LogLevel": {
- "Default": "Information",
- "Microsoft.AspNetCore.Server.Kestrel": "Error"
- }
- }
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore.Server.Kestrel": "Error"
+ }
+ },
+ "DetailedErrors": true
}
diff --git a/src/Databases/AliasServerDb/AliasServerDbContext.cs b/src/Databases/AliasServerDb/AliasServerDbContext.cs
index 9309f30ab..6e4a7e27b 100644
--- a/src/Databases/AliasServerDb/AliasServerDbContext.cs
+++ b/src/Databases/AliasServerDb/AliasServerDbContext.cs
@@ -208,18 +208,20 @@ public class AliasServerDbContext : WorkerStatusDbContext, IDataProtectionKeyCon
.OnDelete(DeleteBehavior.Cascade);
// Configure UserEmailClaim - AliasVaultUser relationship
+ // Note: when a user is deleted the email claims user FK's should be set to NULL
+ // so the claims themselves are preserved to prevent re-use of the email address.
modelBuilder.Entity<UserEmailClaim>()
.HasOne(l => l.User)
.WithMany(c => c.EmailClaims)
.HasForeignKey(l => l.UserId)
- .OnDelete(DeleteBehavior.Cascade);
+ .OnDelete(DeleteBehavior.ClientSetNull);
// Configure Email - UserEncryptionKey relationship
modelBuilder.Entity<Email>()
.HasOne(l => l.EncryptionKey)
.WithMany(c => c.Emails)
.HasForeignKey(l => l.UserEncryptionKeyId)
- .OnDelete(DeleteBehavior.NoAction);
+ .OnDelete(DeleteBehavior.Cascade);
// Configure UserEncryptionKey - AliasVaultUser relationship
modelBuilder.Entity<UserEncryptionKey>()
diff --git a/src/Databases/AliasServerDb/Migrations/20241107205118_PreserveEmailClaimsForDeletedUsers.Designer.cs b/src/Databases/AliasServerDb/Migrations/20241107205118_PreserveEmailClaimsForDeletedUsers.Designer.cs
new file mode 100644
index 000000000..60b08e15d
--- /dev/null
+++ b/src/Databases/AliasServerDb/Migrations/20241107205118_PreserveEmailClaimsForDeletedUsers.Designer.cs
@@ -0,0 +1,828 @@
+// <auto-generated />
+using System;
+using AliasServerDb;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace AliasServerDb.Migrations
+{
+ [DbContext(typeof(AliasServerDbContext))]
+ [Migration("20241107105118_PreserveEmailClaimsForDeletedUsers")]
+ partial class PreserveEmailClaimsForDeletedUsers
+ {
+ /// <inheritdoc />
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "8.0.10")
+ .HasAnnotation("Proxies:ChangeTracking", false)
+ .HasAnnotation("Proxies:CheckEquality", false)
+ .HasAnnotation("Proxies:LazyLoading", true);
+
+ modelBuilder.Entity("AliasServerDb.AdminRole", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("ConcurrencyStamp")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Name")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("NormalizedName")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("AdminRoles");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AdminUser", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("TEXT");
+
+ b.Property<int>("AccessFailedCount")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("ConcurrencyStamp")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Email")
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("EmailConfirmed")
+ .HasColumnType("INTEGER");
+
+ b.Property<DateTime?>("LastPasswordChanged")
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("LockoutEnabled")
+ .HasColumnType("INTEGER");
+
+ b.Property<DateTimeOffset?>("LockoutEnd")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("NormalizedEmail")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("NormalizedUserName")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("PasswordHash")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("PhoneNumber")
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("PhoneNumberConfirmed")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("SecurityStamp")
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("TwoFactorEnabled")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("UserName")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("AdminUsers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultRole", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("ConcurrencyStamp")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Name")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("NormalizedName")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("AliasVaultRoles");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("TEXT");
+
+ b.Property<int>("AccessFailedCount")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("ConcurrencyStamp")
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Email")
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("EmailConfirmed")
+ .HasColumnType("INTEGER");
+
+ b.Property<bool>("LockoutEnabled")
+ .HasColumnType("INTEGER");
+
+ b.Property<DateTimeOffset?>("LockoutEnd")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("NormalizedEmail")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("NormalizedUserName")
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("PasswordChangedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("PasswordHash")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("PhoneNumber")
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("PhoneNumberConfirmed")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("SecurityStamp")
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("TwoFactorEnabled")
+ .HasColumnType("INTEGER");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("UserName")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("AliasVaultUsers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("DeviceIdentifier")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("ExpireDate")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("IpAddress")
+ .HasMaxLength(45)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("PreviousTokenValue")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Value")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AliasVaultUserRefreshTokens");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AuthLog", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("AdditionalInfo")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Browser")
+ .HasMaxLength(100)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Country")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("DeviceType")
+ .HasMaxLength(100)
+ .HasColumnType("TEXT");
+
+ b.Property<int>("EventType")
+ .HasColumnType("nvarchar(50)");
+
+ b.Property<int?>("FailureReason")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("IpAddress")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("IsSuccess")
+ .HasColumnType("INTEGER");
+
+ b.Property<bool>("IsSuspiciousActivity")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("OperatingSystem")
+ .HasMaxLength(100)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("RequestPath")
+ .HasMaxLength(100)
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("Timestamp")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("UserAgent")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Username")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "EventType" }, "IX_EventType");
+
+ b.HasIndex(new[] { "IpAddress" }, "IX_IpAddress");
+
+ b.HasIndex(new[] { "Timestamp" }, "IX_Timestamp");
+
+ b.HasIndex(new[] { "Username", "IsSuccess", "Timestamp" }, "IX_Username_IsSuccess_Timestamp")
+ .IsDescending(false, false, true);
+
+ b.HasIndex(new[] { "Username", "Timestamp" }, "IX_Username_Timestamp")
+ .IsDescending(false, true);
+
+ b.ToTable("AuthLogs");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property<DateTime>("Date")
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("DateSystem")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("EncryptedSymmetricKey")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("From")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("FromDomain")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("FromLocal")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("MessageHtml")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("MessagePlain")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("MessagePreview")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("MessageSource")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("PushNotificationSent")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("Subject")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("To")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("ToDomain")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("ToLocal")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<Guid>("UserEncryptionKeyId")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("Visible")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Date");
+
+ b.HasIndex("DateSystem");
+
+ b.HasIndex("PushNotificationSent");
+
+ b.HasIndex("ToLocal");
+
+ b.HasIndex("UserEncryptionKeyId");
+
+ b.HasIndex("Visible");
+
+ b.ToTable("Emails");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property<byte[]>("Bytes")
+ .IsRequired()
+ .HasColumnType("BLOB");
+
+ b.Property<DateTime>("Date")
+ .HasColumnType("TEXT");
+
+ b.Property<int>("EmailId")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("Filename")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<int>("Filesize")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("MimeType")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("EmailId");
+
+ b.ToTable("EmailAttachments");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Log", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("Application")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Exception")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Level")
+ .IsRequired()
+ .HasMaxLength(128)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("LogEvent")
+ .IsRequired()
+ .HasColumnType("TEXT")
+ .HasColumnName("LogEvent");
+
+ b.Property<string>("Message")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("MessageTemplate")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Properties")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("SourceContext")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("TimeStamp")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Application");
+
+ b.HasIndex("TimeStamp");
+
+ b.ToTable("Logs", (string)null);
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserEmailClaim", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Address")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("AddressDomain")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("AddressLocal")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("UserId")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Address")
+ .IsUnique();
+
+ b.HasIndex("UserId");
+
+ b.ToTable("UserEmailClaims");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserEncryptionKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<bool>("IsPrimary")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("PublicKey")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("UserEncryptionKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Vault", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<int>("CredentialsCount")
+ .HasColumnType("INTEGER");
+
+ b.Property<int>("EmailClaimsCount")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("EncryptionSettings")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("EncryptionType")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<int>("FileSize")
+ .HasColumnType("INTEGER");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("Salt")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("VaultBlob")
+ .IsRequired()
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Verifier")
+ .IsRequired()
+ .HasMaxLength(1000)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Version")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("Vaults");
+ });
+
+ modelBuilder.Entity("AliasVault.WorkerStatus.Database.WorkerServiceStatus", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("CurrentStatus")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.Property<string>("DesiredStatus")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.Property<DateTime>("Heartbeat")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("ServiceName")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("varchar");
+
+ b.HasKey("Id");
+
+ b.ToTable("WorkerServiceStatuses");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("FriendlyName")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Xml")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("DataProtectionKeys");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("ClaimType")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("ClaimValue")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("RoleId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("RoleClaims", (string)null);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property<string>("ClaimType")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("ClaimValue")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("UserId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.ToTable("UserClaims", (string)null);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
+ {
+ b.Property<string>("LoginProvider")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("ProviderKey")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("ProviderDisplayName")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("UserId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("LoginProvider", "ProviderKey");
+
+ b.ToTable("UserLogins", (string)null);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
+ {
+ b.Property<string>("UserId")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("RoleId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("UserId", "RoleId");
+
+ b.ToTable("UserRoles", (string)null);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
+ {
+ b.Property<string>("UserId")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("LoginProvider")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Name")
+ .HasColumnType("TEXT");
+
+ b.Property<string>("Value")
+ .HasColumnType("TEXT");
+
+ b.HasKey("UserId", "LoginProvider", "Name");
+
+ b.ToTable("UserTokens", (string)null);
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.HasOne("AliasServerDb.UserEncryptionKey", "EncryptionKey")
+ .WithMany("Emails")
+ .HasForeignKey("UserEncryptionKeyId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("EncryptionKey");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>
+ {
+ b.HasOne("AliasServerDb.Email", "Email")
+ .WithMany("Attachments")
+ .HasForeignKey("EmailId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Email");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserEmailClaim", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany("EmailClaims")
+ .HasForeignKey("UserId");
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserEncryptionKey", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany("EncryptionKeys")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Vault", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany("Vaults")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
+ {
+ b.Navigation("EmailClaims");
+
+ b.Navigation("EncryptionKeys");
+
+ b.Navigation("Vaults");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.Navigation("Attachments");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserEncryptionKey", b =>
+ {
+ b.Navigation("Emails");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/Databases/AliasServerDb/Migrations/20241107205118_PreserveEmailClaimsForDeletedUsers.cs b/src/Databases/AliasServerDb/Migrations/20241107205118_PreserveEmailClaimsForDeletedUsers.cs
new file mode 100644
index 000000000..e0a9cbf21
--- /dev/null
+++ b/src/Databases/AliasServerDb/Migrations/20241107205118_PreserveEmailClaimsForDeletedUsers.cs
@@ -0,0 +1,87 @@
+// <auto-generated />
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace AliasServerDb.Migrations
+{
+ /// <inheritdoc />
+ public partial class PreserveEmailClaimsForDeletedUsers : Migration
+ {
+ /// <inheritdoc />
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId",
+ table: "Emails");
+
+ migrationBuilder.DropForeignKey(
+ name: "FK_UserEmailClaims_AliasVaultUsers_UserId",
+ table: "UserEmailClaims");
+
+ migrationBuilder.AlterColumn<string>(
+ name: "UserId",
+ table: "UserEmailClaims",
+ type: "TEXT",
+ maxLength: 255,
+ nullable: true,
+ oldClrType: typeof(string),
+ oldType: "TEXT",
+ oldMaxLength: 255);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId",
+ table: "Emails",
+ column: "UserEncryptionKeyId",
+ principalTable: "UserEncryptionKeys",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_UserEmailClaims_AliasVaultUsers_UserId",
+ table: "UserEmailClaims",
+ column: "UserId",
+ principalTable: "AliasVaultUsers",
+ principalColumn: "Id");
+ }
+
+ /// <inheritdoc />
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId",
+ table: "Emails");
+
+ migrationBuilder.DropForeignKey(
+ name: "FK_UserEmailClaims_AliasVaultUsers_UserId",
+ table: "UserEmailClaims");
+
+ migrationBuilder.AlterColumn<string>(
+ name: "UserId",
+ table: "UserEmailClaims",
+ type: "TEXT",
+ maxLength: 255,
+ nullable: false,
+ defaultValue: "",
+ oldClrType: typeof(string),
+ oldType: "TEXT",
+ oldMaxLength: 255,
+ oldNullable: true);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Emails_UserEncryptionKeys_UserEncryptionKeyId",
+ table: "Emails",
+ column: "UserEncryptionKeyId",
+ principalTable: "UserEncryptionKeys",
+ principalColumn: "Id");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_UserEmailClaims_AliasVaultUsers_UserId",
+ table: "UserEmailClaims",
+ column: "UserId",
+ principalTable: "AliasVaultUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ }
+ }
+}
diff --git a/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs b/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
index a31749918..213b6b275 100644
--- a/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
+++ b/src/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
@@ -16,7 +16,7 @@ namespace AliasServerDb.Migrations
{
#pragma warning disable 612, 618
modelBuilder
- .HasAnnotation("ProductVersion", "8.0.8")
+ .HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Proxies:ChangeTracking", false)
.HasAnnotation("Proxies:CheckEquality", false)
.HasAnnotation("Proxies:LazyLoading", true);
@@ -492,7 +492,6 @@ namespace AliasServerDb.Migrations
.HasColumnType("TEXT");
b.Property<string>("UserId")
- .IsRequired()
.HasMaxLength(255)
.HasColumnType("TEXT");
@@ -754,7 +753,7 @@ namespace AliasServerDb.Migrations
b.HasOne("AliasServerDb.UserEncryptionKey", "EncryptionKey")
.WithMany("Emails")
.HasForeignKey("UserEncryptionKeyId")
- .OnDelete(DeleteBehavior.NoAction)
+ .OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("EncryptionKey");
@@ -775,9 +774,7 @@ namespace AliasServerDb.Migrations
{
b.HasOne("AliasServerDb.AliasVaultUser", "User")
.WithMany("EmailClaims")
- .HasForeignKey("UserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
+ .HasForeignKey("UserId");
b.Navigation("User");
});
diff --git a/src/Databases/AliasServerDb/UserEmailClaim.cs b/src/Databases/AliasServerDb/UserEmailClaim.cs
index a9fe28613..0e4a44986 100644
--- a/src/Databases/AliasServerDb/UserEmailClaim.cs
+++ b/src/Databases/AliasServerDb/UserEmailClaim.cs
@@ -24,16 +24,18 @@ public class UserEmailClaim
public Guid Id { get; set; }
/// <summary>
- /// Gets or sets user ID foreign key.
+ /// Gets or sets user ID foreign key. This can be null if the email claim was associated with a user that has since been deleted.
+ /// Email claims are meant to be preserved even if the user is deleted to prevent re-use of the email address.
/// </summary>
[StringLength(255)]
- public string UserId { get; set; } = null!;
+ public string? UserId { get; set; }
/// <summary>
- /// Gets or sets foreign key to the AliasVaultUser object.
+ /// Gets or sets foreign key to the AliasVaultUser object. This can be null if the email claim was associated with a user that has since been deleted.
+ /// Email claims are meant to be preserved even if the user is deleted to prevent re-use of the email address.
/// </summary>
[ForeignKey("UserId")]
- public virtual AliasVaultUser User { get; set; } = null!;
+ public virtual AliasVaultUser? User { get; set; }
/// <summary>
/// Gets or sets the full email address.