Skip to content

[TTAHUB-5390] Make registering new email notifications/email digests easier#3664

Open
thewatermethod wants to merge 13 commits into
mainfrom
mb/dry-up-email
Open

[TTAHUB-5390] Make registering new email notifications/email digests easier#3664
thewatermethod wants to merge 13 commits into
mainfrom
mb/dry-up-email

Conversation

@thewatermethod

@thewatermethod thewatermethod commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Description of change

Simplify adding a new email notification by "dry"-ing up the code. Everything should work exactly the same before and after this change.

How to test

Locally:

  • Update .env with FORCE_CRON=true (to test digests) as well as SEND_NOTIFICATIONS=true and SEND_NON_PRODUCTION_NOTIFICATIONS=true
  • docker start:full
  • Verify your email, assign yourself a role that displays the email prefs in account management (TTAC, ECM, etc), or use impersonation
  • Test via mailpit at http://localhost:8025/
  • You can modify the cron frequency in src/lib/cron.js

Issue(s)

Checklists

Every PR

  • Meets issue criteria
  • JIRA ticket status updated
  • Code is meaningfully tested
  • Meets accessibility standards (WCAG 2.1 Levels A, AA)
  • API Documentation updated
  • Boundary diagram updated
  • Logical Data Model updated
  • Architectural Decision Records written for major infrastructure decisions
  • UI review complete
  • QA review complete

Before merge to main

  • OHS demo complete
  • Ready to create production PR

Production Deploy

  • PR created as Draft
  • Staging smoke test completed
  • PR transitioned to Open (this ready_for_review transition triggers the Slack/Jira automation)
  • Reviewer added after the PR is Open (elainaparrish is the authorized approver under normal circumstances)
    • Sequence: Draft PR → Smoke test → Open PR (automation runs) → Add reviewer
    • Confirm that the Slack notification was sent after the PR was opened
    • Confirm that linked Jira ticket(s) transitioned as expected; if not, review the GitHub Actions workflow logs

After merge/deploy

  • Update JIRA ticket status

thewatermethod and others added 5 commits May 27, 2026 16:43
Documents the full lifecycle of an email (trigger → Bull queue →
handler → email-templates → SMTP), all notification categories
(instant, digest, training report, special), key helpers
(createEmailSender, sendIfEnabled, enqueueNotification, DIGEST_CONFIG),
environment variables, and step-by-step recipes for registering new
instant, digest, and training-report notifications.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@thewatermethod thewatermethod changed the title Make registering new email notifications/email digests easier [TTAHUB-5390] Make registering new email notifications/email digests easier Jun 1, 2026
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

⚠️ Review count advisory: 0 of 2 required human approvals. 2 more needed.

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

⚠️ Diff size advisory: This PR is 1560 lines (1025+, 535−), exceeding the 500-line guideline. Consider splitting into smaller changes.

@thewatermethod thewatermethod marked this pull request as ready for review June 2, 2026 14:33
Copilot AI review requested due to automatic review settings June 2, 2026 14:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the mailer/cron email-notification plumbing to reduce duplication and make it easier to register new notification/digest types while preserving existing email behavior.

Changes:

  • Introduces shared mailer helpers (createEmailSender, sendIfEnabled, enqueueNotification) and refactors notification handlers to use them.
  • Adds a declarative digest registry (DIGEST_CONFIG) and a shared digest runner (digestForSetting), then updates cron to iterate the registry.
  • Adds/updates tests for the new digest registry/runner and documents the email notification architecture; updates local docker compose to point SMTP to mailpit.

Impact assessment: Benefits medium (less duplication, clearer extension points); risks medium (touches core notification sending + cron scheduling/logging paths).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/lib/mailer/index.js Refactors email send/enqueue logic, adds DIGEST_CONFIG + digestForSetting, consolidates queue processors.
src/lib/mailer/index.test.js Adds tests covering the new helpers/registry behavior.
src/lib/cron.js Consolidates daily/weekly/monthly digest jobs into a single configurable digest runner over DIGEST_CONFIG.
src/lib/cron.test.js Updates cron tests to validate iteration via DIGEST_CONFIG/digestForSetting.
docs/email_notifications.md New developer documentation describing notification lifecycle and how to register new email types.
docker/compose/docker-compose.yml Sets SMTP_HOST to mailpit for local docker environment.

Comment thread docs/email_notifications.md Outdated
Comment thread docs/email_notifications.md Outdated
Comment thread src/lib/cron.js
Comment thread src/lib/mailer/index.js
Comment thread src/lib/mailer/index.js
Comment thread src/lib/mailer/index.js
Comment thread src/lib/mailer/index.js
thewatermethod and others added 3 commits June 2, 2026 13:03
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Replace numeric-index lookups (DIGEST_CONFIG[0], etc.) with
semantic key lookups (DIGEST_CONFIG[EMAIL_ACTIONS.X]).

This eliminates positional coupling so that adding, removing,
or reordering digest types no longer risks silent breakage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread docker/compose/docker-compose.yml Outdated
Comment thread docs/email_notifications.md Outdated
Comment thread src/lib/mailer/index.js
thewatermethod and others added 2 commits June 9, 2026 13:45
…ACTIONS from DIGEST_CONFIG

- Remove hard-coded SMTP_HOST=mailpit from always-on backend service in
  docker-compose.yml; mailpit only exists in the fullstack profile so
  core-stack runs were pointing at a non-existent SMTP host
- Document that SMTP_HOST=mailpit must be set in .env when running
  yarn docker:start:full for local email testing (email_notifications.md,
  dev-setup.md)
- Fix command typo: 'docker start:full' → 'yarn docker:start:full' in
  docs/email_notifications.md
- Derive DIGEST_EMAIL_ACTIONS from Object.keys(DIGEST_CONFIG) so any new
  digest added to DIGEST_CONFIG automatically gets a Bull processor
  registered, preventing schedule-without-processor bugs
- Add test asserting processNotificationQueue registers a processor for
  every DIGEST_CONFIG entry plus RECIPIENT_REPORT_APPROVED_DIGEST

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants