Chat invites: an operator-minted single-use link decides who may chat; an uninvited account gets no chat token (#89)

This commit is contained in:
Eureka 2026-11-27 21:15:47 +00:00
commit 5d9fc14598
28 changed files with 1286 additions and 184 deletions

View file

@ -414,6 +414,7 @@ public sealed class OidcLogoutFactory : OidcWebApplicationFactory
}
await SetMembershipAsync(identity, MembershipStatus.Active);
await SetInvitedAsync(identity, true);
if (suspensionReason is not null)
{
using var scope = Services.CreateScope();

View file

@ -276,6 +276,36 @@ public class OidcWebApplicationFactory : TestWebApplicationFactory
}
}
/// <summary>Marks the account as holding a redeemed chat invite (or clears it), as a redemption or a revoked grant would leave it.</summary>
public async Task SetInvitedAsync(string identity, bool invited)
{
using var scope = Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<BifrostDbContext>();
db.UserAccounts.Single(x => x.NormalizedBifrostIdentity == identity).ChatInvitedAtUtc = invited ? DateTimeOffset.UtcNow : null;
await db.SaveChangesAsync();
}
/// <summary>Mints a chat invite through the one service and returns its token.</summary>
public async Task<string> MintInviteAsync(string note = "test")
{
using var scope = Services.CreateScope();
var (_, token) = await scope.ServiceProvider.GetRequiredService<Bifrost.Web.Features.Invites.ChatInviteService>().MintAsync(Guid.NewGuid(), note, CancellationToken.None);
return token;
}
public async Task<ChatInvite> InviteRowAsync(string token)
{
using var scope = Services.CreateScope();
var hash = Bifrost.Web.Features.Invites.ChatInviteService.Hash(token);
return await scope.ServiceProvider.GetRequiredService<BifrostDbContext>().ChatInvites.AsNoTracking().SingleAsync(x => x.TokenHash == hash);
}
public async Task<DateTimeOffset?> InvitedAtAsync(string identity)
{
using var scope = Services.CreateScope();
return (await scope.ServiceProvider.GetRequiredService<BifrostDbContext>().UserAccounts.AsNoTracking().SingleAsync(x => x.NormalizedBifrostIdentity == identity)).ChatInvitedAtUtc;
}
public Guid AccountId(string identity)
{
using var scope = Services.CreateScope();