Skip to content

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

Move statistic columns from user to group (#2159)

Leendert de Borst5d5e0e8667b9
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Index.razor b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Index.razor
index 048779fc9..ea9b524ac 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Index.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Index.razor
@@ -185,12 +185,12 @@ else
<div class="flex flex-col space-y-2">
<div class="flex items-center space-x-2">
<span class="text-gray-700 dark:text-gray-300">
- <strong>Max Emails:</strong> @(User.MaxEmails == 0 ? "Unlimited" : User.MaxEmails.ToString("N0"))
+ <strong>Max Emails:</strong> @(User.PersonalGroup.MaxEmails == 0 ? "Unlimited" : User.PersonalGroup.MaxEmails.ToString("N0"))
</span>
</div>
<div class="flex items-center space-x-2">
<span class="text-gray-700 dark:text-gray-300">
- <strong>Max Age:</strong> @(User.MaxEmailAgeDays == 0 ? "Unlimited" : User.MaxEmailAgeDays + " days")
+ <strong>Max Age:</strong> @(User.PersonalGroup.MaxEmailAgeDays == 0 ? "Unlimited" : User.PersonalGroup.MaxEmailAgeDays + " days")
</span>
</div>
<div class="mt-2">
@@ -354,9 +354,9 @@ else
IsLoading = true;
StateHasChanged();
- // Load the aliases from the webapi via AliasService.
+ // Load the aliases from the webapi via AliasService. Eager-load the personal group as it holds the user's email limits.
await using var dbContext = await DbContextFactory.CreateDbContextAsync();
- User = await dbContext.AliasVaultUsers.FindAsync(Id);
+ User = await dbContext.AliasVaultUsers.Include(u => u.PersonalGroup).FirstOrDefaultAsync(u => u.Id == Id);
// Get count of user authenticator tokens.
TwoFactorKeysCount = await dbContext.UserTokens.CountAsync(x => x.UserId == User!.Id && x.Name == "AuthenticatorKey");
@@ -642,8 +642,8 @@ Do you want to proceed with the restoration?")) {
private void StartEditingEmailLimits()
{
IsEditingEmailLimits = true;
- EditMaxEmails = User!.MaxEmails;
- EditMaxEmailAgeDays = User.MaxEmailAgeDays;
+ EditMaxEmails = User!.PersonalGroup.MaxEmails;
+ EditMaxEmailAgeDays = User.PersonalGroup.MaxEmailAgeDays;
}
/// <summary>
@@ -662,12 +662,12 @@ Do you want to proceed with the restoration?")) {
private async Task SaveEmailLimits()
{
await using var dbContext = await DbContextFactory.CreateDbContextAsync();
- User = await dbContext.AliasVaultUsers.FindAsync(Id);
+ var personalGroup = await dbContext.Groups.FirstOrDefaultAsync(g => dbContext.AliasVaultUsers.Any(u => u.Id == Id && u.PersonalGroupId == g.Id));
- if (User != null)
+ if (personalGroup != null)
{
- User.MaxEmails = EditMaxEmails;
- User.MaxEmailAgeDays = EditMaxEmailAgeDays;
+ personalGroup.MaxEmails = EditMaxEmails;
+ personalGroup.MaxEmailAgeDays = EditMaxEmailAgeDays;
await dbContext.SaveChangesAsync();
IsEditingEmailLimits = false;
await RefreshData();
diff --git a/apps/server/AliasVault.Admin/Services/StatisticsService.cs b/apps/server/AliasVault.Admin/Services/StatisticsService.cs
index 324199530..7fcee3086 100644
--- a/apps/server/AliasVault.Admin/Services/StatisticsService.cs
+++ b/apps/server/AliasVault.Admin/Services/StatisticsService.cs
@@ -343,9 +343,8 @@ public class StatisticsService
.Where(e => e.EncryptionKey.UserId == userId)
.CountAsync();
- // Get persistent emails received counter from user record (never decremented, even when emails are deleted)
- var user = await context.AliasVaultUsers.FindAsync(userId);
- stats.TotalEmailsReceivedPersistent = user?.EmailsReceived ?? 0;
+ // Get persistent emails received counter from the user's personal group (never decremented, even when emails are deleted)
+ stats.TotalEmailsReceivedPersistent = await context.AliasVaultUsers.Where(u => u.Id == userId).Select(u => u.PersonalGroup.EmailsReceived).FirstOrDefaultAsync();
// Get recent statistics (last 72 hours).
var recentCurrentRevisions = await context.VaultManifests
diff --git a/apps/server/Databases/AliasServerDb/AliasVaultUser.cs b/apps/server/Databases/AliasServerDb/AliasVaultUser.cs
index f6549983d..2a9f91b83 100644
--- a/apps/server/Databases/AliasServerDb/AliasVaultUser.cs
+++ b/apps/server/Databases/AliasServerDb/AliasVaultUser.cs
@@ -53,46 +53,17 @@ public class AliasVaultUser : IdentityUser
/// </summary>
public DateTime? BlockedAt { get; set; }
- /// <summary>
- /// Gets or sets a value indicating whether the user is marked as shadow-blocked.
- /// </summary>
- public bool ShadowBlocked { get; set; }
-
- /// <summary>
- /// Gets or sets the UTC timestamp when the user was shadow-blocked. Used to only hide emails received after the
- /// block occurred. Null when the user has never been shadow-blocked (in which case all emails are hidden while
- /// ShadowBlocked is true, as a conservative fallback).
- /// </summary>
- public DateTime? ShadowBlockedAt { get; set; }
-
/// <summary>
/// Gets or sets updated timestamp.
/// </summary>
public DateTime UpdatedAt { get; set; }
- /// <summary>
- /// Gets or sets the maximum number of emails for all of user's aliases. 0 means unlimited.
- /// </summary>
- public int MaxEmails { get; set; } = 0;
-
- /// <summary>
- /// Gets or sets the maximum age of emails in days. Emails older than this will be deleted. 0 means unlimited.
- /// </summary>
- public int MaxEmailAgeDays { get; set; } = 0;
-
/// <summary>
/// Gets or sets the date of the user's last activity (login, API call, etc.).
/// Updated automatically on successful authentication events.
/// </summary>
public DateTime? LastActivityDate { get; set; }
- /// <summary>
- /// Gets or sets the total count of emails received by this user across all time.
- /// This is a persistent counter that is incremented when emails are received and is never decremented,
- /// even when emails are deleted. Used for abuse detection and usage statistics.
- /// </summary>
- public int EmailsReceived { get; set; } = 0;
-
/// <summary>
/// Gets or sets the collection of vault unlock keys (KEK/VEK model). Empty for users still on the legacy
/// model where the password-derived key encrypts the vault directly.
diff --git a/apps/server/Databases/AliasServerDb/Group.cs b/apps/server/Databases/AliasServerDb/Group.cs
index 71774e7ce..af995cf16 100644
--- a/apps/server/Databases/AliasServerDb/Group.cs
+++ b/apps/server/Databases/AliasServerDb/Group.cs
@@ -37,6 +37,34 @@ public class Group
/// </summary>
public virtual ICollection<GroupMember> Members { get; set; } = [];
+ /// <summary>
+ /// Gets or sets a value indicating whether the group is marked as shadow-blocked.
+ /// </summary>
+ public bool ShadowBlocked { get; set; }
+
+ /// <summary>
+ /// Gets or sets the UTC timestamp when the group was shadow-blocked. Used to only hide emails received after the
+ /// block occurred. Null when the group has never been shadow-blocked.
+ /// </summary>
+ public DateTime? ShadowBlockedAt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the maximum number of emails for all aliases owned by this group. 0 means unlimited.
+ /// </summary>
+ public int MaxEmails { get; set; } = 0;
+
+ /// <summary>
+ /// Gets or sets the maximum age of emails in days. Emails older than this will be deleted. 0 means unlimited.
+ /// </summary>
+ public int MaxEmailAgeDays { get; set; } = 0;
+
+ /// <summary>
+ /// Gets or sets the total count of emails received by this group's aliases across all time.
+ /// This is a persistent counter that is incremented when emails are received and is never decremented,
+ /// even when emails are deleted. Used for abuse detection and usage statistics.
+ /// </summary>
+ public int EmailsReceived { get; set; } = 0;
+
/// <summary>
/// Gets or sets created timestamp.
/// </summary>
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260801184559_MoveEmailAbuseCountersToGroups.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260801184559_MoveEmailAbuseCountersToGroups.Designer.cs
new file mode 100644
index 000000000..eb40ec17b
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/Migrations/20260801184559_MoveEmailAbuseCountersToGroups.Designer.cs
@@ -0,0 +1,1657 @@
+// <auto-generated />
+using System;
+using AliasServerDb;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace AliasServerDb.Migrations
+{
+ [DbContext(typeof(AliasServerDbContext))]
+ [Migration("20260801184559_MoveEmailAbuseCountersToGroups")]
+ partial class MoveEmailAbuseCountersToGroups
+ {
+ /// <inheritdoc />
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "10.0.10")
+ .HasAnnotation("Proxies:ChangeTracking", false)
+ .HasAnnotation("Proxies:CheckEquality", false)
+ .HasAnnotation("Proxies:LazyLoading", true)
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ 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("boolean");
+
+ b.Property<DateTime?>("LastPasswordChanged")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("LockoutEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTimeOffset?>("LockoutEnd")
+ .HasColumnType("timestamp with time zone");
+
+ 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("boolean");
+
+ b.Property<string>("SecurityStamp")
+ .HasColumnType("text");
+
+ b.Property<bool>("TwoFactorEnabled")
+ .HasColumnType("boolean");
+
+ 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<bool>("Blocked")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("BlockedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ConcurrencyStamp")
+ .HasColumnType("text");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Email")
+ .HasColumnType("text");
+
+ b.Property<bool>("EmailConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("LastActivityDate")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("LockoutEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTimeOffset?>("LockoutEnd")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("NormalizedEmail")
+ .HasColumnType("text");
+
+ b.Property<string>("NormalizedUserName")
+ .HasColumnType("text");
+
+ b.Property<DateTime>("PasswordChangedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("PasswordHash")
+ .HasColumnType("text");
+
+ b.Property<Guid>("PersonalGroupId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("PhoneNumber")
+ .HasColumnType("text");
+
+ b.Property<bool>("PhoneNumberConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<string>("SecurityStamp")
+ .HasColumnType("text");
+
+ b.Property<string>("SrpIdentity")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("TwoFactorEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserName")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex("PersonalGroupId")
+ .IsUnique()
+ .HasDatabaseName("UX_AliasVaultUsers_PersonalGroupId");
+
+ b.ToTable("AliasVaultUsers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("DeviceIdentifier")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime>("ExpireDate")
+ .HasMaxLength(255)
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("IpAddress")
+ .HasMaxLength(45)
+ .HasColumnType("character varying(45)");
+
+ b.Property<string>("PreviousTokenValue")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Value")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AliasVaultUserRefreshTokens");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AuthLog", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("AdditionalInfo")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Browser")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("Client")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("Country")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("DeviceType")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<int>("EventType")
+ .HasColumnType("integer");
+
+ b.Property<int?>("FailureReason")
+ .HasColumnType("integer");
+
+ b.Property<string>("IpAddress")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<bool>("IsSuccess")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("IsSuspiciousActivity")
+ .HasColumnType("boolean");
+
+ b.Property<string>("OperatingSystem")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("RequestPath")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<DateTime>("Timestamp")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Username")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ 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.BlockedIpRange", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<bool>("BlockLogin")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("BlockRegistration")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("BlockShadow")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("CreatedBy")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("Enabled")
+ .HasColumnType("boolean");
+
+ b.Property<string>("IpRange")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("Reason")
+ .HasMaxLength(500)
+ .HasColumnType("character varying(500)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "Enabled" }, "IX_BlockedIpRange_Enabled");
+
+ b.HasIndex(new[] { "IpRange" }, "IX_BlockedIpRange_IpRange")
+ .IsUnique();
+
+ b.ToTable("BlockedIpRanges");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<DateTime>("Date")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime>("DateSystem")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedSymmetricKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<Guid>("EncryptionKeyId")
+ .HasMaxLength(255)
+ .HasColumnType("uuid");
+
+ 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("boolean");
+
+ 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<bool>("Visible")
+ .HasColumnType("boolean");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Date");
+
+ b.HasIndex("DateSystem");
+
+ b.HasIndex("EncryptionKeyId");
+
+ b.HasIndex("PushNotificationSent");
+
+ b.HasIndex("Visible");
+
+ b.HasIndex("To", "DateSystem");
+
+ b.ToTable("Emails");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<byte[]>("Bytes")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<DateTime>("Date")
+ .HasColumnType("timestamp with time zone");
+
+ 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.EmailClaim", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Address")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("AddressDomain")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("AddressLocal")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("Disabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid?>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Address")
+ .IsUnique();
+
+ b.HasIndex("VaultManifestId", "CreatedAt");
+
+ b.HasIndex("VaultManifestId", "Disabled");
+
+ b.ToTable("EmailClaims");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Group", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("EmailsReceived")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxEmailAgeDays")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxEmails")
+ .HasColumnType("integer");
+
+ b.Property<string>("Name")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("ShadowBlocked")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("ShadowBlockedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("Type")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.ToTable("Groups");
+ });
+
+ modelBuilder.Entity("AliasServerDb.GroupMember", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid>("GroupId")
+ .HasColumnType("uuid");
+
+ b.Property<int>("Role")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.HasIndex("GroupId", "UserId")
+ .IsUnique();
+
+ b.ToTable("GroupMembers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Log", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("Application")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("Exception")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Level")
+ .IsRequired()
+ .HasMaxLength(128)
+ .HasColumnType("character varying(128)");
+
+ 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()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("TimeStamp")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Application");
+
+ b.HasIndex("TimeStamp");
+
+ b.ToTable("Logs", (string)null);
+ });
+
+ modelBuilder.Entity("AliasServerDb.MobileLoginRequest", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("ClearedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ClientIpAddress")
+ .HasColumnType("text");
+
+ b.Property<string>("ClientPublicKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedDecryptionKey")
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("FulfilledAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("MobileIpAddress")
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("RetrievedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "ClientIpAddress" }, "IX_ClientIpAddress");
+
+ b.HasIndex(new[] { "CreatedAt" }, "IX_CreatedAt");
+
+ b.HasIndex(new[] { "MobileIpAddress" }, "IX_MobileIpAddress");
+
+ b.HasIndex(new[] { "RetrievedAt", "ClearedAt", "FulfilledAt" }, "IX_RetrievedAt_ClearedAt_FulfilledAt");
+
+ b.HasIndex(new[] { "UserId" }, "IX_UserId");
+
+ b.ToTable("MobileLoginRequests");
+ });
+
+ modelBuilder.Entity("AliasServerDb.RateLimit", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<int?>("AppliesToAccountAgeMaxDays")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("CreatedBy")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime?>("EffectiveFrom")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime?>("EffectiveUntil")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("Enabled")
+ .HasColumnType("boolean");
+
+ b.Property<int>("LimitType")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxCount")
+ .HasColumnType("integer");
+
+ b.Property<string>("Notes")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<int?>("Tier")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<int>("WindowSeconds")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Tier");
+
+ b.HasIndex("UserId");
+
+ b.HasIndex("LimitType", "Enabled");
+
+ b.ToTable("RateLimits");
+ });
+
+ modelBuilder.Entity("AliasServerDb.ServerSetting", b =>
+ {
+ b.Property<string>("Key")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Value")
+ .HasColumnType("text");
+
+ b.HasKey("Key");
+
+ b.ToTable("ServerSettings");
+ });
+
+ modelBuilder.Entity("AliasServerDb.TaskRunnerJob", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<TimeOnly?>("EndTime")
+ .HasColumnType("time without time zone");
+
+ b.Property<string>("ErrorMessage")
+ .HasColumnType("text");
+
+ b.Property<bool>("IsOnDemand")
+ .HasColumnType("boolean");
+
+ b.Property<string>("Name")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<DateTime>("RunDate")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<TimeOnly>("StartTime")
+ .HasColumnType("time without time zone");
+
+ b.Property<int>("Status")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("TaskRunnerJobs");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserGrantKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedPrivateKey")
+ .IsRequired()
+ .HasMaxLength(4000)
+ .HasColumnType("character varying(4000)");
+
+ b.Property<bool>("IsPrimary")
+ .HasColumnType("boolean");
+
+ b.Property<string>("PublicKey")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("character varying(2000)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId")
+ .IsUnique()
+ .HasDatabaseName("UX_UserGrantKeys_User_Primary")
+ .HasFilter("\"IsPrimary\"");
+
+ b.ToTable("UserGrantKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserUnlockKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedAccountKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("LastUsedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Metadata")
+ .HasColumnType("jsonb");
+
+ b.Property<int>("Type")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId", "Type")
+ .IsUnique()
+ .HasDatabaseName("UX_UserUnlockKeys_UserId_Type");
+
+ b.ToTable("UserUnlockKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>
+ {
+ b.Property<string>("Hash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("OwnerUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Category")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<byte[]>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<DateTime>("LastReferencedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("SizeBytes")
+ .HasColumnType("integer");
+
+ b.HasKey("Hash", "OwnerUserId");
+
+ b.HasIndex("OwnerUserId", "Category");
+
+ b.ToTable("VaultBlobObjects");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobReference", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("BlobHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.HasKey("ManifestId", "RevisionNumber", "BlobHash");
+
+ b.ToTable("VaultBlobReferences");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucket", b =>
+ {
+ b.Property<string>("OwnerUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Category")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("CiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("OwnerUserId", "Category");
+
+ b.ToTable("VaultDataBuckets");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>
+ {
+ b.Property<string>("OwnerUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Category")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("CiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("OwnerUserId", "Category", "RevisionNumber");
+
+ b.ToTable("VaultDataBucketsHistory");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifest", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Client")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ 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<bool>("IsRoot")
+ .HasColumnType("boolean");
+
+ b.Property<string>("ManifestBlob")
+ .HasColumnType("text");
+
+ b.Property<string>("ManifestCiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("Name")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<Guid>("OwnerGroupId")
+ .HasColumnType("uuid");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("Salt")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("StorageFormat")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("VaultBlob")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Verifier")
+ .IsRequired()
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Version")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("ManifestId");
+
+ b.HasIndex("OwnerGroupId")
+ .IsUnique()
+ .HasDatabaseName("UX_VaultManifests_OwnerGroupId_Root")
+ .HasFilter("\"IsRoot\"");
+
+ b.ToTable("VaultManifests");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestAccessKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedVek")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("LastUsedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Metadata")
+ .HasColumnType("jsonb");
+
+ b.Property<int>("Type")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid?>("UserGrantKeyId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<Guid>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserGrantKeyId");
+
+ b.HasIndex("VaultManifestId")
+ .HasDatabaseName("IX_VaultManifestAccessKeys_VaultManifestId");
+
+ b.HasIndex("UserId", "Type", "VaultManifestId")
+ .IsUnique()
+ .HasDatabaseName("UX_VaultManifestAccessKeys_UserId_Type_Manifest");
+
+ b.ToTable("VaultManifestAccessKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("IsPrimary")
+ .HasColumnType("boolean");
+
+ b.Property<string>("PublicKey")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("character varying(2000)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("VaultManifestId")
+ .IsUnique()
+ .HasDatabaseName("UX_VaultManifestDeliveryKeys_Manifest_Primary")
+ .HasFilter("\"IsPrimary\"");
+
+ b.HasIndex("VaultManifestId", "IsPrimary");
+
+ b.ToTable("VaultManifestDeliveryKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestsHistory", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("Client")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ 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<string>("ManifestBlob")
+ .HasColumnType("text");
+
+ b.Property<string>("ManifestCiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("Salt")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("StorageFormat")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("VaultBlob")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Verifier")
+ .IsRequired()
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Version")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("ManifestId", "RevisionNumber");
+
+ b.ToTable("VaultManifestsHistory", (string)null);
+ });
+
+ modelBuilder.Entity("AliasVault.WorkerStatus.Database.WorkerServiceStatus", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("CurrentStatus")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("DesiredStatus")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<DateTime>("Heartbeat")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ServiceName")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.ToTable("WorkerServiceStatuses");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ 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");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ 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");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ 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.AliasVaultUser", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "PersonalGroup")
+ .WithOne()
+ .HasForeignKey("AliasServerDb.AliasVaultUser", "PersonalGroupId")
+ .OnDelete(DeleteBehavior.Restrict)
+ .IsRequired();
+
+ b.Navigation("PersonalGroup");
+ });
+
+ 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.VaultManifestDeliveryKey", "EncryptionKey")
+ .WithMany("Emails")
+ .HasForeignKey("EncryptionKeyId")
+ .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.EmailClaim", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")
+ .WithMany()
+ .HasForeignKey("VaultManifestId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.Navigation("VaultManifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.GroupMember", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "Group")
+ .WithMany("Members")
+ .HasForeignKey("GroupId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Group");
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.MobileLoginRequest", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.RateLimit", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserGrantKey", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserUnlockKey", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("OwnerUserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobReference", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Manifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucket", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("OwnerUserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>
+ {
+ b.HasOne("AliasServerDb.VaultDataBucket", "Bucket")
+ .WithMany()
+ .HasForeignKey("OwnerUserId", "Category")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Bucket");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifest", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "OwnerGroup")
+ .WithMany()
+ .HasForeignKey("OwnerGroupId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("OwnerGroup");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestAccessKey", b =>
+ {
+ b.HasOne("AliasServerDb.UserGrantKey", "UserGrantKey")
+ .WithMany()
+ .HasForeignKey("UserGrantKeyId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany("VaultManifestAccessKeys")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+
+ b.Navigation("UserGrantKey");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")
+ .WithMany()
+ .HasForeignKey("VaultManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("VaultManifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestsHistory", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Manifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
+ {
+ b.Navigation("VaultManifestAccessKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.Navigation("Attachments");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Group", b =>
+ {
+ b.Navigation("Members");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
+ {
+ b.Navigation("Emails");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260801184559_MoveEmailAbuseCountersToGroups.cs b/apps/server/Databases/AliasServerDb/Migrations/20260801184559_MoveEmailAbuseCountersToGroups.cs
new file mode 100644
index 000000000..e93d745d5
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/Migrations/20260801184559_MoveEmailAbuseCountersToGroups.cs
@@ -0,0 +1,153 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace AliasServerDb.Migrations
+{
+ /// <inheritdoc />
+ public partial class MoveEmailAbuseCountersToGroups : Migration
+ {
+ /// <inheritdoc />
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn<int>(
+ name: "EmailsReceived",
+ table: "Groups",
+ type: "integer",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.AddColumn<int>(
+ name: "MaxEmailAgeDays",
+ table: "Groups",
+ type: "integer",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.AddColumn<int>(
+ name: "MaxEmails",
+ table: "Groups",
+ type: "integer",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.AddColumn<bool>(
+ name: "ShadowBlocked",
+ table: "Groups",
+ type: "boolean",
+ nullable: false,
+ defaultValue: false);
+
+ migrationBuilder.AddColumn<DateTime>(
+ name: "ShadowBlockedAt",
+ table: "Groups",
+ type: "timestamp with time zone",
+ nullable: true);
+
+ // Move the existing per-user abuse counters and email limits onto each user's personal group.
+ migrationBuilder.Sql(
+ """
+ UPDATE "Groups" g
+ SET "EmailsReceived" = u."EmailsReceived",
+ "MaxEmailAgeDays" = u."MaxEmailAgeDays",
+ "MaxEmails" = u."MaxEmails",
+ "ShadowBlocked" = u."ShadowBlocked",
+ "ShadowBlockedAt" = u."ShadowBlockedAt"
+ FROM "AliasVaultUsers" u
+ WHERE u."PersonalGroupId" = g."Id";
+ """);
+
+ migrationBuilder.DropColumn(
+ name: "EmailsReceived",
+ table: "AliasVaultUsers");
+
+ migrationBuilder.DropColumn(
+ name: "MaxEmailAgeDays",
+ table: "AliasVaultUsers");
+
+ migrationBuilder.DropColumn(
+ name: "MaxEmails",
+ table: "AliasVaultUsers");
+
+ migrationBuilder.DropColumn(
+ name: "ShadowBlocked",
+ table: "AliasVaultUsers");
+
+ migrationBuilder.DropColumn(
+ name: "ShadowBlockedAt",
+ table: "AliasVaultUsers");
+ }
+
+ /// <inheritdoc />
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn<int>(
+ name: "EmailsReceived",
+ table: "AliasVaultUsers",
+ type: "integer",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.AddColumn<int>(
+ name: "MaxEmailAgeDays",
+ table: "AliasVaultUsers",
+ type: "integer",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.AddColumn<int>(
+ name: "MaxEmails",
+ table: "AliasVaultUsers",
+ type: "integer",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.AddColumn<bool>(
+ name: "ShadowBlocked",
+ table: "AliasVaultUsers",
+ type: "boolean",
+ nullable: false,
+ defaultValue: false);
+
+ migrationBuilder.AddColumn<DateTime>(
+ name: "ShadowBlockedAt",
+ table: "AliasVaultUsers",
+ type: "timestamp with time zone",
+ nullable: true);
+
+ // Move the abuse counters and email limits from each user's personal group back onto the user record.
+ migrationBuilder.Sql(
+ """
+ UPDATE "AliasVaultUsers" u
+ SET "EmailsReceived" = g."EmailsReceived",
+ "MaxEmailAgeDays" = g."MaxEmailAgeDays",
+ "MaxEmails" = g."MaxEmails",
+ "ShadowBlocked" = g."ShadowBlocked",
+ "ShadowBlockedAt" = g."ShadowBlockedAt"
+ FROM "Groups" g
+ WHERE u."PersonalGroupId" = g."Id";
+ """);
+
+ migrationBuilder.DropColumn(
+ name: "EmailsReceived",
+ table: "Groups");
+
+ migrationBuilder.DropColumn(
+ name: "MaxEmailAgeDays",
+ table: "Groups");
+
+ migrationBuilder.DropColumn(
+ name: "MaxEmails",
+ table: "Groups");
+
+ migrationBuilder.DropColumn(
+ name: "ShadowBlocked",
+ table: "Groups");
+
+ migrationBuilder.DropColumn(
+ name: "ShadowBlockedAt",
+ table: "Groups");
+ }
+ }
+}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
index bb97c304d..e38330b9e 100644
--- a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
+++ b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
@@ -144,9 +144,6 @@ namespace AliasServerDb.Migrations
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
- b.Property<int>("EmailsReceived")
- .HasColumnType("integer");
-
b.Property<DateTime?>("LastActivityDate")
.HasColumnType("timestamp with time zone");
@@ -156,12 +153,6 @@ namespace AliasServerDb.Migrations
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
- b.Property<int>("MaxEmailAgeDays")
- .HasColumnType("integer");
-
- b.Property<int>("MaxEmails")
- .HasColumnType("integer");
-
b.Property<string>("NormalizedEmail")
.HasColumnType("text");
@@ -186,12 +177,6 @@ namespace AliasServerDb.Migrations
b.Property<string>("SecurityStamp")
.HasColumnType("text");
- b.Property<bool>("ShadowBlocked")
- .HasColumnType("boolean");
-
- b.Property<DateTime?>("ShadowBlockedAt")
- .HasColumnType("timestamp with time zone");
-
b.Property<string>("SrpIdentity")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
@@ -558,11 +543,26 @@ namespace AliasServerDb.Migrations
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
+ b.Property<int>("EmailsReceived")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxEmailAgeDays")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxEmails")
+ .HasColumnType("integer");
+
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)");
+ b.Property<bool>("ShadowBlocked")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("ShadowBlockedAt")
+ .HasColumnType("timestamp with time zone");
+
b.Property<int>("Type")
.HasColumnType("integer");
diff --git a/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailCleanupTask.cs b/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailCleanupTask.cs
index e66e94706..042cd8e85 100644
--- a/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailCleanupTask.cs
+++ b/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailCleanupTask.cs
@@ -67,10 +67,10 @@ public class EmailCleanupTask : IMaintenanceTask
}
}
- // Now handle per-user age limits
+ // Now handle per-user age limits. The email age limit is stored on the user's personal group.
var usersWithAgeLimits = await dbContext.AliasVaultUsers
- .Where(u => u.MaxEmailAgeDays > 0)
- .Select(u => new { u.Id, u.UserName, u.MaxEmailAgeDays })
+ .Where(u => u.PersonalGroup.MaxEmailAgeDays > 0)
+ .Select(u => new { u.Id, u.UserName, u.PersonalGroup.MaxEmailAgeDays })
.ToListAsync(cancellationToken);
foreach (var user in usersWithAgeLimits)
diff --git a/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailQuotaCleanupTask.cs b/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailQuotaCleanupTask.cs
index 8fe5bb361..0bc812166 100644
--- a/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailQuotaCleanupTask.cs
+++ b/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailQuotaCleanupTask.cs
@@ -45,11 +45,12 @@ public class EmailQuotaCleanupTask : IMaintenanceTask
var settings = await _settingsService.GetAllSettingsAsync();
await using var dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
- // Get all users with their email claims and limits
+ // Get all users with their email claims and limits. The email limit is stored on the user's personal group.
var usersWithClaims = await (from u in dbContext.AliasVaultUsers
- join m in dbContext.VaultManifests on u.PersonalGroupId equals m.OwnerGroupId
+ join g in dbContext.Groups on u.PersonalGroupId equals g.Id
+ join m in dbContext.VaultManifests on g.Id equals m.OwnerGroupId
join c in dbContext.EmailClaims on (Guid?)m.ManifestId equals c.VaultManifestId
- select new { u.Id, u.UserName, u.MaxEmails, u.LastActivityDate, u.CreatedAt, c.Address })
+ select new { u.Id, u.UserName, g.MaxEmails, u.LastActivityDate, u.CreatedAt, c.Address })
.ToListAsync(cancellationToken);
// Get minimum activity date which is used to determine if user is active.
diff --git a/apps/server/Utilities/AliasVault.Auth/IpAddress/IpBlockListService.cs b/apps/server/Utilities/AliasVault.Auth/IpAddress/IpBlockListService.cs
index 30d098e33..c49c4dd18 100644
--- a/apps/server/Utilities/AliasVault.Auth/IpAddress/IpBlockListService.cs
+++ b/apps/server/Utilities/AliasVault.Auth/IpAddress/IpBlockListService.cs
@@ -54,8 +54,16 @@ public class IpBlockListService(IAliasServerDbContextFactory dbContextFactory, I
/// <returns>The earliest shadow-block timestamp, or null when not shadow-blocked.</returns>
public async Task<DateTime?> GetShadowBlockCutoffAsync(AliasVaultUser user, IPAddress? ipAddress)
{
- // Account-level shadow-block. When the timestamp is unknown, return min timestamp.
- DateTime? cutoff = user.ShadowBlocked ? (user.ShadowBlockedAt ?? DateTime.UnixEpoch) : null;
+ // Account-level shadow-block, stored on the user's personal group. When the timestamp is unknown, return min timestamp.
+ DateTime? cutoff = null;
+ await using (var dbContext = await dbContextFactory.CreateDbContextAsync())
+ {
+ var personalGroup = await dbContext.Groups.AsNoTracking().Where(g => g.Id == user.PersonalGroupId).Select(g => new { g.ShadowBlocked, g.ShadowBlockedAt }).FirstOrDefaultAsync();
+ if (personalGroup is not null && personalGroup.ShadowBlocked)
+ {
+ cutoff = personalGroup.ShadowBlockedAt ?? DateTime.UnixEpoch;
+ }
+ }
// IP-range shadow-block: the earliest matching block determines the cutoff time.
if (ipAddress is not null)