Skip to content

[#13635] Migrate NEW_INSTRUCTOR_ACCOUNT_WELCOME to dynamic DB template (POC)#13636

Draft
WeeJean wants to merge 4 commits intoTEAMMATES:masterfrom
WeeJean:email-modification
Draft

[#13635] Migrate NEW_INSTRUCTOR_ACCOUNT_WELCOME to dynamic DB template (POC)#13636
WeeJean wants to merge 4 commits intoTEAMMATES:masterfrom
WeeJean:email-modification

Conversation

@WeeJean
Copy link
Copy Markdown
Contributor

@WeeJean WeeJean commented Mar 18, 2026

Part of #13635

Description

This PR introduces the infrastructure to decouple TEAMMATES from hardcoded, static email templates. It allows administrators to dynamically edit email templates directly from the Admin UI, starting with the NEW_INSTRUCTOR_ACCOUNT_WELCOME email as a Proof of Concept (POC).

Key Architectural Changes

  1. Storage Layer: Created an email_templates table in PostgreSQL (via Liquibase), along with the EmailTemplate entity and EmailTemplatesDb DAO. It uses a unique constraint on the templateKey.
  2. API & Logic Layer: Added REST endpoints (GetEmailTemplatesAction, GetEmailTemplateAction, UpdateEmailTemplateAction) routed through a new EmailTemplatesLogic singleton to safely fetch, upsert, and revert templates.
  3. Frontend: Created a new standalone Angular component (admin-email-templates-page). It features a template editor with a live HTML preview (using DomSanitizer.bypassSecurityTrustHtml to safely render email <style> tags).
  4. Email Generation: Updated SqlEmailGenerator to attempt fetching the template from the DB first. If no custom template exists, it safely falls back to the original static .html file. The subject line is also parsed dynamically to support variables like ${userName}.

Why just one email?

This PR serves as a "Vertical Slice" to establish and review the Database, API, and UI architecture safely. Once this pattern is approved, the remaining ~30 static emails can easily be migrated to this new system in follow-up PRs without ballooning the scope of this initial review.

Screenshots / UI Preview

default format
image

revert to default option when you customise your message
image

Testing Done

  • Verified Liquibase migrations run successfully on local startup.
  • Verified template saves/updates correctly in PostgreSQL.
  • Verified "Revert to Default" successfully deletes the DB row and reloads the static fallback.
  • Triggered a real Account Request approval and verified via server logs that the email constructed utilizes the custom Subject and Body from the database, properly injecting ${userName} and ${joinUrl}.
  • Passed local checkstyleMain and npm run lint.

@WeeJean WeeJean marked this pull request as draft March 18, 2026 11:16
@WeeJean WeeJean requested a review from DhiraPT March 18, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant