Skip to content

✨ Mailer: resolve templates through config.mailer.templates #4129

Description

@PierreBrisorgueil

What

  • Add mailer.templates: {} to development.config.js. It maps a key to a relative .html path.
  • Extract render(key, params, { subject } = {}), which returns the html, and export it. sendMail calls it.
  • Resolution:
    • The key goes through path.basename.
    • A key in the map uses its path.
    • Any other key falls back to config/templates/<key>.html, which is today's behavior.
  • Containment: a configured path must be relative, end in .html and resolve (path.relative) inside the project root. Otherwise throw an error that names the key.

Acceptance criteria

  • Callers are unchanged, and every existing key renders the same HTML as today.
  • A map entry pointing to config/templates/<project>/x.html wins over the flat file.
  • Keys not in the map still resolve from the flat folder, so templates that exist only in a downstream keep working.
  • Absolute paths, paths containing .. that escape the root, and non-.html paths are rejected.

Tests

  • Resolution order: a map hit, a map miss that falls back, and a key containing a traversal attempt.
  • Containment: an absolute path, .., and the wrong extension.
  • Baseline render over all 15 shared templates: each template gets fixture params. Assert that every {{variable}} it references is present in its fixture. Snapshot the normalized text; the fragments slice diffs against this snapshot.
  • Make the files.readFile mock path-aware.

Depends on: nothing (it can land in parallel with the billing-links fix).
Refs: lib/helpers/mailer/index.js:82-99, lib/helpers/mailer/tests/mailer.unit.tests.js

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions