From 0dbbbaa2079c480c221dc76a98045024fac7fc85 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 26 Nov 2026 16:41:52 +0100 Subject: [PATCH] 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. --- AGENTS.md | 30 +++++++++++- .../Common/Dto/DocumentDetailsDto.cs | 9 +++- .../EnvelopeReceiver/EnvelopeReceiverDto.cs | 9 ---- .../Common/Dto/History/HistoryCreateDto.cs | 6 ++- .../Services/EnvelopeHistoryService.cs | 2 +- EnvelopeGenerator.Domain/Entities/Document.cs | 8 +++- .../Interfaces/IDocReceiverElement.cs | 31 ++++++++++++ .../Interfaces/IDocument.cs | 29 ++++++++++++ .../EnvelopeGenerator.Server/README.md | 47 +++++++++++++++++++ 9 files changed, 155 insertions(+), 16 deletions(-) create mode 100644 EnvelopeGenerator.Domain/Interfaces/IDocument.cs diff --git a/AGENTS.md b/AGENTS.md index 438b2601..764a3eb3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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) diff --git a/EnvelopeGenerator.Application/Common/Dto/DocumentDetailsDto.cs b/EnvelopeGenerator.Application/Common/Dto/DocumentDetailsDto.cs index 5e3a6fd4..280caaa4 100644 --- a/EnvelopeGenerator.Application/Common/Dto/DocumentDetailsDto.cs +++ b/EnvelopeGenerator.Application/Common/Dto/DocumentDetailsDto.cs @@ -1,9 +1,11 @@ +using EnvelopeGenerator.Domain.Interfaces; + namespace EnvelopeGenerator.Application.Common.Dto; /// /// Data Transfer Object representing document metadata and elements without binary payload. /// -public record DocumentDetailsDto +public record DocumentDetailsDto : IDocument { /// /// Gets or sets the unique identifier of the document. @@ -24,4 +26,9 @@ public record DocumentDetailsDto /// Gets or sets the collection of elements associated with the document for receiver interactions, if any. /// public IEnumerable? Elements { get; init; } + + /// + /// + /// + public IEnumerable? ElementsBase => Elements; } diff --git a/EnvelopeGenerator.Application/Common/Dto/EnvelopeReceiver/EnvelopeReceiverDto.cs b/EnvelopeGenerator.Application/Common/Dto/EnvelopeReceiver/EnvelopeReceiverDto.cs index 86153648..2186c1a6 100644 --- a/EnvelopeGenerator.Application/Common/Dto/EnvelopeReceiver/EnvelopeReceiverDto.cs +++ b/EnvelopeGenerator.Application/Common/Dto/EnvelopeReceiver/EnvelopeReceiverDto.cs @@ -79,13 +79,4 @@ public record EnvelopeReceiverDto /// /// public bool HasPhoneNumber { get; init; } - - /// - /// Indicates whether this receiver has signed the envelope. - /// Checks if there is a DocumentSigned history entry for this receiver in the envelope's history. - /// - public bool Signed => Envelope?.Histories?.Any(h => - h.Receiver?.Id == ReceiverId && - h.Status == EnvelopeStatus.DocumentSigned - ) ?? false; } diff --git a/EnvelopeGenerator.Application/Common/Dto/History/HistoryCreateDto.cs b/EnvelopeGenerator.Application/Common/Dto/History/HistoryCreateDto.cs index 0c89802e..8a12708b 100644 --- a/EnvelopeGenerator.Application/Common/Dto/History/HistoryCreateDto.cs +++ b/EnvelopeGenerator.Application/Common/Dto/History/HistoryCreateDto.cs @@ -1,4 +1,6 @@ -namespace EnvelopeGenerator.Application.Common.Dto.History; +using EnvelopeGenerator.Domain.Constants; + +namespace EnvelopeGenerator.Application.Common.Dto.History; /// /// Data Transfer Object for creating a new envelope history record. @@ -18,7 +20,7 @@ public class HistoryCreateDto /// /// Gets or sets the status of the envelope at the time of the action. /// - public int Status { get; set; } + public EnvelopeStatus Status { get; set; } /// /// Gets or sets the date and time when the action occurred. diff --git a/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs b/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs index d76f5a6f..af2fb697 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs @@ -144,7 +144,7 @@ public class EnvelopeHistoryService : CRUDService +#if nullable + ? +#endif + ElementsBase => Elements; + [ForeignKey("EnvelopeId")] public virtual Envelope #if nullable diff --git a/EnvelopeGenerator.Domain/Interfaces/IDocReceiverElement.cs b/EnvelopeGenerator.Domain/Interfaces/IDocReceiverElement.cs index 0b0829c6..b1ef7534 100644 --- a/EnvelopeGenerator.Domain/Interfaces/IDocReceiverElement.cs +++ b/EnvelopeGenerator.Domain/Interfaces/IDocReceiverElement.cs @@ -7,5 +7,36 @@ double X { get; set; } double Y { get; set; } + + string +#if nullable + ? +# endif + FullName { get; set; } + + string +#if nullable + ? +#endif + Place { get; set; } + + byte[] +#if nullable + ? +#endif + Ink { get; set; } + } + + public static class DocReceiverElementExtensions + { + /// + /// + /// + /// + /// + public static bool IsSigned(this IDocReceiverElement element) + => element.FullName != null + && element.Place != null && + element.Ink != null; } } \ No newline at end of file diff --git a/EnvelopeGenerator.Domain/Interfaces/IDocument.cs b/EnvelopeGenerator.Domain/Interfaces/IDocument.cs new file mode 100644 index 00000000..90a5fd77 --- /dev/null +++ b/EnvelopeGenerator.Domain/Interfaces/IDocument.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; + +namespace EnvelopeGenerator.Domain.Interfaces +{ + public interface IDocument + { + IEnumerable +#if nullable + ? +#endif + ElementsBase { get; } + } + + public static class DocumentExtensions + { + public static bool IsSigned(this IDocument document) + { + if(document.ElementsBase == null) + throw new ArgumentNullException(nameof(document.ElementsBase), "Elements collection cannot be null. Please add with Includ()"); + + foreach (var element in document.ElementsBase) + if (!element.IsSigned()) + return false; + + return true; + } + } +} diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/README.md b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/README.md index f0493aa7..a564426d 100644 --- a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/README.md +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/README.md @@ -8,6 +8,7 @@ 4. [IIS-Konfiguration](#iis-konfiguration) 5. [Verzeichnisstruktur nach dem Publish](#verzeichnisstruktur-nach-dem-publish) 6. [Häufige Fehler](#häufige-fehler) +7. [E-Mail-Vorlagen (`TBSIG_EMAIL_TEMPLATE`)](#e-mail-vorlagen-tbsig_email_template) --- @@ -223,3 +224,49 @@ publish-output\ | `HTTP 500.30` + `sc-win32-status: 574` | App Pool falsch oder `AspNetCoreModuleV2` fehlt | Pool prüfen + Hosting Bundle installieren | | App startet per `.exe`, aber nicht in IIS | `web.config` hat noch `processPath="dotnet"` | `web.config` auf `.\EnvelopeGenerator.Server.exe` korrigieren | | Logs-Verzeichnis fehlt → App startet nicht | `stdoutLogEnabled="true"` aber `logs\` existiert nicht | `logs\`-Ordner anlegen + IIS_IUSRS Schreibrecht geben | + +--- + +## E-Mail-Vorlagen (`TBSIG_EMAIL_TEMPLATE`) + +Alle Benachrichtigungs-E-Mails werden zur Laufzeit aus der Tabelle `dbo.TBSIG_EMAIL_TEMPLATE` +der Datenbank `DD_ECM` geladen. Die Vorlagen sind **kein Bestandteil des Publish-Pakets**: +Sie müssen in der Zieldatenbank vorhanden sein. Fehlt eine Vorlage, wird die jeweilige Mail +nicht versendet — `EnvelopeMailService` protokolliert dann ein `DataIntegrityIssue` und +überspringt den Versand. + +Die Tabelle enthält aktuell **10 Vorlagen**, alle in `de-DE`. Aufgelöst werden sie über `NAME` +(`EmailTemplateType`), nicht über `GUID`; die GUIDs 7 und 8 sind unbenutzt. + +| GUID | `NAME` | Zweck | Empfänger | +|---|---|---|---| +| 1 | `DocumentReceived` | "[NAME_SENDER] hat Ihnen ein Dokument zum [SIGNATURE_TYPE] gesendet" + Dokumentlink, optional `[MESSAGE]` | Alle Empfänger bei der Envelope-Erstellung | +| 2 | `DocumentDeleted` | Umschlag vom Absender gelöscht/zurückgezogen, inkl. `[REASON]` | Empfänger | +| 3 | `DocumentSigned` | Bestätigung der erfolgreichen Signatur/Bestätigung (`[FINAL_STATUS]`, `[RECEIVER_ACTION]`) | Der handelnde Empfänger | +| 4 | `DocumentCompleted` | Umschlag abgeschlossen; fertiges Dokument + Ergebnisbericht im Anhang | Empfänger | +| 5 | `DocumentAccessCodeReceived` | Zugriffscode (`[DOCUMENT_ACCESS_CODE]`) zur Ansicht/Signatur | Der Empfänger | +| 6 | `DocumentRejected_ADM` | Ein Empfänger hat den Umschlag abgelehnt, inkl. `[REASON]` | Absender/ADM | +| 9 | `DocumentRejected_REC` | Bestätigung der Ablehnung; "Absender wurde informiert" | Der ablehnende Empfänger | +| 10 | `DocumentRejected_REC_2` | "Anderer Vertragspartner hat abgelehnt; Absender meldet sich bei Bedarf" | Alle übrigen Empfänger | +| 11 | `DocumentShared` | "[NAME_RECEIVER] hat Ihnen ein Dokument zum Ansehen gesendet" + Link | Neu freigegebener (Read-only) Empfänger | +| 12 | `TotpSecret` | 2FA-QR-Code (`[TFA_QR_CODE]`), gültig bis `[TFA_EXPIRATION]` | Der Empfänger (TFA-Registrierung) | + +**Wichtige Platzhalter:** `[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]`. Die Standardwerte für `[NAME_PORTAL]`, `[SIGNATURE_TYPE]` und `[REASON]` +kommen aus `MailParams:Placeholders` in `appsettings.json`; die übrigen werden beim Versand +gefüllt. + +**Hinweise:** + +- Aktiv aus diesem Repo versendet: 1, 2, 3, 5, 11. Für 4, 6, 9, 10 und 12 existieren + Notification-Payloads unter `Application/Common/Interfaces/Services/Notification/`, aber + kein `new ...Notification`-Aufruf im Repo — vermutlich übernimmt die Legacy-Form-App oder + eine DB-Automatisierung den Versand. +- Vorlagen werden zur Laufzeit über `UpdateEmailTemplateCommand` bearbeitet; die + Standardwerte für ein Reset liegen in `ResetEmailTemplateCommand`. +- Der DB-Trigger `TBSIG_EMAIL_TEMPLATE_AFT_UPD` ist über `DbTriggerParams.EmailTemplate` + registriert. +- `GUID`s nicht ändern — die Auflösung erfolgt über `NAME`, aber nachgelagerte Tools/ + Reports können auf der ID aufbauen.