## What & why S-10b: the self-service **diploma upload** is now real. After submitting, the citizen picks a PDF and uploads it; the portal base64-encodes it client-side → BFF → domain → **ACL**, which stores it in the ZGW **Documenten (DRC) API** as an `enkelvoudiginformatieobject` and relates it to the zaak, then the `WachtOpDocumenten` wait completes and the case advances to beoordeling. Per §8.1 only the ACL talks to ZGW. Closes #103 Mechanism in **ADR-0018** (proposal #107). Builds on S-10a (#102). The zaak-close-on-expiry item is carved to **#106 (S-10c)**. ## Definition of Done - [x] Linked Gitea issue (above). - [x] Failing test committed before the implementation (red→green per layer). - [x] Conventional Commits referencing the issue (`refs #103`). - [ ] CI green — all Gitea Actions jobs (pending on this PR). - [x] `docker compose up` health unaffected (ACL boots on a placeholder informatieobjecttype URL; the real one is injected by verify-domain). - [x] Docs updated (ADR-0018, demo-script, BACKLOG + S-10c). - [x] ADR added (`docs/architecture/adr-0018-diploma-upload-via-acl-documenten.md`). - [x] Demo note in `docs/demo-script.md`. ## Notes for reviewers - **ACL** (`OpenZaakGateway.StoreDocumentAsync` + `AclService.StoreDiplomaAsync` + `POST /documenten`) reuses the existing gateway patterns (ZGW Bearer, buffered non-chunked body, **no CRS** — Documenten isn't geo). Unit-tested via the stub handler; an **integration test** stores a real document against live OpenZaak (verify-acl). - **Transport:** base64 JSON on every hop (portal encodes client-side) — I deviated from proposal #107's multipart to keep one contract shape and avoid `IFormFile`/antiforgery/multipart-client plumbing; fine at diploma size (ADR-0018 §Alternatives). - **Infra:** `seed_catalogus.py` seeds + publishes a "Diploma" `informatieobjecttype` and relates it to the zaaktype (while both concept); `verify-domain` injects its URL into the ACL. No new ZGW scopes (seed applicatie has `heeft_alle_autorisaties`). - **e2e:** uploads a real PDF (`setInputFiles`) after the openbaar INGEDIEND row confirms the zaak is open (so storage doesn't race the OpenZaak worker). - **Scope boundary:** the ZGW zaak is not set to a cancellation status on 30-day expiry — that's #106 (S-10c). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed-on: #108
This commit was merged in pull request #108.
This commit is contained in:
@@ -120,8 +120,17 @@ app.MapPost("/registrations/{id}/documents", async (string id, ProvideDocumentsR
|
||||
|
||||
if (string.IsNullOrWhiteSpace(body?.Bsn))
|
||||
return Results.BadRequest(new { error = "A bsn is required to provide documents." });
|
||||
if (string.IsNullOrWhiteSpace(body.ContentBase64))
|
||||
return Results.BadRequest(new { error = "A document is required." });
|
||||
|
||||
var outcome = await provide.HandleAsync(new ProvideDocumentsCommand(new RegistrationId(guid), body.Bsn), ct);
|
||||
byte[] content;
|
||||
try { content = Convert.FromBase64String(body.ContentBase64); }
|
||||
catch (FormatException) { return Results.BadRequest(new { error = "The document content is not valid base64." }); }
|
||||
|
||||
var command = new ProvideDocumentsCommand(
|
||||
new RegistrationId(guid), body.Bsn, content,
|
||||
body.FileName ?? "diploma.pdf", body.ContentType ?? "application/pdf");
|
||||
var outcome = await provide.HandleAsync(command, ct);
|
||||
return outcome == ProvideDocumentsOutcome.Accepted ? Results.NoContent() : Results.NotFound();
|
||||
});
|
||||
|
||||
@@ -152,7 +161,7 @@ public sealed record DecideRequest(string Besluit);
|
||||
|
||||
public sealed record WithdrawRequest(string Bsn);
|
||||
|
||||
public sealed record ProvideDocumentsRequest(string Bsn);
|
||||
public sealed record ProvideDocumentsRequest(string Bsn, string ContentBase64, string? FileName = null, string? ContentType = null);
|
||||
|
||||
public sealed record RegistrationResponse(string RegistrationId, string Status, string? ZaakUrl);
|
||||
|
||||
|
||||
@@ -52,6 +52,13 @@ public interface IAclClient
|
||||
/// the zaak's final status — which OpenZaak notifies over NRC; the domain never names statustypen.
|
||||
/// </summary>
|
||||
Task ApproveZaakAsync(Uri zaakUrl, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Store an uploaded diploma against the zaak (S-10b). The domain hands over the zaak, the raw file
|
||||
/// bytes, and the file's name/type; the ACL creates the ZGW informatieobject and relates it to the
|
||||
/// zaak (§8.1). Returns the stored document's URL.
|
||||
/// </summary>
|
||||
Task<Uri> StoreDiplomaAsync(Uri zaakUrl, byte[] content, string fileName, string contentType, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,10 +2,12 @@ using Big.Domain;
|
||||
|
||||
namespace Big.Application;
|
||||
|
||||
/// <summary>A zorgprofessional's signal that they have supplied the documents their registration is
|
||||
/// waiting for ("documenten aanleveren"). <paramref name="Bsn"/> is the authenticated caller (from the
|
||||
/// DigiD token, forwarded by the BFF): only the registration's own bsn may provide its documents.</summary>
|
||||
public sealed record ProvideDocumentsCommand(RegistrationId RegistrationId, string Bsn);
|
||||
/// <summary>A zorgprofessional's upload of the diploma their registration is waiting for ("documenten
|
||||
/// aanleveren"). <paramref name="Bsn"/> is the authenticated caller (from the DigiD token, forwarded by
|
||||
/// the BFF): only the registration's own bsn may provide its documents. <paramref name="Content"/> is
|
||||
/// the raw file, with its <paramref name="FileName"/> and <paramref name="ContentType"/>.</summary>
|
||||
public sealed record ProvideDocumentsCommand(
|
||||
RegistrationId RegistrationId, string Bsn, byte[] Content, string FileName, string ContentType);
|
||||
|
||||
/// <summary>The outcome of a provide-documents request.</summary>
|
||||
public enum ProvideDocumentsOutcome
|
||||
@@ -19,14 +21,14 @@ public enum ProvideDocumentsOutcome
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The provide-documents use case (S-10a): a zorgprofessional supplies the documents their registration
|
||||
/// is parked waiting for, completing the WachtOpDocumenten task so the registratie process leaves the
|
||||
/// 30-day wait and continues to beoordeling (ADR-0017). Owner-scoped by bsn. Completing the wait is
|
||||
/// best-effort: if the registration never started a process (or already left the wait), the request
|
||||
/// still stands, mirroring how <see cref="WithdrawRegistration"/> cancels best-effort. The actual file
|
||||
/// upload and its ZGW storage via the ACL is S-10b; this is the trigger that unblocks the process.
|
||||
/// The provide-documents use case (S-10a/S-10b): a zorgprofessional uploads the diploma their
|
||||
/// registration is parked waiting for. The document is stored in ZGW via the ACL (§8.1), then the
|
||||
/// WachtOpDocumenten task is completed so the registratie process leaves the 30-day wait and continues
|
||||
/// to beoordeling (ADR-0017). Owner-scoped by bsn. Both steps are best-effort about missing preconditions
|
||||
/// (mirroring <see cref="WithdrawRegistration"/>): storage needs an opened zaak, and completion needs a
|
||||
/// running process — a request that arrives before either still stands, storing/completing what it can.
|
||||
/// </summary>
|
||||
public sealed class ProvideDocuments(IRegistrationStore store, IWorkflowClient workflow)
|
||||
public sealed class ProvideDocuments(IRegistrationStore store, IWorkflowClient workflow, IAclClient acl)
|
||||
{
|
||||
public async Task<ProvideDocumentsOutcome> HandleAsync(ProvideDocumentsCommand command, CancellationToken ct = default)
|
||||
{
|
||||
@@ -38,6 +40,11 @@ public sealed class ProvideDocuments(IRegistrationStore store, IWorkflowClient w
|
||||
if (registration is null || registration.Bsn != command.Bsn)
|
||||
return ProvideDocumentsOutcome.NotFound;
|
||||
|
||||
// Store the diploma against the zaak (once it is opened) — the ACL is the only ZGW caller (§8.1).
|
||||
if (registration.ZaakUrl is not null)
|
||||
await acl.StoreDiplomaAsync(
|
||||
registration.ZaakUrl, command.Content, command.FileName, command.ContentType, ct);
|
||||
|
||||
// Complete the document wait (if a process is running) so beoordeling can proceed.
|
||||
if (registration.ProcessInstanceId is not null)
|
||||
await workflow.CompleteDocumentWaitAsync(registration.ProcessInstanceId, ct);
|
||||
|
||||
@@ -31,6 +31,23 @@ public sealed class AclHttpClient(HttpClient http, AclOptions options) : IAclCli
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public async Task<Uri> StoreDiplomaAsync(Uri zaakUrl, byte[] content, string fileName, string contentType, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(zaakUrl);
|
||||
ArgumentNullException.ThrowIfNull(content);
|
||||
|
||||
// The file crosses this boundary base64-encoded in JSON — the domain and ACL contracts are
|
||||
// JSON, and a diploma is small (S-10b, ADR). The ACL turns it into a ZGW informatieobject.
|
||||
using var response = await http.PostAsJsonAsync(
|
||||
new Uri(options.BaseUrl, "documenten"),
|
||||
new StoreDocumentRequest(zaakUrl.ToString(), Convert.ToBase64String(content), fileName, contentType), ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stored = await response.Content.ReadFromJsonAsync<StoreDocumentResponse>(ct)
|
||||
?? throw new InvalidOperationException("The ACL returned an empty document response.");
|
||||
return new Uri(stored.InformatieobjectUrl);
|
||||
}
|
||||
|
||||
private sealed record OpenZaakRequest(
|
||||
[property: JsonPropertyName("bsn")] string Bsn,
|
||||
[property: JsonPropertyName("reference")] string Reference);
|
||||
@@ -38,4 +55,13 @@ public sealed class AclHttpClient(HttpClient http, AclOptions options) : IAclCli
|
||||
private sealed record OpenZaakResponse([property: JsonPropertyName("zaakUrl")] string ZaakUrl);
|
||||
|
||||
private sealed record SetStatusRequest([property: JsonPropertyName("zaakUrl")] string ZaakUrl);
|
||||
|
||||
private sealed record StoreDocumentRequest(
|
||||
[property: JsonPropertyName("zaakUrl")] string ZaakUrl,
|
||||
[property: JsonPropertyName("contentBase64")] string ContentBase64,
|
||||
[property: JsonPropertyName("fileName")] string FileName,
|
||||
[property: JsonPropertyName("contentType")] string ContentType);
|
||||
|
||||
private sealed record StoreDocumentResponse(
|
||||
[property: JsonPropertyName("informatieobjectUrl")] string InformatieobjectUrl);
|
||||
}
|
||||
|
||||
@@ -110,4 +110,13 @@ internal sealed class FakeAclClient(Uri? zaakUrl = null) : IAclClient
|
||||
ApprovedZaakUrl = zaakUrl;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public (Uri ZaakUrl, byte[] Content, string FileName, string ContentType)? StoredDiploma { get; private set; }
|
||||
public static readonly Uri DefaultDocumentUrl = new("http://openzaak/documenten/api/v1/enkelvoudiginformatieobjecten/doc");
|
||||
|
||||
public Task<Uri> StoreDiplomaAsync(Uri zaakUrl, byte[] content, string fileName, string contentType, CancellationToken ct = default)
|
||||
{
|
||||
StoredDiploma = (zaakUrl, content, fileName, contentType);
|
||||
return Task.FromResult(DefaultDocumentUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,52 +3,60 @@ using Big.Domain;
|
||||
|
||||
namespace Big.Tests;
|
||||
|
||||
// S-10a (#102): the "documents received" use case. A zorgprofessional supplies the documents their
|
||||
// registration is waiting for; the handler completes the WachtOpDocumenten task via the Workflow Client
|
||||
// so the process leaves the 30-day wait and continues to beoordeling. Owner-scoped by the caller's bsn,
|
||||
// like WithdrawRegistration. (The real file upload + ZGW storage is S-10b; this is the trigger path.)
|
||||
// S-10a/S-10b (#102/#103): the "documents received" use case. A zorgprofessional supplies the diploma
|
||||
// their registration is waiting for; the handler stores it in ZGW via the ACL and completes the
|
||||
// WachtOpDocumenten task via the Workflow Client so the process continues to beoordeling. Owner-scoped
|
||||
// by the caller's bsn, like WithdrawRegistration.
|
||||
public class ProvideDocumentsTests
|
||||
{
|
||||
private const string Bsn = "123456782";
|
||||
private static readonly Uri Zaak = new("http://openzaak/zaken/api/v1/zaken/abc");
|
||||
|
||||
private static Registration Submitted(string processInstanceId = "proc-1")
|
||||
{
|
||||
var registration = Registration.Submit(Bsn);
|
||||
registration.RecordProcessStarted(processInstanceId);
|
||||
registration.AttachZaak(Zaak);
|
||||
return registration;
|
||||
}
|
||||
|
||||
private static ProvideDocumentsCommand Command(RegistrationId id, string bsn = Bsn) => new(id, bsn);
|
||||
private static ProvideDocumentsCommand Command(RegistrationId id, string bsn = Bsn) =>
|
||||
new(id, bsn, [1, 2, 3], "diploma.pdf", "application/pdf");
|
||||
|
||||
[Fact]
|
||||
public async Task Providing_documents_completes_the_document_wait()
|
||||
public async Task Providing_documents_stores_the_diploma_and_completes_the_wait()
|
||||
{
|
||||
var store = new FakeRegistrationStore();
|
||||
var registration = Submitted("proc-42");
|
||||
store.Seed(registration);
|
||||
var workflow = new FakeWorkflowClient();
|
||||
var handler = new ProvideDocuments(store, workflow);
|
||||
var acl = new FakeAclClient();
|
||||
var handler = new ProvideDocuments(store, workflow, acl);
|
||||
|
||||
var outcome = await handler.HandleAsync(Command(registration.Id));
|
||||
|
||||
Assert.Equal(ProvideDocumentsOutcome.Accepted, outcome);
|
||||
// Stored against the registration's zaak, carrying the uploaded bytes + file metadata.
|
||||
Assert.Equal((Zaak, new byte[] { 1, 2, 3 }, "diploma.pdf", "application/pdf"), acl.StoredDiploma);
|
||||
// …and the wait is completed so beoordeling can proceed.
|
||||
Assert.Equal("proc-42", workflow.CompletedDocumentWaitFor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_different_bsn_cannot_provide_documents()
|
||||
{
|
||||
// Owner-scoping: only the registration's own bsn may supply its documents. Another bsn is told
|
||||
// NotFound (existence not revealed) and the wait is not completed.
|
||||
// Owner-scoping: another bsn is told NotFound; nothing is stored or completed.
|
||||
var store = new FakeRegistrationStore();
|
||||
var registration = Submitted();
|
||||
store.Seed(registration);
|
||||
var workflow = new FakeWorkflowClient();
|
||||
var handler = new ProvideDocuments(store, workflow);
|
||||
var acl = new FakeAclClient();
|
||||
var handler = new ProvideDocuments(store, workflow, acl);
|
||||
|
||||
var outcome = await handler.HandleAsync(Command(registration.Id, bsn: "999999990"));
|
||||
|
||||
Assert.Equal(ProvideDocumentsOutcome.NotFound, outcome);
|
||||
Assert.Null(acl.StoredDiploma);
|
||||
Assert.Null(workflow.CompletedDocumentWaitFor);
|
||||
}
|
||||
|
||||
@@ -56,30 +64,33 @@ public class ProvideDocumentsTests
|
||||
public async Task Providing_for_an_unknown_registration_is_not_found()
|
||||
{
|
||||
var store = new FakeRegistrationStore();
|
||||
var handler = new ProvideDocuments(store, new FakeWorkflowClient());
|
||||
var handler = new ProvideDocuments(store, new FakeWorkflowClient(), new FakeAclClient());
|
||||
|
||||
Assert.Equal(ProvideDocumentsOutcome.NotFound, await handler.HandleAsync(Command(RegistrationId.New())));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Providing_before_a_process_started_is_accepted_without_calling_the_workflow()
|
||||
public async Task Providing_before_a_zaak_is_opened_does_not_store_but_still_completes_the_wait()
|
||||
{
|
||||
// No process yet → no wait task to complete; the request still stands (best-effort, mirroring
|
||||
// WithdrawRegistration) and the Workflow Client is not called.
|
||||
// No zaak yet → nothing to file the document against, but the request still stands (best-effort,
|
||||
// mirroring WithdrawRegistration). The wait is completed if a process is running.
|
||||
var store = new FakeRegistrationStore();
|
||||
var registration = Registration.Submit(Bsn); // no RecordProcessStarted
|
||||
var registration = Registration.Submit(Bsn);
|
||||
registration.RecordProcessStarted("proc-9"); // process started, but no zaak attached
|
||||
store.Seed(registration);
|
||||
var workflow = new FakeWorkflowClient();
|
||||
var handler = new ProvideDocuments(store, workflow);
|
||||
var acl = new FakeAclClient();
|
||||
var handler = new ProvideDocuments(store, workflow, acl);
|
||||
|
||||
var outcome = await handler.HandleAsync(Command(registration.Id));
|
||||
|
||||
Assert.Equal(ProvideDocumentsOutcome.Accepted, outcome);
|
||||
Assert.Null(workflow.CompletedDocumentWaitFor);
|
||||
Assert.Null(acl.StoredDiploma);
|
||||
Assert.Equal("proc-9", workflow.CompletedDocumentWaitFor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Rejects_a_null_command()
|
||||
=> await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
new ProvideDocuments(new FakeRegistrationStore(), new FakeWorkflowClient()).HandleAsync(null!));
|
||||
new ProvideDocuments(new FakeRegistrationStore(), new FakeWorkflowClient(), new FakeAclClient()).HandleAsync(null!));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user