Contact: ontvangstadres uit de site-instellingen (instelling > env), PUT /contact-settings/recipient en Berichten-veld (CMS-U11)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 23:54:03 +01:00
co-authored by Claude Sonnet 5.5
parent 9ff5c8bd94
commit 62f4d4dfe0
29 changed files with 1165 additions and 24 deletions
@@ -0,0 +1,6 @@
# CMS-U11 — Recipient address from the site settings (summary)
- Backend: nullable `RecipientEmail` on `ContactSettings` (migration `ContactSettingsRecipient`); `IContactSettingsService.GetEffectiveRecipientAsync` (setting > env > none) and `SetRecipientAsync` (wakes the mail sender); `ContactMailSender` reads the recipient per send (`NotReadyReasonAsync`); `GET /contact-settings` + `recipientEmail`/`recipientSource` (the env address is never returned); `PUT /contact-settings/recipient`; OpenAPI regenerated.
- Frontend: `RecipientCard` next to the form switch (field, save, back to the server setting, source text, client + server validation, translated), warning banner on the switch card while there is no address (no blocking). nl/en.
- Tests (new/changed): resolution order, invalid stored value ignored, admin view never shows the env address, set/clear, signal, sender uses the setting without a restart, no address = not ready + nothing sent, controller (valid/trimmed/blank/invalid/CRLF/too long/missing body), pipeline on the real host (login/role, view, set/invalid/clear, no leak in the public token response, a stored-but-pending message goes out after the address is set), route-table test, OpenAPI snapshot; frontend (field, save, invalid client/server, clear, banner without blocking). The existing outgoing contact mail tests keep their intent (only their construction and the async `NotReadyReasonAsync` signature were adapted).
- Decisions (approved): warn instead of block; the env address is not shown; the field sits on the Berichten page.
@@ -109,7 +109,7 @@ CMS switch (not configuration): table `ContactSettings`, `PUT /contact-settings`
Rebased onto `origin/master` `e671078` (merge of PR #11: identity-email-notifications + andreaslop-site-hosting). Conflicts: `aidlc-docs/active-features.md` (kept master's table, appended our row), `AvailabilityMiddleware` (kept their `CheckAdmin` / expired-token 401 behaviour, our marker block before it), `AddCmsRateLimiting.OnRejected` (kept their Retry-After logic for sliding windows, added the `60 s` fallback for policies without a wait and the problem+json body), `SlpModularCms.sln` (took master's, re-added the two Contact projects). No EF snapshot conflict (own contexts). Checklist steps 1 and 2 are DONE: `ContactRateLimitPartition.KeyFor` now returns `ClientPartitionKey.For(context)` and its test asserts different buckets per address. Still open: step 3 (`ForwardedHeaders:KnownProxies` per host), step 5 (`Contact:Enabled=true`), step 6 (CMS switch). `GET /System/capabilities` now carries `[PublicSiteEndpoint]` (never 503; separate commit). The pipeline tests for the management routes log in with a real user (the host validates every access token against its user and security stamp).
## 7. CMS-U5 additions (contact mail)
- Env var `Contact__RecipientEmail` (SLP: environment only, like ASF). Optional `Contact__Mail__SweepSeconds|MaxAttempts|ClaimMinutes|BatchSize`, `Contact__Mail__BackoffMinutes__0..n`.
- Recipient address: since CMS-U11 the **site setting wins over** the env var `Contact__RecipientEmail` (see section 9); the env var stays the default/fallback (SLP: environment only, like ASF). Optional `Contact__Mail__SweepSeconds|MaxAttempts|ClaimMinutes|BatchSize`, `Contact__Mail__BackoffMinutes__0..n`.
- Mail itself needs the host's normal `Email:*` configuration; without it messages stay `pending` with `mailError: "disabled"`.
- Detail: `nextMailAttemptAt`; resend: `mailError`. New migration `ContactMailClaim`.
@@ -144,3 +144,15 @@ With `Contact:Enabled=true` and `Captcha:Enabled=true` the host **refuses to sta
- References `Modules.Contact`; section `Contact` in its `appsettings.json` (`Enabled:false`, `SiteId: andreaslop`), the three contact rate-limit policies. Capabilities now list `Contact`; the module does nothing and touches no database while `Contact:Enabled=false`.
- Release conditions (also in the comment of that section): `ForwardedHeaders__KnownProxies__0` = reverse proxy (IIS) address first (otherwise the whole site shares one bucket); `Contact__RecipientEmail` (env only); mail via `Email__Smtp__*`, `App__PublicBaseUrl`; sender = `Email:FromAddress` or the address chosen in the site settings from `Email:AllowedFromAddresses` (set by environment for ASF); captcha settings above; then `Contact__Enabled=true` and the admin switch (Berichten).
- Host tests (`Api.AndreaSlopFotografie.Tests/ContactHostTests.cs`, real MariaDB): closed by default; public routes stay reachable (200/202) while the availability gate is "not available" and the management routes answer 503; per-client buckets with a known proxy vs one shared bucket without.
## 9. CMS-U11 additions (recipient address from the site settings)
Order of precedence for the address contact mails are sent to: **site setting (CMS admin, Berichten) > `Contact__RecipientEmail` (environment) > none.** The setting changes without a restart (read on every send); an invalid stored value is ignored (falls back). Table `ContactSettings` gets a nullable `RecipientEmail` (migration `ContactSettingsRecipient`, additive).
| Method + path | Auth | Notes |
|---|---|---|
| `GET /contact-settings` | AdminOnly | now `{ enabled, hostEnabled, recipientEmail: string\|null, recipientSource: "setting"\|"config"\|"none" }`. `recipientEmail` is only the CMS setting; **the address from the environment is never returned** (source `config` = "set by the server configuration"). |
| `PUT /contact-settings/recipient` `{ "recipientEmail": string\|null }` | AdminOnly | `200` same shape as GET; `null`/blank clears the setting (back to the environment default); trimmed; `EmailAddressRules`; `400` problem+json `errors.recipientEmail = ["invalid"]` or `["tooLong"]` (> 254), never echoing the value; `401/403/404/503` as the other management routes. Not part of any public route or OpenAPI example. |
| `PUT /contact-settings` `{ enabled }` | AdminOnly | unchanged. |
Without any address (`recipientSource: "none"`) the host still starts and the form can still be switched on (warn, not block): messages are stored, the mail stays `pending` with `mailError: "recipient_not_configured"` (not counted as an attempt) and goes out by itself within seconds once an address is set (setting the address wakes the mail sender). The admin shows a warning banner on the switch card. Release condition for SLP/ASF: the address no longer has to be in the environment when it is set in the admin.