U1 mail-foundation (frontend en documentatie): Mail-kaart bij Instellingen

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 18:22:27 +01:00
co-authored by Claude Sonnet 5.5
parent 745f0b2203
commit 2a0561a58e
15 changed files with 442 additions and 5 deletions
@@ -5,7 +5,7 @@
- **Feature Slug**: identity-email-notifications
- **Project Type**: Brownfield
- **Start Date**: 2026-11-08
- **Current Stage**: INCEPTION - design presented for approval (Workflow Planning, Application Design, Units); no code before approval
- **Current Stage**: CONSTRUCTION - U1 mail-foundation code generated and tested (local commits, not pushed); requirements and design approved by Bryan (relayed), D1 and D2 decided
- **Branch**: feature/identity-email-notifications (branched from feature/andreaslop-site-hosting at e9feb37; own branch, not merged anywhere)
- **Request Type**: Feature (Bryan chose real e-mail over a workaround button; relayed by session "CMS & API")
@@ -42,6 +42,11 @@
- [x] Workspace Detection - Complete
- [x] Requirements Analysis - P1-P5 decided by Bryan (relayed); requirements.md updated
- [~] User Stories - skipped (see execution plan)
- [x] Workflow Planning - written, approval pending
- [x] Application Design - written, approval pending (choices D1, D2)
- [x] Workflow Planning - approved (relayed)
- [x] Application Design - approved (relayed); D1 picker in invite dialog, D2 stamp in access token (U3)
- [x] Units Generation - U1 mail-foundation, U2 identity-mail-flows, U3 password-reset
### CONSTRUCTION
- [x] U1 mail-foundation - Infrastructure Design (construction/mail-foundation/infrastructure-design/infrastructure-design.md), Code Generation done, build and tests green (see code-summary.md); hand-back pending
- [ ] U2 identity-mail-flows
- [ ] U3 password-reset (includes D2: security stamp in the access token)
@@ -57,3 +57,15 @@
**Context**: Inception documents complete; approval of requirements and design pending, no code.
---
## Construction U1 - approval and code generation
**Timestamp**: 2026-11-08T20:30:00Z
**User Input**: "(Relayed by 'CMS & API', Bryan's decisions) Requirements + ontwerp identity-email-notifications: AKKOORD, begin met Code Generation van U1. D1: beheerder kiest nl/en in het uitnodigingsvenster (default sitetaal), bewaard op de uitnodiging, bij afronden overgenomen. D2: direct beeindigen: security stamp in access-token en vergelijken in de actief-controle (ook voor gewone wachtwoordwijziging); tokens van voor de deploy eenmalig geweigerd, refresh geeft stil een nieuw token. Test dit expliciet en meld het als gedragswijziging voor SLP Software. SMTP voor Infrastructure Design: Email__Smtp__Host=mail.slpsoftware.nl, Port=587, EnableSsl=true (STARTTLS). FromAddress/FromName ... no-reply@slpsoftware.nl. Let op SPF-aligned ... blijft productie-checklistpunt. ... Werk U1 op feature/identity-email-notifications, commit lokaal, geen push voordat U1 getest is; meld je na U1 met testresultaten en wat je op ASF test wilt uitrollen."
**AI Response**: "Built U1 (Core email building blocks, SiteSettings store + migration, SiteSettings API, Mail card, capabilities flags, config sections, README). Tests: Core 452, Identity 96, Availability 82, Master 57, Offerings 57, ASF config 6, frontend 333; MariaDB-backed migration up/down/up and DateTimeOffset round trip verified against a real MariaDB container; vulnerability scan clean. D2 (stamp in access tokens) belongs to U3 and is recorded in the plan."
**Context**: Construction U1, per-unit build and test done; completion message to follow via the peer session.
---
@@ -0,0 +1,28 @@
# Code summary - U1 mail-foundation
## What was built
**Core (`SlpModularCms.Core/Email`, `/SiteSettings`)**
- `IEmailSender` (`SendAsync(OutgoingMail)` returning `MailSendResult`; SimpleDeckApp-shaped extension `SendAsync(to, subject, html)`), `SmtpEmailSender` (MailKit 4.18.2: StartTls when `EnableSsl`, authenticate only with a username, connect/send bounded by `TimeoutSeconds`, every exception mapped to `timeout|auth_failed|rejected|unknown`, exception type only in the log), `NullEmailSender` (`disabled`).
- Headers are validated before connecting (`EmailAddressRules`: strict ASCII address allowlist, display name without control characters, colour `#rrggbb`); a bad value is refused with `rejected` and nothing is sent.
- `EmailOptions` (section `Email`) and `AppMailOptions` (section `App`: `PublicBaseUrl`, `DefaultLanguage`), `EmailOptionsValidator` (start-up validation, only when `Email:Smtp:Host` is set; messages never contain credentials).
- `MailTemplateRenderer` (six kinds, nl/en, one shared HTML layout with logo or site name, brand colour, button plus raw link, plain-text part; all values HTML-encoded; subject without control characters; unknown language falls back to Dutch), `LanguageResolver` (user, site default, Dutch).
- `SiteSettingsEntity` + `ISiteSettingsService`/`SiteSettingsService` (sender address only from default + `Email:AllowedFromAddresses`, name 1..80 without control characters, blank = reset to defaults, a stored address that is no longer allowed falls back to the default on use). Table `SiteSettings` (migration `AddSiteSettings`, additive, with `Down`).
- `AddCmsEmail` registration (null sender when mail is off), `SystemController` capabilities now include `EmailEnabled` and `DefaultLanguage`.
**Identity module**: `SiteSettingsController` (`GET SiteSettings/mail` AdminOnly, `PUT SiteSettings/mail` OwnerOnly; 400 with code for invalid, 409 when mail is off).
**Config**: `Email` and `App` sections (mail OFF, no credentials) in the ASF and SlpSoftware `appsettings.json`.
**Frontend**: `MailSettingsCard` on the Settings page (only when `emailEnabled`; Owner edits, Administrator read-only; select limited to allowed addresses; restore defaults), `useMailSettings`, capabilities hook reads `emailEnabled`/`defaultLanguage`, nl/en strings.
## Decisions kept from the design
No mail configuration means no behaviour change anywhere. Sending never throws into callers. Sender address is never free text. Logo and colour come from per-site config (`Email:LogoUrl`, `Email:BrandColor`).
## Tests
- Core.Tests 452: option validation (every rule, no credentials in messages), address/name rules, renderer (nl/en, fallback, encoding, role names, no link without button, invalid colour), `SmtpEmailSender` against an in-process SMTP stub (success, sender override, SimpleDeckApp-shaped call, header injection refused without connecting, timeout, nothing listening, not configured, disabled), site settings (default, allowed, rejected, reset, narrowed allowlist, mail off), registration (null/SMTP sender, start-up failure), capabilities flag.
- Property-based (PBT-03/07/08/09 partial): rendering never throws/never leaks raw markup/subject stays one line for any generated value; control characters never valid in a display name; only the allowed alphabet in addresses; sender never outside default + allowlist; token survives the link round trip (PBT-02).
- MariaDB-backed (run when `ConnectionStrings__DefaultConnection` is set, as in CI; own scratch databases): all migrations apply on MariaDB, the newest is undone and re-applied; `DateTimeOffset` round trip.
- Identity.Tests 96 (new `SiteSettingsControllerTests`: policies AdminOnly/OwnerOnly, status mapping). Frontend 333 (card: hidden when off, Owner saves, allowed options only, save disabled/empty/too-long name, reset, Administrator read-only; capabilities flags). ESLint and tsc clean. `dotnet list package --vulnerable` clean.
## Not run locally
`Api.Tests` and the ASF `HostPipelineTests` (the developer's `appsettings.local.json` overrides the connection string and points to a database that is not running); CI runs them. The new migration was verified separately on a real MariaDB (above).
@@ -0,0 +1,34 @@
# Infrastructure design - U1 mail-foundation
## Configuration keys (per environment, on the host)
| Key | Where | Example / note |
|---|---|---|
| `Email__Smtp__Host` | `shared/env` | `mail.slpsoftware.nl` (the SMTP host SimpleDeckApp uses in production, per Bryan). Setting it switches mail ON. |
| `Email__Smtp__Port` | `shared/env` | `587` |
| `Email__Smtp__EnableSsl` | `shared/env` | `true` (STARTTLS) |
| `Email__Smtp__Username`, `Email__Smtp__Password` | `shared/env` (mode 600) | secrets, never committed, never in messages or logs |
| `App__PublicBaseUrl` | `shared/env` | `https://test.andreaslop.nl` (https, no path) |
| `App__DefaultLanguage` | optional | `nl` (default) or `en` |
| `Email__FromAddress`, `Email__FromName` | committed default or env | `no-reply@slpsoftware.nl` / site name (SimpleDeckApp's committed default) |
| `Email__AllowedFromAddresses__0..n` | env | extra sender addresses a site may choose in its settings; empty = only `FromAddress` |
| `Email__LogoUrl`, `Email__BrandColor` | committed (ASF) or env | `/admin/brand-logo-on-light.png`, `#5f6a58` |
Start-up validation refuses a broken mail configuration (when a host is set) with a message that never contains the credentials. Without a host nothing changes.
## Local development
smtp4dev (already installed) on `localhost:25`: `Email__Smtp__Host=localhost`, `Email__Smtp__Port=25`, `Email__Smtp__EnableSsl=false`, no username, `App__PublicBaseUrl=http://localhost:5200` (http is accepted for loopback only).
## ASF test host (Operations will do it, needs Bryan's go for the real test mail)
1. Add the keys above to `shared/env` of `andreaslopfotografie-test` (mode 600 stays), restart the unit.
2. `Email__FromAddress` stays `no-reply@slpsoftware.nl` (the SMTP service's own domain). A sender on `@andreaslop.nl` only after the check below.
3. One real test mail to an address of Bryan before approval.
## Sender-domain alignment (production checklist item)
`From:` domain, SPF and DKIM must agree with the SMTP service that actually sends:
- SPF of the `From:` domain must authorise the sending service (today both `slpsoftware.nl` and `andreaslop.nl` publish `v=spf1 a mx include:smtp.spf.ziggo.nl ~all`).
- That service must DKIM-sign for the `From:` domain (a `dkim._domainkey` record exists for both domains; whether the service signs with it is not visible from outside).
- `mail.slpsoftware.nl` will deliver `@andreaslop.nl` mail properly only if it may send/sign for that domain. DMARC is `p=none` today (monitoring only).
- Therefore the sender list is an allowlist: add an `@andreaslop.nl` address to `Email__AllowedFromAddresses` only after this is confirmed.
## No other infrastructure
No new service, port, queue or storage. One additive table (`SiteSettings`) in the existing database.