Skip to content

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

Add capabilities flags to API (#2159)

Leendert de Borst94b4d127b11e
diff --git a/apps/server/AliasVault.Api/Controllers/Abstracts/AuthenticatedRequestController.cs b/apps/server/AliasVault.Api/Controllers/Abstracts/AuthenticatedRequestController.cs
index 3aa65211e..18fb46282 100644
--- a/apps/server/AliasVault.Api/Controllers/Abstracts/AuthenticatedRequestController.cs
+++ b/apps/server/AliasVault.Api/Controllers/Abstracts/AuthenticatedRequestController.cs
@@ -9,6 +9,7 @@ namespace AliasVault.Api.Controllers.Abstracts;
using System.Security.Claims;
using AliasServerDb;
+using AliasVault.Api.Headers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
@@ -22,6 +23,11 @@ using Microsoft.AspNetCore.Mvc;
[Authorize]
public abstract class AuthenticatedRequestController(UserManager<AliasVaultUser> userManager) : ControllerBase
{
+ /// <summary>
+ /// Gets the raw client header the current request arrived with.
+ /// </summary>
+ protected string? ClientHeader => Request.Headers[ClientHeaderInfo.HeaderName].FirstOrDefault();
+
/// <summary>
/// Get the userManager instance.
/// </summary>
diff --git a/apps/server/AliasVault.Api/Controllers/V2/GroupsController.cs b/apps/server/AliasVault.Api/Controllers/V2/GroupsController.cs
index 1e8ad5af0..d0bc23cb6 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/GroupsController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/GroupsController.cs
@@ -9,11 +9,13 @@ namespace AliasVault.Api.Controllers.V2;
using AliasServerDb;
using AliasVault.Api.Controllers.Abstracts;
+using AliasVault.Api.Filters;
using AliasVault.Api.Helpers;
using AliasVault.Shared.Models.Enums;
using AliasVault.Shared.Models.WebApi;
using AliasVault.Shared.Models.WebApi.V2.Groups;
using AliasVault.Shared.Providers.Time;
+using AliasVault.Shared.Server.Capabilities;
using Asp.Versioning;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
@@ -22,6 +24,11 @@ using Microsoft.EntityFrameworkCore;
/// <summary>
/// Groups controller which manages shared groups and their related manifests.
/// </summary>
+/// <remarks>
+/// Note: the vault sharing capability gate sits on the endpoints that create or modify a shared vault or a membership,
+/// and deliberately not on the ones that read or leave one: an account that loses the capability keeps full access to
+/// what it already shares, and can still get out of it. TODO: review all capability gain vs loss states when this is gated behind account tiers.
+/// </remarks>
/// <param name="dbContextFactory">The database context factory.</param>
/// <param name="userManager">The user manager.</param>
/// <param name="timeProvider">Time provider.</param>
@@ -114,10 +121,10 @@ public class GroupsController(IAliasServerDbContextFactory dbContextFactory, Use
/// </summary>
/// <param name="groupId">The shared group ID.</param>
/// <param name="model">The create manifest request.</param>
- /// <param name="clientHeader">The client header.</param>
/// <returns>The created manifest id and its revision.</returns>
[HttpPost("{groupId:guid}/manifest")]
- public async Task<IActionResult> CreateManifest(Guid groupId, [FromBody] CreateSharedManifestRequest model, [FromHeader(Name = "X-AliasVault-Client")] string? clientHeader)
+ [RequireCapability(CapabilityKeys.VaultSharing)]
+ public async Task<IActionResult> CreateManifest(Guid groupId, [FromBody] CreateSharedManifestRequest model)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
var me = await GetCurrentUserAsync();
@@ -168,7 +175,7 @@ public class GroupsController(IAliasServerDbContextFactory dbContextFactory, Use
StorageFormat = ManifestFormat,
RevisionNumber = 0,
FileSize = 0,
- Client = clientHeader,
+ Client = ClientHeader,
CreatedAt = timeProvider.UtcNow,
UpdatedAt = timeProvider.UtcNow,
};
@@ -195,6 +202,7 @@ public class GroupsController(IAliasServerDbContextFactory dbContextFactory, Use
/// <param name="model">The username to look up.</param>
/// <returns>The recipient and the key to seal for.</returns>
[HttpPost("{groupId:guid}/invitations/recipient")]
+ [RequireCapability(CapabilityKeys.VaultSharing)]
public async Task<IActionResult> ResolveInvitationRecipient(Guid groupId, [FromBody] GroupInvitationRecipientRequest model)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
@@ -227,6 +235,7 @@ public class GroupsController(IAliasServerDbContextFactory dbContextFactory, Use
/// <param name="model">The create invitation request.</param>
/// <returns>The created invitation id.</returns>
[HttpPost("{groupId:guid}/invitations")]
+ [RequireCapability(CapabilityKeys.VaultSharing)]
public async Task<IActionResult> CreateInvitation(Guid groupId, [FromBody] CreateGroupInvitationRequest model)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
@@ -301,6 +310,7 @@ public class GroupsController(IAliasServerDbContextFactory dbContextFactory, Use
/// <param name="invitationId">The invitation ID.</param>
/// <returns>Ok on success.</returns>
[HttpPost("invitations/{invitationId:guid}/accept")]
+ [RequireCapability(CapabilityKeys.VaultSharing)]
public async Task<IActionResult> AcceptInvitation(Guid invitationId)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
diff --git a/apps/server/AliasVault.Api/Controllers/V2/StatusController.cs b/apps/server/AliasVault.Api/Controllers/V2/StatusController.cs
index 948fb16d0..c578aac90 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/StatusController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/StatusController.cs
@@ -11,6 +11,7 @@ using AliasServerDb;
using AliasVault.Api.Controllers.Abstracts;
using AliasVault.Api.Headers;
using AliasVault.Api.Helpers;
+using AliasVault.Api.Services;
using AliasVault.Shared.Core;
using AliasVault.Shared.Models.Enums;
using AliasVault.Shared.Models.WebApi;
@@ -27,8 +28,9 @@ using StatusModels = AliasVault.Shared.Models.WebApi.V2.Status;
/// </summary>
/// <param name="dbContextFactory">DbContext factory.</param>
/// <param name="userManager">UserManager.</param>
+/// <param name="capabilityService">Resolves which capabilities the caller may use.</param>
[ApiVersion("2")]
-public class StatusController(IAliasServerDbContextFactory dbContextFactory, UserManager<AliasVaultUser> userManager) : AuthenticatedRequestController(userManager)
+public class StatusController(IAliasServerDbContextFactory dbContextFactory, UserManager<AliasVaultUser> userManager, CapabilityService capabilityService) : AuthenticatedRequestController(userManager)
{
/// <summary>
/// Status endpoint called by the client to get the full sync status in one call.
@@ -85,6 +87,7 @@ public class StatusController(IAliasServerDbContextFactory dbContextFactory, Use
ManifestRevisions = manifestRevisions,
PersonalManifestId = personalManifestId,
BucketRevisions = bucketRevisions,
+ Capabilities = await capabilityService.GetCapabilitiesAsync(user.Id, clientHeader),
PendingActions = await ClientActionHelper.GetPendingActionsAsync(context, user.Id),
});
}
diff --git a/apps/server/AliasVault.Api/Filters/RequireCapabilityAttribute.cs b/apps/server/AliasVault.Api/Filters/RequireCapabilityAttribute.cs
new file mode 100644
index 000000000..2ab9e5192
--- /dev/null
+++ b/apps/server/AliasVault.Api/Filters/RequireCapabilityAttribute.cs
@@ -0,0 +1,45 @@
+//-----------------------------------------------------------------------
+// <copyright file="RequireCapabilityAttribute.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Api.Filters;
+
+using System.Security.Claims;
+using AliasVault.Api.Headers;
+using AliasVault.Api.Services;
+using AliasVault.Shared.Models.Enums;
+using AliasVault.Shared.Models.WebApi;
+using AliasVault.Shared.Server.Capabilities;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Filters;
+
+/// <summary>
+/// Refuses the request when the capability is not enabled for the calling account.
+/// </summary>
+/// <param name="capabilityKey">The capability key to require, from <see cref="CapabilityKeys"/>.</param>
+[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
+public sealed class RequireCapabilityAttribute(string capabilityKey) : Attribute, IAsyncAuthorizationFilter
+{
+ /// <inheritdoc />
+ public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
+ {
+ var userId = context.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
+ if (userId is null)
+ {
+ context.Result = new UnauthorizedResult();
+ return;
+ }
+
+ var capabilityService = context.HttpContext.RequestServices.GetRequiredService<CapabilityService>();
+ var clientHeader = context.HttpContext.Request.Headers[ClientHeaderInfo.HeaderName].FirstOrDefault();
+ if (await capabilityService.IsEnabledAsync(userId, capabilityKey, clientHeader))
+ {
+ return;
+ }
+
+ context.Result = new ObjectResult(ApiErrorCodeHelper.CreateErrorResponse(ApiErrorCode.CAPABILITY_NOT_AVAILABLE, StatusCodes.Status403Forbidden)) { StatusCode = StatusCodes.Status403Forbidden };
+ }
+}
diff --git a/apps/server/AliasVault.Api/Program.cs b/apps/server/AliasVault.Api/Program.cs
index 1a120156a..1db3d14ae 100644
--- a/apps/server/AliasVault.Api/Program.cs
+++ b/apps/server/AliasVault.Api/Program.cs
@@ -90,6 +90,7 @@ builder.Services.AddScoped<IpBlockListService>();
builder.Services.AddScoped<MobileLoginRateLimitService>();
builder.Services.AddSingleton<FaviconRateLimitService>();
builder.Services.AddScoped<RateLimitService>();
+builder.Services.AddScoped<CapabilityService>();
builder.Services.AddHttpContextAccessor();
builder.Services.AddLogging(logging =>
diff --git a/apps/server/AliasVault.Api/Services/CapabilityResolver.cs b/apps/server/AliasVault.Api/Services/CapabilityResolver.cs
new file mode 100644
index 000000000..211061efe
--- /dev/null
+++ b/apps/server/AliasVault.Api/Services/CapabilityResolver.cs
@@ -0,0 +1,143 @@
+//-----------------------------------------------------------------------
+// <copyright file="CapabilityResolver.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Api.Services;
+
+using AliasServerDb;
+using AliasVault.Shared.Server.Capabilities;
+
+/// <summary>
+/// Resolver logic which determines what a capability resolves to for a given caller.
+/// </summary>
+public static class CapabilityResolver
+{
+ /// <summary>
+ /// Resolves every capability this build knows about for the given caller. Ones no rule targets fall back to their registry default.
+ /// </summary>
+ /// <param name="rules">The candidate rules.</param>
+ /// <param name="subject">The caller to resolve for.</param>
+ /// <param name="now">The current UTC time, used to evaluate effective-from/until windows.</param>
+ /// <returns>Every known capability key and its resolved value.</returns>
+ public static Dictionary<string, string> ResolveAll(IEnumerable<CapabilityRule> rules, CapabilitySubject subject, DateTime now)
+ {
+ var byKey = rules.Where(r => Applies(r, subject, now)).GroupBy(r => r.CapabilityKey, StringComparer.OrdinalIgnoreCase).ToDictionary(g => g.Key, g => g.ToList(), StringComparer.OrdinalIgnoreCase);
+
+ var resolved = new Dictionary<string, string>(StringComparer.Ordinal);
+ foreach (var definition in CapabilityRegistry.All)
+ {
+ var winner = byKey.TryGetValue(definition.Key, out var candidates) ? PickWinner(candidates, subject) : null;
+ resolved[definition.Key] = winner?.Value ?? definition.DefaultValue;
+ }
+
+ return resolved;
+ }
+
+ /// <summary>
+ /// Resolves a single capability for the given caller.
+ /// </summary>
+ /// <param name="rules">The candidate rules.</param>
+ /// <param name="subject">The caller to resolve for.</param>
+ /// <param name="capabilityKey">The capability key to resolve.</param>
+ /// <param name="now">The current UTC time, used to evaluate effective-from/until windows.</param>
+ /// <returns>The resolved value, or the registry default when no rule targets the caller.</returns>
+ public static string Resolve(IEnumerable<CapabilityRule> rules, CapabilitySubject subject, string capabilityKey, DateTime now)
+ {
+ var candidates = rules.Where(r => string.Equals(r.CapabilityKey, capabilityKey, StringComparison.OrdinalIgnoreCase) && Applies(r, subject, now)).ToList();
+ var winner = PickWinner(candidates, subject);
+ if (winner is not null)
+ {
+ return winner.Value;
+ }
+
+ return CapabilityRegistry.Find(capabilityKey)?.DefaultValue ?? string.Empty;
+ }
+
+ /// <summary>
+ /// Whether a rule is live right now and targets this caller at all.
+ /// </summary>
+ private static bool Applies(CapabilityRule rule, CapabilitySubject subject, DateTime now)
+ {
+ if (!rule.Enabled)
+ {
+ return false;
+ }
+
+ if ((rule.EffectiveFrom is not null && rule.EffectiveFrom > now) || (rule.EffectiveUntil is not null && rule.EffectiveUntil < now))
+ {
+ return false;
+ }
+
+ if (rule.ClientName is not null && !string.Equals(rule.ClientName, subject.ClientName, StringComparison.OrdinalIgnoreCase))
+ {
+ return false;
+ }
+
+ return ScopeRank(rule, subject) is not null;
+ }
+
+ /// <summary>
+ /// How specific a rule's scope is for this caller. Null when the rule targets somebody else.
+ /// </summary>
+ private static int? ScopeRank(CapabilityRule rule, CapabilitySubject subject)
+ {
+ if (rule.UserId is not null)
+ {
+ return string.Equals(rule.UserId, subject.UserId, StringComparison.Ordinal) ? 3 : null;
+ }
+
+ if (rule.GroupId is not null)
+ {
+ return subject.GroupIds.Contains(rule.GroupId.Value) ? 2 : null;
+ }
+
+ if (rule.Tier is not null)
+ {
+ return rule.Tier == subject.Tier ? 1 : null;
+ }
+
+ return 0;
+ }
+
+ /// <summary>
+ /// The rule that decides the value.
+ /// </summary>
+ private static CapabilityRule? PickWinner(List<CapabilityRule> candidates, CapabilitySubject subject)
+ {
+ CapabilityRule? winner = null;
+ var winningRank = -1;
+
+ foreach (var rule in candidates)
+ {
+ var rank = ScopeRank(rule, subject);
+ if (rank is null)
+ {
+ continue;
+ }
+
+ if (rank > winningRank || (rank == winningRank && Supersedes(rule, winner!)))
+ {
+ winner = rule;
+ winningRank = rank.Value;
+ }
+ }
+
+ return winner;
+ }
+
+ /// <summary>
+ /// Whether one rule takes precedence over another of the same scope.
+ /// </summary>
+ private static bool Supersedes(CapabilityRule rule, CapabilityRule current)
+ {
+ if (rule.UpdatedAt != current.UpdatedAt)
+ {
+ return rule.UpdatedAt > current.UpdatedAt;
+ }
+
+ return rule.Id.CompareTo(current.Id) > 0;
+ }
+}
diff --git a/apps/server/AliasVault.Api/Services/CapabilityService.cs b/apps/server/AliasVault.Api/Services/CapabilityService.cs
new file mode 100644
index 000000000..17468fc62
--- /dev/null
+++ b/apps/server/AliasVault.Api/Services/CapabilityService.cs
@@ -0,0 +1,102 @@
+//-----------------------------------------------------------------------
+// <copyright file="CapabilityService.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Api.Services;
+
+using AliasServerDb;
+using AliasVault.Api.Headers;
+using AliasVault.Shared.Providers.Time;
+using AliasVault.Shared.Server.Capabilities;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Caching.Memory;
+
+/// <summary>
+/// Answers which capabilities a caller may use. Rules are read from the CapabilityRules table and cached in memory briefly.
+/// </summary>
+/// <param name="dbContextFactory">IDbContextFactory instance.</param>
+/// <param name="cache">IMemoryCache instance used to cache the enabled rules.</param>
+/// <param name="timeProvider">ITimeProvider instance.</param>
+public class CapabilityService(IAliasServerDbContextFactory dbContextFactory, IMemoryCache cache, ITimeProvider timeProvider)
+{
+ private const int CacheDurationSeconds = 60;
+
+ private const string EnabledRulesCacheKey = "CapabilityRules_Enabled";
+
+ /// <summary>
+ /// Resolves the caller's capabilities, every one this build knows about, on or off.
+ /// </summary>
+ /// <param name="userId">The calling account.</param>
+ /// <param name="clientHeader">The raw client header the call arrived with, used by client-scoped rules.</param>
+ /// <returns>Every known capability key and its resolved value.</returns>
+ public async Task<Dictionary<string, string>> GetCapabilitiesAsync(string userId, string? clientHeader)
+ {
+ var rules = await GetEnabledRulesAsync();
+ var subject = await BuildSubjectAsync(userId, clientHeader, rules);
+ return CapabilityResolver.ResolveAll(rules, subject, timeProvider.UtcNow);
+ }
+
+ /// <summary>
+ /// Whether the caller may use a capability.
+ /// </summary>
+ /// <param name="userId">The calling account.</param>
+ /// <param name="capabilityKey">The capability key, from <see cref="CapabilityKeys"/>.</param>
+ /// <param name="clientHeader">The raw client header the call arrived with, used by client-scoped rules.</param>
+ /// <returns>True when the capability is on for this caller.</returns>
+ public async Task<bool> IsEnabledAsync(string userId, string capabilityKey, string? clientHeader)
+ {
+ var rules = await GetEnabledRulesAsync();
+ var subject = await BuildSubjectAsync(userId, clientHeader, rules);
+ return CapabilityValue.IsEnabled(CapabilityResolver.Resolve(rules, subject, capabilityKey, timeProvider.UtcNow));
+ }
+
+ /// <summary>
+ /// Gathers what the caller can be targeted by.
+ /// </summary>
+ private async Task<CapabilitySubject> BuildSubjectAsync(string userId, string? clientHeader, List<CapabilityRule> rules)
+ {
+ var groupIds = rules.Exists(r => r.GroupId is not null) ? await GetGroupIdsAsync(userId) : [];
+ return new CapabilitySubject(userId, groupIds, AccountTier.Free, ClientHeaderInfo.Parse(clientHeader).ClientName);
+ }
+
+ /// <summary>
+ /// Every group the account belongs to, its personal group included.
+ /// </summary>
+ private async Task<List<Guid>> GetGroupIdsAsync(string userId)
+ {
+ await using var dbContext = await dbContextFactory.CreateDbContextAsync();
+ var groupIds = await dbContext.GroupMembers.AsNoTracking().Where(m => m.UserId == userId).Select(m => m.GroupId).ToListAsync();
+ var personalGroupId = await dbContext.AliasVaultUsers.AsNoTracking().Where(u => u.Id == userId).Select(u => u.PersonalGroupId).FirstOrDefaultAsync();
+
+ if (personalGroupId != Guid.Empty && !groupIds.Contains(personalGroupId))
+ {
+ groupIds.Add(personalGroupId);
+ }
+
+ return groupIds;
+ }
+
+ /// <summary>
+ /// Returns the enabled rules from cache.
+ /// </summary>
+ /// <returns>The list of enabled rules.</returns>
+ private async Task<List<CapabilityRule>> GetEnabledRulesAsync()
+ {
+ if (cache.TryGetValue(EnabledRulesCacheKey, out List<CapabilityRule>? cached) && cached is not null)
+ {
+ return cached;
+ }
+
+ await using var dbContext = await dbContextFactory.CreateDbContextAsync();
+ var rules = await dbContext.CapabilityRules
+ .AsNoTracking()
+ .Where(x => x.Enabled)
+ .ToListAsync();
+
+ cache.Set(EnabledRulesCacheKey, rules, TimeSpan.FromSeconds(CacheDurationSeconds));
+ return rules;
+ }
+}
diff --git a/apps/server/AliasVault.Api/Services/CapabilitySubject.cs b/apps/server/AliasVault.Api/Services/CapabilitySubject.cs
new file mode 100644
index 000000000..27d907d49
--- /dev/null
+++ b/apps/server/AliasVault.Api/Services/CapabilitySubject.cs
@@ -0,0 +1,20 @@
+//-----------------------------------------------------------------------
+// <copyright file="CapabilitySubject.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Api.Services;
+
+using System.Collections.Generic;
+using AliasServerDb;
+
+/// <summary>
+/// Who a capability is being resolved for.
+/// </summary>
+/// <param name="UserId">The account.</param>
+/// <param name="GroupIds">Every group the account belongs to, its personal group included.</param>
+/// <param name="Tier">The account's plan.</param>
+/// <param name="ClientName">The client making the call, from the client header. Null when it did not say.</param>
+public sealed record CapabilitySubject(string UserId, IReadOnlyCollection<Guid> GroupIds, AccountTier Tier, string? ClientName);
diff --git a/apps/server/Databases/AliasServerDb/AliasServerDbContext.cs b/apps/server/Databases/AliasServerDb/AliasServerDbContext.cs
index 293e93e6c..dc409c095 100644
--- a/apps/server/Databases/AliasServerDb/AliasServerDbContext.cs
+++ b/apps/server/Databases/AliasServerDb/AliasServerDbContext.cs
@@ -192,6 +192,11 @@ public class AliasServerDbContext : WorkerStatusDbContext, IDataProtectionKeyCon
/// </summary>
public DbSet<RateLimit> RateLimits { get; set; }
+ /// <summary>
+ /// Gets or sets the CapabilityRules DbSet.
+ /// </summary>
+ public DbSet<CapabilityRule> CapabilityRules { get; set; }
+
/// <summary>
/// Gets or sets the UserUnlockKeys DbSet.
/// </summary>
@@ -424,6 +429,23 @@ public class AliasServerDbContext : WorkerStatusDbContext, IDataProtectionKeyCon
.OnDelete(DeleteBehavior.SetNull);
});
+ // Configure CapabilityRule.
+ modelBuilder.Entity<CapabilityRule>(builder =>
+ {
+ builder.HasOne(e => e.User)
+ .WithMany()
+ .HasForeignKey(e => e.UserId)
+ .OnDelete(DeleteBehavior.Cascade);
+
+ builder.HasOne(e => e.Group)
+ .WithMany()
+ .HasForeignKey(e => e.GroupId)
+ .OnDelete(DeleteBehavior.Cascade);
+
+ builder.Property(e => e.Kind).HasConversion<string>().HasMaxLength(20);
+ builder.Property(e => e.Tier).HasConversion<string>().HasMaxLength(20);
+ });
+
// Configure UserUnlockKey: one row per enrolled unlock method, each encrypting the user's Account Key.
modelBuilder.Entity<UserUnlockKey>(builder =>
{
diff --git a/apps/server/Databases/AliasServerDb/CapabilityRule.cs b/apps/server/Databases/AliasServerDb/CapabilityRule.cs
new file mode 100644
index 000000000..78ea1d3cf
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/CapabilityRule.cs
@@ -0,0 +1,119 @@
+//-----------------------------------------------------------------------
+// <copyright file="CapabilityRule.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasServerDb;
+
+using System;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using Microsoft.EntityFrameworkCore;
+
+/// <summary>
+/// Rule which adds server-side control to enable or disable capabilities for specific users, groups or plans based on the environment.
+/// </summary>
+[Index(nameof(CapabilityKey), nameof(Enabled))]
+[Index(nameof(UserId))]
+[Index(nameof(GroupId))]
+[Index(nameof(Tier))]
+public class CapabilityRule
+{
+ /// <summary>
+ /// Gets or sets the unique identifier for the rule.
+ /// </summary>
+ [Key]
+ public Guid Id { get; set; }
+
+ /// <summary>
+ /// Gets or sets the capability this rule governs, e.g. "vault-sharing". Free text rather than an enum, so a rule
+ /// may name a key the running build predates; an unknown key matches nothing.
+ /// </summary>
+ [MaxLength(100)]
+ public string CapabilityKey { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets what this rule is for. Documentation and cleanup only; resolution ignores it.
+ /// </summary>
+ public CapabilityRuleKind Kind { get; set; } = CapabilityRuleKind.Entitlement;
+
+ /// <summary>
+ /// Gets or sets the account this rule applies to (per-account override). Null for wider rules.
+ /// </summary>
+ [MaxLength(255)]
+ public string? UserId { get; set; }
+
+ /// <summary>
+ /// Gets or sets the navigation property to the account this rule applies to.
+ /// </summary>
+ [ForeignKey(nameof(UserId))]
+ public virtual AliasVaultUser? User { get; set; }
+
+ /// <summary>
+ /// Gets or sets the group this rule applies to (per-group override). Null for wider rules.
+ /// </summary>
+ public Guid? GroupId { get; set; }
+
+ /// <summary>
+ /// Gets or sets the navigation property to the group this rule applies to.
+ /// </summary>
+ [ForeignKey(nameof(GroupId))]
+ public virtual Group? Group { get; set; }
+
+ /// <summary>
+ /// Gets or sets the account tier this rule applies to. Null for per-account, per-group and global rules.
+ /// </summary>
+ public AccountTier? Tier { get; set; }
+
+ /// <summary>
+ /// Gets or sets what the capability resolves to when this rule wins. Boolean capabilities use "true" and "false".
+ /// </summary>
+ [MaxLength(255)]
+ public string Value { get; set; } = "false";
+
+ /// <summary>
+ /// Gets or sets the client this rule is limited to, matched against the client header name (e.g. "chrome").
+ /// Null = every client.
+ /// </summary>
+ [MaxLength(100)]
+ public string? ClientName { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether this rule is applied. Disabled rules are retained for auditing.
+ /// </summary>
+ public bool Enabled { get; set; } = true;
+
+ /// <summary>
+ /// Gets or sets an optional UTC timestamp before which the rule does not apply.
+ /// </summary>
+ public DateTime? EffectiveFrom { get; set; }
+
+ /// <summary>
+ /// Gets or sets an optional UTC timestamp after which the rule no longer applies.
+ /// </summary>
+ public DateTime? EffectiveUntil { get; set; }
+
+ /// <summary>
+ /// Gets or sets an optional note describing why the rule exists.
+ /// </summary>
+ [MaxLength(1000)]
+ public string? Notes { get; set; }
+
+ /// <summary>
+ /// Gets or sets an optional identifier of who created the rule.
+ /// </summary>
+ [MaxLength(255)]
+ public string? CreatedBy { get; set; }
+
+ /// <summary>
+ /// Gets or sets the creation date of the rule.
+ /// </summary>
+ public DateTime CreatedAt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the last update date of the rule.
+ /// </summary>
+ public DateTime UpdatedAt { get; set; }
+}
diff --git a/apps/server/Databases/AliasServerDb/CapabilityRuleKind.cs b/apps/server/Databases/AliasServerDb/CapabilityRuleKind.cs
new file mode 100644
index 000000000..9b54060df
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/CapabilityRuleKind.cs
@@ -0,0 +1,24 @@
+//-----------------------------------------------------------------------
+// <copyright file="CapabilityRuleKind.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasServerDb;
+
+/// <summary>
+/// What a <see cref="CapabilityRule"/> rule is for. Only used for documentation purposes.
+/// </summary>
+public enum CapabilityRuleKind
+{
+ /// <summary>
+ /// What an account is allowed to have based on their current plan, or on the general environment.
+ /// </summary>
+ Entitlement = 0,
+
+ /// <summary>
+ /// Whether a code path is live yet, used for temporary rollouts of new capabilities.
+ /// </summary>
+ Rollout = 1,
+}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260821145822_AddCapabilityRules.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260821145822_AddCapabilityRules.Designer.cs
new file mode 100644
index 000000000..a7e76ac07
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/Migrations/20260821145822_AddCapabilityRules.Designer.cs
@@ -0,0 +1,1926 @@
+// <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("20260821145822_AddCapabilityRules")]
+ partial class AddCapabilityRules
+ {
+ /// <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.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.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.CapabilityRule", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("CapabilityKey")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("ClientName")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ 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<Guid?>("GroupId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Kind")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<string>("Notes")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Tier")
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Value")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("GroupId");
+
+ b.HasIndex("Tier");
+
+ b.HasIndex("UserId");
+
+ b.HasIndex("CapabilityKey", "Enabled");
+
+ b.ToTable("CapabilityRules");
+ });
+
+ modelBuilder.Entity("AliasServerDb.ClientAction", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid?>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Payload")
+ .HasColumnType("jsonb");
+
+ b.Property<Guid?>("TargetGroupId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("TargetUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex("TargetGroupId");
+
+ b.HasIndex("TargetUserId");
+
+ b.ToTable("ClientActions");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<int>("AttachmentCount")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("Date")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime>("DateSystem")
+ .HasColumnType("timestamp with time zone");
+
+ 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")
+ .HasColumnType("text");
+
+ b.Property<byte[]>("MessageSourceBytes")
+ .HasColumnType("bytea");
+
+ 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("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<bool>("AnonymizedSenderCounted")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Address")
+ .IsUnique();
+
+ b.ToTable("EmailClaims");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailClaimLink", b =>
+ {
+ b.Property<Guid>("EmailClaimId")
+ .HasColumnType("uuid");
+
+ b.Property<Guid>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("State")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.HasKey("EmailClaimId", "VaultManifestId");
+
+ b.HasIndex("EmailClaimId")
+ .HasDatabaseName("IX_EmailClaimLinks_EmailClaimId_Live")
+ .HasFilter("\"State\" <> 'Removed'");
+
+ b.HasIndex("VaultManifestId", "EmailClaimId");
+
+ b.ToTable("EmailClaimLinks");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailDecryptionKey", b =>
+ {
+ b.Property<int>("EmailId")
+ .HasColumnType("integer");
+
+ b.Property<Guid>("VaultManifestDeliveryKeyId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("EncryptedSymmetricKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("EmailId", "VaultManifestDeliveryKeyId");
+
+ b.HasIndex("VaultManifestDeliveryKeyId", "EmailId");
+
+ b.ToTable("EmailDecryptionKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailPart", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<byte[]>("Bytes")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<int>("EmailId")
+ .HasColumnType("integer");
+
+ b.Property<int>("PartIndex")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("EmailId", "PartIndex")
+ .IsUnique();
+
+ b.ToTable("EmailParts");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Group", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.PrimitiveCollection<int[]>("AnonymizedEmailAliasSenderCounts")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer[]")
+ .HasDefaultValueSql("array_fill(0, ARRAY[64])");
+
+ 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.GroupInvitation", 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")
+ .HasColumnType("text");
+
+ b.Property<Guid>("GroupId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("InviteeUserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("InviterUserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime?>("RespondedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("Role")
+ .HasColumnType("integer");
+
+ b.Property<string>("State")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid?>("UserGrantKeyId")
+ .HasColumnType("uuid");
+
+ b.Property<Guid?>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("InviterUserId");
+
+ b.HasIndex("UserGrantKeyId");
+
+ b.HasIndex("GroupId", "InviteeUserId")
+ .IsUnique()
+ .HasDatabaseName("UX_GroupInvitations_Group_Invitee_Pending")
+ .HasFilter("\"State\" = 'Pending'");
+
+ b.HasIndex("InviteeUserId", "State");
+
+ b.ToTable("GroupInvitations");
+ });
+
+ 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<Guid?>("GroupId")
+ .HasColumnType("uuid");
+
+ 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<int>("WindowSeconds")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("GroupId");
+
+ b.HasIndex("Tier");
+
+ 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<int>("AccountKeyVersion")
+ .HasColumnType("integer");
+
+ 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<int>("AccountKeyVersion")
+ .HasColumnType("integer");
+
+ 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<string>("Label")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<DateTime?>("LastUsedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Metadata")
+ .HasColumnType("jsonb");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ 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", "Label")
+ .IsUnique()
+ .HasDatabaseName("UX_UserUnlockKeys_UserId_Type_Label");
+
+ 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<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ 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<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ 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<byte[]>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("ManifestId", "Category");
+
+ b.ToTable("VaultDataBuckets");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ 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<byte[]>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("ManifestId", "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")
+ .HasColumnType("text");
+
+ b.Property<string>("EncryptionType")
+ .HasColumnType("text");
+
+ b.Property<int>("FileSize")
+ .HasColumnType("integer");
+
+ b.Property<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<byte[]>("ManifestBlob")
+ .HasColumnType("bytea");
+
+ 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")
+ .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")
+ .HasColumnType("text");
+
+ b.Property<string>("Verifier")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Version")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("ManifestId");
+
+ b.HasIndex("OwnerGroupId");
+
+ b.ToTable("VaultManifests");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestAccessKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<int?>("AccountKeyVersion")
+ .HasColumnType("integer");
+
+ 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<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<DateTime?>("LastUsedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Metadata")
+ .HasColumnType("jsonb");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ 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", "KeyVersion")
+ .IsUnique()
+ .HasDatabaseName("UX_VaultManifestAccessKeys_UserId_Type_Manifest_Version");
+
+ 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")
+ .HasColumnType("text");
+
+ b.Property<string>("EncryptionType")
+ .HasColumnType("text");
+
+ b.Property<int>("FileSize")
+ .HasColumnType("integer");
+
+ b.Property<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<byte[]>("ManifestBlob")
+ .HasColumnType("bytea");
+
+ b.Property<string>("ManifestCiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("Salt")
+ .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")
+ .HasColumnType("text");
+
+ b.Property<string>("Verifier")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Version")
+ .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.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.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.CapabilityRule", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "Group")
+ .WithMany()
+ .HasForeignKey("GroupId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("Group");
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.ClientAction", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "TargetGroup")
+ .WithMany()
+ .HasForeignKey("TargetGroupId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "TargetUser")
+ .WithMany()
+ .HasForeignKey("TargetUserId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("TargetGroup");
+
+ b.Navigation("TargetUser");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>
+ {
+ b.HasOne("AliasServerDb.Email", "Email")
+ .WithMany("Attachments")
+ .HasForeignKey("EmailId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Email");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailClaimLink", b =>
+ {
+ b.HasOne("AliasServerDb.EmailClaim", "EmailClaim")
+ .WithMany("Links")
+ .HasForeignKey("EmailClaimId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")
+ .WithMany()
+ .HasForeignKey("VaultManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("EmailClaim");
+
+ b.Navigation("VaultManifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailDecryptionKey", b =>
+ {
+ b.HasOne("AliasServerDb.Email", "Email")
+ .WithMany("DecryptionKeys")
+ .HasForeignKey("EmailId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.VaultManifestDeliveryKey", "VaultManifestDeliveryKey")
+ .WithMany("DecryptionKeys")
+ .HasForeignKey("VaultManifestDeliveryKeyId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired()
+ .HasConstraintName("FK_EmailDecryptionKeys_VaultManifestDeliveryKeys_DeliveryKeyId");
+
+ b.Navigation("Email");
+
+ b.Navigation("VaultManifestDeliveryKey");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailPart", b =>
+ {
+ b.HasOne("AliasServerDb.Email", "Email")
+ .WithMany("Parts")
+ .HasForeignKey("EmailId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Email");
+ });
+
+ modelBuilder.Entity("AliasServerDb.GroupInvitation", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "Group")
+ .WithMany()
+ .HasForeignKey("GroupId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "Invitee")
+ .WithMany()
+ .HasForeignKey("InviteeUserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "Inviter")
+ .WithMany()
+ .HasForeignKey("InviterUserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.UserGrantKey", "UserGrantKey")
+ .WithMany()
+ .HasForeignKey("UserGrantKeyId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.Navigation("Group");
+
+ b.Navigation("Invitee");
+
+ b.Navigation("Inviter");
+
+ b.Navigation("UserGrantKey");
+ });
+
+ 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.Group", "Group")
+ .WithMany()
+ .HasForeignKey("GroupId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("Group");
+ });
+
+ 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.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Manifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>
+ {
+ b.HasOne("AliasServerDb.VaultDataBucket", "Bucket")
+ .WithMany()
+ .HasForeignKey("ManifestId", "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");
+
+ b.Navigation("DecryptionKeys");
+
+ b.Navigation("Parts");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailClaim", b =>
+ {
+ b.Navigation("Links");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Group", b =>
+ {
+ b.Navigation("Members");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
+ {
+ b.Navigation("DecryptionKeys");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260821145822_AddCapabilityRules.cs b/apps/server/Databases/AliasServerDb/Migrations/20260821145822_AddCapabilityRules.cs
new file mode 100644
index 000000000..85b5622f7
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/Migrations/20260821145822_AddCapabilityRules.cs
@@ -0,0 +1,79 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace AliasServerDb.Migrations
+{
+ /// <inheritdoc />
+ public partial class AddCapabilityRules : Migration
+ {
+ /// <inheritdoc />
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "CapabilityRules",
+ columns: table => new
+ {
+ Id = table.Column<Guid>(type: "uuid", nullable: false),
+ CapabilityKey = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
+ Kind = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
+ UserId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
+ GroupId = table.Column<Guid>(type: "uuid", nullable: true),
+ Tier = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true),
+ Value = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
+ ClientName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
+ Enabled = table.Column<bool>(type: "boolean", nullable: false),
+ EffectiveFrom = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
+ EffectiveUntil = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
+ Notes = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
+ CreatedBy = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
+ CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
+ UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_CapabilityRules", x => x.Id);
+ table.ForeignKey(
+ name: "FK_CapabilityRules_AliasVaultUsers_UserId",
+ column: x => x.UserId,
+ principalTable: "AliasVaultUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_CapabilityRules_Groups_GroupId",
+ column: x => x.GroupId,
+ principalTable: "Groups",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_CapabilityRules_CapabilityKey_Enabled",
+ table: "CapabilityRules",
+ columns: new[] { "CapabilityKey", "Enabled" });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_CapabilityRules_GroupId",
+ table: "CapabilityRules",
+ column: "GroupId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_CapabilityRules_Tier",
+ table: "CapabilityRules",
+ column: "Tier");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_CapabilityRules_UserId",
+ table: "CapabilityRules",
+ column: "UserId");
+ }
+
+ /// <inheritdoc />
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "CapabilityRules");
+ }
+ }
+}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
index a17700258..79e225595 100644
--- a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
+++ b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
@@ -329,6 +329,78 @@ namespace AliasServerDb.Migrations
b.ToTable("BlockedIpRanges");
});
+ modelBuilder.Entity("AliasServerDb.CapabilityRule", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("CapabilityKey")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("ClientName")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ 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<Guid?>("GroupId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Kind")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<string>("Notes")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Tier")
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Value")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("GroupId");
+
+ b.HasIndex("Tier");
+
+ b.HasIndex("UserId");
+
+ b.HasIndex("CapabilityKey", "Enabled");
+
+ b.ToTable("CapabilityRules");
+ });
+
modelBuilder.Entity("AliasServerDb.ClientAction", b =>
{
b.Property<Guid>("Id")
@@ -1532,6 +1604,23 @@ namespace AliasServerDb.Migrations
b.Navigation("User");
});
+ modelBuilder.Entity("AliasServerDb.CapabilityRule", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "Group")
+ .WithMany()
+ .HasForeignKey("GroupId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("Group");
+
+ b.Navigation("User");
+ });
+
modelBuilder.Entity("AliasServerDb.ClientAction", b =>
{
b.HasOne("AliasServerDb.Group", "TargetGroup")
diff --git a/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityDefinition.cs b/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityDefinition.cs
new file mode 100644
index 000000000..85e3fb74b
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityDefinition.cs
@@ -0,0 +1,25 @@
+//-----------------------------------------------------------------------
+// <copyright file="CapabilityDefinition.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Server.Capabilities;
+
+using AliasServerDb;
+
+/// <summary>
+/// One capability this server build knows about.
+/// </summary>
+/// <param name="Key">The key clients gate on, from <see cref="CapabilityKeys"/>.</param>
+/// <param name="Kind">Whether the capability is a durable entitlement or a temporary rollout switch.</param>
+/// <param name="DefaultValue">What the capability resolves to when no rule matches.</param>
+/// <param name="Description">What the capability covers, shown to the operator in the admin portal.</param>
+public sealed record CapabilityDefinition(string Key, CapabilityRuleKind Kind, string DefaultValue, string Description)
+{
+ /// <summary>
+ /// Gets a value indicating whether the capability is disabled unless a rule says otherwise.
+ /// </summary>
+ public bool IsDefaultOff => !CapabilityValue.IsEnabled(DefaultValue);
+}
diff --git a/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityKeys.cs b/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityKeys.cs
new file mode 100644
index 000000000..61b8f0d11
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityKeys.cs
@@ -0,0 +1,19 @@
+//-----------------------------------------------------------------------
+// <copyright file="CapabilityKeys.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Server.Capabilities;
+
+/// <summary>
+/// The capability keys this server build knows about.
+/// </summary>
+public static class CapabilityKeys
+{
+ /// <summary>
+ /// Shared vaults.
+ /// </summary>
+ public const string VaultSharing = "vault-sharing";
+}
diff --git a/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityRegistry.cs b/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityRegistry.cs
new file mode 100644
index 000000000..9d9b14400
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityRegistry.cs
@@ -0,0 +1,41 @@
+//-----------------------------------------------------------------------
+// <copyright file="CapabilityRegistry.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Server.Capabilities;
+
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using AliasServerDb;
+
+/// <summary>
+/// All known capabilities with their default values and descriptions, used for administration and fall-back purposes.
+/// </summary>
+public static class CapabilityRegistry
+{
+ private static readonly ReadOnlyCollection<CapabilityDefinition> Definitions = new List<CapabilityDefinition>
+ {
+ new(
+ CapabilityKeys.VaultSharing,
+ CapabilityRuleKind.Entitlement,
+ CapabilityValue.Off,
+ "Shared vaults: creating a shared vault, inviting people to it and accepting invitations. Currently in beta."),
+ }.AsReadOnly();
+
+ private static readonly Dictionary<string, CapabilityDefinition> ByKey = Definitions.ToDictionary(d => d.Key, StringComparer.OrdinalIgnoreCase);
+
+ /// <summary>
+ /// Gets every capability this build knows about.
+ /// </summary>
+ public static IReadOnlyList<CapabilityDefinition> All => Definitions;
+
+ /// <summary>
+ /// Looks up a capability by key.
+ /// </summary>
+ /// <param name="key">The capability key.</param>
+ /// <returns>The definition, or null when this build does not know the key.</returns>
+ public static CapabilityDefinition? Find(string key) => ByKey.GetValueOrDefault(key);
+}
diff --git a/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityValue.cs b/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityValue.cs
new file mode 100644
index 000000000..639de0b45
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared.Server/Capabilities/CapabilityValue.cs
@@ -0,0 +1,40 @@
+//-----------------------------------------------------------------------
+// <copyright file="CapabilityValue.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Server.Capabilities;
+
+using System;
+
+/// <summary>
+/// Capability values travel as strings so one can carry a cap or a variant name and not only an on/off.
+/// </summary>
+public static class CapabilityValue
+{
+ /// <summary>
+ /// The value of a boolean capability that is on.
+ /// </summary>
+ public const string On = "true";
+
+ /// <summary>
+ /// The value of a boolean capability that is off.
+ /// </summary>
+ public const string Off = "false";
+
+ /// <summary>
+ /// Whether a resolved value means the capability is on. Anything that is not "true" is off.
+ /// </summary>
+ /// <param name="value">The resolved value.</param>
+ /// <returns>True when the capability is on.</returns>
+ public static bool IsEnabled(string? value) => string.Equals(value, On, StringComparison.OrdinalIgnoreCase);
+
+ /// <summary>
+ /// The value to store for a boolean capability.
+ /// </summary>
+ /// <param name="enabled">Whether the capability should be on.</param>
+ /// <returns>The value to store.</returns>
+ public static string From(bool enabled) => enabled ? On : Off;
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs b/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
index 222227b1b..25ba11b58 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
@@ -249,4 +249,9 @@ public enum ApiErrorCode
/// Too many mobile login requests were created from this client in a short period.
/// </summary>
MOBILE_LOGIN_RATE_LIMIT_EXCEEDED,
+
+ /// <summary>
+ /// The capability the request needs is not enabled for this account on this server.
+ /// </summary>
+ CAPABILITY_NOT_AVAILABLE,
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Status/StatusResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Status/StatusResponse.cs
index efdfc487c..1276c6d25 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Status/StatusResponse.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Status/StatusResponse.cs
@@ -49,6 +49,12 @@ public class StatusResponse
/// <summary>Gets or sets the latest revision for each data-bucket kind the user has. Empty when none stored.</summary>
public List<BucketRevision> BucketRevisions { get; set; } = [];
+ /// <summary>
+ /// Gets or sets what this caller may do, keyed by capability. Includes the ones that are off, so an absent key
+ /// means only that this server does not know the capability.
+ /// </summary>
+ public Dictionary<string, string> Capabilities { get; set; } = [];
+
/// <summary>
/// Gets or sets the work the server needs this client to carry out, because it needs something only a client has:
/// vault content, a vault key, a private key. This primarily affects vault sharing and revocation actions.
diff --git a/apps/server/Tests/AliasVault.UnitTests/Services/CapabilityResolverTests.cs b/apps/server/Tests/AliasVault.UnitTests/Services/CapabilityResolverTests.cs
new file mode 100644
index 000000000..810c33fb6
--- /dev/null
+++ b/apps/server/Tests/AliasVault.UnitTests/Services/CapabilityResolverTests.cs
@@ -0,0 +1,254 @@
+//-----------------------------------------------------------------------
+// <copyright file="CapabilityResolverTests.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.UnitTests.Services;
+
+using AliasServerDb;
+using AliasVault.Api.Services;
+using AliasVault.Shared.Server.Capabilities;
+
+/// <summary>
+/// Tests for <see cref="CapabilityResolver"/> with various rule combinations.
+/// </summary>
+public class CapabilityResolverTests
+{
+ private const string Key = CapabilityKeys.VaultSharing;
+ private const string OtherUserId = "user-other";
+ private const string UserId = "user-1";
+ private static readonly Guid GroupId = new("11111111-1111-1111-1111-111111111111");
+ private static readonly Guid OtherGroupId = new("22222222-2222-2222-2222-222222222222");
+ private static readonly DateTime Now = new(2026, 1, 1, 12, 0, 0, DateTimeKind.Utc);
+
+ /// <summary>
+ /// With no rules at all, a gated capability is off.
+ /// </summary>
+ [Test]
+ public void NoRulesResolvesToDefaultTest()
+ {
+ Assert.That(Resolve([]), Is.EqualTo(CapabilityValue.Off));
+ }
+
+ /// <summary>
+ /// The resolved set always covers the whole registry, so a client can tell "off for you" apart from
+ /// "this server has never heard of it".
+ /// </summary>
+ [Test]
+ public void ResolveAllCoversEveryKnownCapabilityTest()
+ {
+ var result = CapabilityResolver.ResolveAll([], Subject(), Now);
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(result, Has.Count.EqualTo(CapabilityRegistry.All.Count));
+ Assert.That(result[Key], Is.EqualTo(CapabilityValue.Off));
+ });
+ }
+
+ /// <summary>
+ /// A global rule reaches everyone on the server, which is what a self-hosted admin switching one on writes.
+ /// </summary>
+ [Test]
+ public void GlobalRuleAppliesToEveryoneTest()
+ {
+ Assert.That(Resolve([Rule(CapabilityValue.On)]), Is.EqualTo(CapabilityValue.On));
+ }
+
+ /// <summary>
+ /// A rule aimed at one account reaches that account and nobody else.
+ /// </summary>
+ [Test]
+ public void UserRuleOnlyAppliesToThatUserTest()
+ {
+ var rules = new[] { Rule(CapabilityValue.On, userId: UserId) };
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(Resolve(rules), Is.EqualTo(CapabilityValue.On));
+ Assert.That(Resolve(rules, Subject(userId: OtherUserId)), Is.EqualTo(CapabilityValue.Off));
+ });
+ }
+
+ /// <summary>
+ /// A rule aimed at a group reaches its members and nobody else.
+ /// </summary>
+ [Test]
+ public void GroupRuleOnlyAppliesToMembersTest()
+ {
+ var rules = new[] { Rule(CapabilityValue.On, groupId: GroupId) };
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(Resolve(rules), Is.EqualTo(CapabilityValue.On));
+ Assert.That(Resolve(rules, Subject(groupIds: [OtherGroupId])), Is.EqualTo(CapabilityValue.Off));
+ });
+ }
+
+ /// <summary>
+ /// A per-account rule beats a group rule, which beats a tier rule, which beats a global one. This is what makes
+ /// "on for everybody except this one account" expressible.
+ /// </summary>
+ [Test]
+ public void MostSpecificScopeWinsTest()
+ {
+ var global = Rule(CapabilityValue.On);
+ var tier = Rule(CapabilityValue.Off, tier: AccountTier.Free);
+ var group = Rule(CapabilityValue.On, groupId: GroupId);
+ var user = Rule(CapabilityValue.Off, userId: UserId);
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(Resolve([global, tier]), Is.EqualTo(CapabilityValue.Off));
+ Assert.That(Resolve([global, tier, group]), Is.EqualTo(CapabilityValue.On));
+ Assert.That(Resolve([global, tier, group, user]), Is.EqualTo(CapabilityValue.Off));
+ });
+ }
+
+ /// <summary>
+ /// A tier rule only reaches the accounts on that tier.
+ /// </summary>
+ [Test]
+ public void TierRuleOnlyAppliesToThatTierTest()
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.That(Resolve([Rule(CapabilityValue.On, tier: AccountTier.Free)]), Is.EqualTo(CapabilityValue.On));
+ Assert.That(Resolve([Rule(CapabilityValue.On, tier: AccountTier.Premium)]), Is.EqualTo(CapabilityValue.Off));
+ });
+ }
+
+ /// <summary>
+ /// A disabled rule is retained for auditing but does not apply.
+ /// </summary>
+ [Test]
+ public void DisabledRuleIsIgnoredTest()
+ {
+ Assert.That(Resolve([Rule(CapabilityValue.On, enabled: false)]), Is.EqualTo(CapabilityValue.Off));
+ }
+
+ /// <summary>
+ /// A rule outside its effective window does not apply, which is how a timed beta ends without anyone deleting rows.
+ /// </summary>
+ [Test]
+ public void EffectiveWindowIsHonouredTest()
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.That(Resolve([Rule(CapabilityValue.On, from: Now.AddDays(1))]), Is.EqualTo(CapabilityValue.Off));
+ Assert.That(Resolve([Rule(CapabilityValue.On, until: Now.AddDays(-1))]), Is.EqualTo(CapabilityValue.Off));
+ Assert.That(Resolve([Rule(CapabilityValue.On, from: Now.AddDays(-1), until: Now.AddDays(1))]), Is.EqualTo(CapabilityValue.On));
+ });
+ }
+
+ /// <summary>
+ /// A client-scoped rule only reaches the client it names, so a capability can go live on one platform first.
+ /// </summary>
+ [Test]
+ public void ClientScopedRuleOnlyAppliesToThatClientTest()
+ {
+ var rules = new[] { Rule(CapabilityValue.On, clientName: "chrome") };
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(Resolve(rules, Subject(clientName: "chrome")), Is.EqualTo(CapabilityValue.On));
+ Assert.That(Resolve(rules, Subject(clientName: "ios")), Is.EqualTo(CapabilityValue.Off));
+ Assert.That(Resolve(rules, Subject(clientName: null)), Is.EqualTo(CapabilityValue.Off));
+ });
+ }
+
+ /// <summary>
+ /// Two rules of equal scope are settled by the later edit, so the answer never depends on row order.
+ /// </summary>
+ [Test]
+ public void LaterEditWinsWithinTheSameScopeTest()
+ {
+ var older = Rule(CapabilityValue.On, groupId: GroupId, updatedAt: Now.AddDays(-2));
+ var newer = Rule(CapabilityValue.Off, groupId: OtherGroupId, updatedAt: Now.AddDays(-1));
+ var subject = Subject(groupIds: [GroupId, OtherGroupId]);
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(Resolve([older, newer], subject), Is.EqualTo(CapabilityValue.Off));
+ Assert.That(Resolve([newer, older], subject), Is.EqualTo(CapabilityValue.Off));
+ });
+ }
+
+ /// <summary>
+ /// Rules for another capability never leak into this one.
+ /// </summary>
+ [Test]
+ public void OtherCapabilityRulesAreIgnoredTest()
+ {
+ Assert.That(Resolve([Rule(CapabilityValue.On, key: "some-other-capability")]), Is.EqualTo(CapabilityValue.Off));
+ }
+
+ /// <summary>
+ /// A key this build does not know resolves to an empty value, which reads as off rather than as an exception.
+ /// </summary>
+ [Test]
+ public void UnknownCapabilityKeyResolvesOffTest()
+ {
+ var resolved = CapabilityResolver.Resolve([], Subject(), "not-a-known-capability", Now);
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(resolved, Is.Empty);
+ Assert.That(CapabilityValue.IsEnabled(resolved), Is.False);
+ });
+ }
+
+ /// <summary>
+ /// Anything that is not exactly "true" leaves the capability off, so a half-written rule fails closed.
+ /// </summary>
+ [Test]
+ public void MalformedValueFailsClosedTest()
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.That(CapabilityValue.IsEnabled(Resolve([Rule("yes")])), Is.False);
+ Assert.That(CapabilityValue.IsEnabled(Resolve([Rule(string.Empty)])), Is.False);
+ Assert.That(CapabilityValue.IsEnabled(Resolve([Rule("TRUE")])), Is.True);
+ });
+ }
+
+ private static string Resolve(IEnumerable<CapabilityRule> rules, CapabilitySubject? subject = null)
+ => CapabilityResolver.Resolve(rules, subject ?? Subject(), Key, Now);
+
+ private static CapabilitySubject Subject(
+ string userId = UserId,
+ IReadOnlyCollection<Guid>? groupIds = null,
+ AccountTier tier = AccountTier.Free,
+ string? clientName = "chrome")
+ => new(userId, groupIds ?? [GroupId], tier, clientName);
+
+ private static CapabilityRule Rule(
+ string value,
+ string key = Key,
+ string? userId = null,
+ Guid? groupId = null,
+ AccountTier? tier = null,
+ bool enabled = true,
+ string? clientName = null,
+ DateTime? from = null,
+ DateTime? until = null,
+ DateTime? updatedAt = null)
+ => new()
+ {
+ Id = Guid.NewGuid(),
+ CapabilityKey = key,
+ Kind = CapabilityRuleKind.Entitlement,
+ UserId = userId,
+ GroupId = groupId,
+ Tier = tier,
+ Value = value,
+ ClientName = clientName,
+ Enabled = enabled,
+ EffectiveFrom = from,
+ EffectiveUntil = until,
+ CreatedAt = Now,
+ UpdatedAt = updatedAt ?? Now,
+ };
+}