Add email template support and improve type safety

Updated documentation to include details on the `TBSIG_EMAIL_TEMPLATE` table, its structure, and runtime behavior. Enhanced code by introducing the `IDocument` interface and adding properties/methods to support email templates and document signing workflows. Replaced `int` with the `EnvelopeStatus` enum for improved type safety. Removed unused `Signed` property from `EnvelopeReceiverDto`. Added extension methods for `IDocument` and `IDocReceiverElement` to verify signing status. Updated deployment and troubleshooting guides to highlight email template requirements.
This commit is contained in:
2026-11-26 16:41:52 +01:00
parent 8cd4a1b888
commit 0dbbbaa207
9 changed files with 155 additions and 16 deletions

View File

@@ -13,7 +13,7 @@ This section explains every markdown file in the repo: what it contains, why it
### Core Architecture Docs (Active — Always Relevant)
#### `AGENTS.md` ← you are here
**What:** Authoritative agent/copilot onboarding guide. Covers project structure, route table, render mode rules, coordinate system, API gaps, and common mistakes.
**What:** Authoritative agent/copilot onboarding guide. Covers project structure, route table, render mode rules, coordinate system, API gaps, database/email-template reference, and common mistakes.
**Why it exists:** Single source of truth for agents so they don't re-derive architecture from code on every session.
**When you need it:** Always. Read first on every session.
**Maintenance:** Update whenever project structure, routes, render modes, or naming conventions change.
@@ -63,7 +63,7 @@ This section explains every markdown file in the repo: what it contains, why it
### Deployment Docs
#### `EnvelopeGenerator.Server/EnvelopeGenerator.Server/README.md`
**What:** IIS publish and deployment guide for `EnvelopeGenerator.Server`. Covers why self-contained publish is required (WASM assembly version strictness), the exact `dotnet publish` command, IIS Application Pool settings (`No Managed Code`), directory structure after publish, and common deployment errors.
**What:** IIS publish and deployment guide for `EnvelopeGenerator.Server`. Covers why self-contained publish is required (WASM assembly version strictness), the exact `dotnet publish` command, IIS Application Pool settings (`No Managed Code`), directory structure after publish, common deployment errors, and the email-template table (`TBSIG_EMAIL_TEMPLATE`) that must exist in the target DB.
**Why it exists:** Blazor Auto (Server + WASM hybrid) has non-obvious deployment requirements that differ from a standard ASP.NET Core app. Forgetting self-contained publish or using the wrong app pool will break WASM loading in production.
**When you need it:**
- Deploying to IIS for the first time
@@ -309,6 +309,32 @@ Manual testing workflow:
- `TBSIG_RECEIVER` - Receiver registry
- `TBSIG_ENVELOPE_DOCUMENT` - PDF binary data
- `TBSIG_ENVELOPE_HISTORY` - Audit trail
- `TBSIG_EMAIL_TEMPLATE` - Notification mail templates (HTML, `de-DE`, placeholder tokens)
### Email Templates (`TBSIG_EMAIL_TEMPLATE`)
All notification mails are rendered from `dbo.TBSIG_EMAIL_TEMPLATE` (`GUID`, `NAME`, `SUBJECT`, `BODY`, `LANG_CODE`, `ADDED_WHEN`, `CHANGED_WHEN`). Current data: 10 rows, all `de-DE`, HTML bodies sharing one layout (600px card, gradient header, `[NAME_PORTAL]` branding). Templates are resolved by `NAME` (`EmailTemplateType`), never by `GUID`; GUIDs 7 and 8 are unused.
| GUID | `NAME` | Purpose | Recipient |
|---|---|---|---|
| 1 | `DocumentReceived` | "[NAME_SENDER] sent you a document to [SIGNATURE_TYPE]" + document link, optional `[MESSAGE]` | Every receiver on envelope creation (`CreateEnvelopeCommandHandler`) |
| 2 | `DocumentDeleted` | Envelope deleted/withdrawn by sender, includes `[REASON]` | Receivers (`EnvelopeDeletedNotification`) |
| 3 | `DocumentSigned` | Confirms successful signing/confirmation (`[FINAL_STATUS]`, `[RECEIVER_ACTION]`) | The acting receiver (`SendSignedMailBehavior`, `FinalizeEnvelopeCommand`) |
| 4 | `DocumentCompleted` | Envelope completed; finished document + result report attached | Receivers (payload exists, no active dispatch in repo) |
| 5 | `DocumentAccessCodeReceived` | Access code (`[DOCUMENT_ACCESS_CODE]`) for viewing/signing | The receiver (`SendAccessCodeCommand`) |
| 6 | `DocumentRejected_ADM` | A receiver rejected the envelope, includes `[REASON]` | Sender/ADM |
| 9 | `DocumentRejected_REC` | Confirms the rejection; "sender was informed" | The rejecting receiver |
| 10 | `DocumentRejected_REC_2` | "Another party rejected; sender will contact you if needed" | All other receivers |
| 11 | `DocumentShared` | "[NAME_RECEIVER] shared a document for viewing" + link | The newly shared (read-only) recipient (`ReadOnlyController`) |
| 12 | `TotpSecret` | 2FA QR code (`[TFA_QR_CODE]`), valid until `[TFA_EXPIRATION]` | The receiver (TFA registration, `TfaRegistrationController`) |
**Key placeholders:** `[NAME_PORTAL]`, `[NAME_SENDER]`, `[NAME_RECEIVER]`, `[DOCUMENT_TITLE]`, `[LINK_TO_DOCUMENT]`, `[REASON]`, `[SIGNATURE_TYPE]`, `[FINAL_STATUS]`, `[FINAL_ACTION]`, `[DOCUMENT_ACCESS_CODE]`, `[TFA_QR_CODE]`, `[TFA_EXPIRATION]`. Defaults for `[NAME_PORTAL]`, `[SIGNATURE_TYPE]` and `[REASON]` come from `MailParams:Placeholders` in `appsettings.json`; the rest are filled at send time (`EnvelopeMailService` / notification payloads).
**Notes:**
- Actively dispatched in this repo: 1, 2, 3, 5, 11. Templates 4, 6, 9, 10, 12 have notification payloads in `Application/Common/Interfaces/Services/Notification/` but no in-repo `new ...Notification` call — assume the legacy Form app or DB-side automation dispatches them.
- Templates are runtime data, not code: they must exist in the target DB. A missing template makes `EnvelopeMailService` log a `DataIntegrityIssue` and skip the mail.
- Edit via `UpdateEmailTemplateCommand`; reset-to-default values live in `ResetEmailTemplateCommand`. DB trigger `TBSIG_EMAIL_TEMPLATE_AFT_UPD` is registered through `DbTriggerParams.EmailTemplate`.
- Do not change `GUID`s — lookup is by `NAME`, but downstream tooling/reporting may key on the ID.
### Data Structure (Domain + EGDbContext)