S-09b: Approval flow — temp admin endpoint + status transition to projection (#77)
All checks were successful
All checks were successful
## What & why S-09b (#75, split from #10) — the **approval flow** that completes the walking skeleton. A behandelaar can now approve a submitted registration; the entry flips from `INGEDIEND` to `INGESCHREVEN` in the public register. Flow: `POST /registrations/{id}/approve` (domain) → ACL sets the zaak eindstatus (ZGW `/statussen`) → OpenZaak → NRC → event-subscriber → projection → openbaar. ## Changes (bottom-up, each red→green TDD) - **Domain** — `RegistrationStatus.Ingeschreven` + `Registration.Approve()` (guards: opened zaak, only from INGEDIEND); `ApproveRegistration` use case (idempotent) + temp `POST /registrations/{id}/approve` endpoint; `IAclClient.ApproveZaakAsync`. - **ACL** — resolves the zaaktype's **eindstatus** from the catalogus (`isEindstatus` / highest volgnummer) and POSTs a ZGW status; exposed as `POST /statussen`. Unit + real-OpenZaak integration test. - **Event-subscriber** — binds NRC `hoofdObject`, projects a `status`/`create` as `INGESCHREVEN` keyed on the zaak (updates the existing row), **without reading OpenZaak** (§8.1). Retains the ZGW `resource` in the log (new column + EF migration) so a rebuild reproduces the status. - **e2e** — extended: submit → public INGEDIEND → approve → public INGESCHREVEN. - **Docs** — ADR-0011 (the two non-obvious decisions + the walking-skeleton assumption) + demo note. ## Key decisions (see ADR-0011) - **ACL discovers the eindstatus** (chosen over injecting a statustype URL): no new config/seed plumbing, domain stays ZGW-ignorant. - **Any post-creation status-set ⇒ INGESCHREVEN**: in the walking skeleton the only status ever set after creation is the approval, and the subscriber may not read ZGW — documented to tighten when more transitions arrive (S-12+). ## Verification - All .NET unit suites green locally (domain 47, acl 11, event-subscriber 14, bff 16, acceptance 7); Release build + `dotnet format` clean. - No new compose config (the eindstatus-discovery approach avoided it). - The real-OpenZaak integration test (ACL status-set) and the full submit→approve→visible e2e run in CI `verify-stack` (live NRC→projection + selectielijst egress, not reproducible locally). closes #75 Reviewed-on: #77
This commit was merged in pull request #77.
This commit is contained in:
@@ -19,12 +19,46 @@ public static class ServiceCollectionExtensions
|
||||
return services;
|
||||
}
|
||||
|
||||
// A fixed application-scoped key for the migration advisory lock (any stable 64-bit constant).
|
||||
private const long MigrationAdvisoryLockKey = 727501;
|
||||
|
||||
/// <summary>Apply any pending EF migrations. Called once on service start so a fresh stack
|
||||
/// reaches a usable schema without a manual migration step (DoD: compose up reaches green).</summary>
|
||||
/// reaches a usable schema without a manual migration step (DoD: compose up reaches green).
|
||||
///
|
||||
/// The Event Subscriber and the projection-api share this DB and both migrate on start. EF's
|
||||
/// migrations-history lock is released between individual migrations, so with more than one pending
|
||||
/// migration two migrators can interleave and one re-applies a migration the other just did
|
||||
/// ("column already exists"). Hold a Postgres session <c>pg_advisory_lock</c> across the whole
|
||||
/// sequence so it runs exactly once; the second migrator then finds nothing pending.</summary>
|
||||
public static async Task MigrateProjectionAsync(this IServiceProvider services, CancellationToken ct = default)
|
||||
{
|
||||
await using var scope = services.CreateAsyncScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<ProjectionDbContext>();
|
||||
await db.Database.MigrateAsync(ct);
|
||||
var connection = db.Database.GetDbConnection();
|
||||
|
||||
await connection.OpenAsync(ct);
|
||||
try
|
||||
{
|
||||
await ExecuteAsync(connection, $"SELECT pg_advisory_lock({MigrationAdvisoryLockKey})", ct);
|
||||
try
|
||||
{
|
||||
await db.Database.MigrateAsync(ct);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await ExecuteAsync(connection, $"SELECT pg_advisory_unlock({MigrationAdvisoryLockKey})", ct);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task ExecuteAsync(System.Data.Common.DbConnection connection, string sql, CancellationToken ct)
|
||||
{
|
||||
await using var command = connection.CreateCommand();
|
||||
command.CommandText = sql;
|
||||
await command.ExecuteNonQueryAsync(ct);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user