Skip to content

feat: add configurable email templates#1173

Open
gnyiri wants to merge 93 commits intodevelopfrom
add-configurable-email-templates
Open

feat: add configurable email templates#1173
gnyiri wants to merge 93 commits intodevelopfrom
add-configurable-email-templates

Conversation

@gnyiri
Copy link
Collaborator

@gnyiri gnyiri commented Sep 8, 2025

Description

Configure email templates from UI. The PR introduces a new table for storing email templates (name, description, subject, body). The logic of assigning email templates to status actions will be the same as before: the user selects the template name from the list of available templates (populated from DB).

Important notes:

  • email handler classes will still be able to use the original approach (file based templates). If the email template of the given name don't exist in the DB the email service will try to look for a template file with the given name and use it as a template
  • the migration will only be partial and a one-time manual step will be needed from STFC after deployment: the body/subject of the email templates have to be manually copied from the physical files so that the email templates will be stored in the DB (since I only have the template names and not the content).

Motivation and Context

At ELI we frequently change the email templates and found it uncomfortable to write physical files on the host of the backend.

How Has This Been Tested

Manual tests + backend test.

Fixes

N/A

Changes

See above

Depends on

N/A

Tests included/Docs Updated?

Yes

  • [ x] I have added tests to cover my changes.
  • All relevant doc has been updated

@gnyiri gnyiri changed the title Add configurable email templates feat: add configurable email templates Sep 8, 2025
@jekabs-karklins
Copy link
Contributor

Do you mean that PUG syntax highlighting should be applied in this editor field?

Thank you for clarifying, that user will enter the PUG syntax in the field. And then - yes we can add latter the syntax verification and highligting with the library. Would be nice addition and seems like a low hanging fruit.

@jekabs-karklins
Copy link
Contributor

suggestion: I suggest not putting the template names in the PR, as the content of the templates appears to be placeholders and will change dynamically. I suggest putting one or two placeholder template names like "Template 1"

Where should I apply these template names in fact? Are you referring to the sql script?

Hi, yes sorry - I'm reffering to the SQL patch
I think we can defined new templates with the Create new template
image . Would that work?

@jekabs-karklins
Copy link
Contributor

Hello @gnyiri , first of all, sorry for the late review, was catching up from my paternity leave.
I see @yoganandaness has looked into this PR deeply and thoroughly. In this regard if there are any outstanding clarifications from what @yoganandaness has commented, please let me know and we can look at them together, if those addressed we can merge the PR.
I have looked at the PR from a little higher perspective and I have a few comments/questions. below
Comment: Using SparkPost it is possible to send email two ways,

  • "stored template" - you supply template_id:string + substitution_data:object
  • "inline" - you supply pre-rendered email body
    If you have implemented rendering of email body in the User Office we could move the SparkPost templates in the UOS, switch to "inline" method and use Sparkpost only as a email transport layer.

I would need to talk to the team but I think that would simplify the whole email handling.

Yes, with the current implementation the email service will pre-render the email body into html (PUG syntax) and send the message using the rendered html as is.

Perfect, thanks. This sounds promissing.

@yoganandaness yoganandaness self-requested a review January 9, 2026 08:47
@gnyiri
Copy link
Collaborator Author

gnyiri commented Jan 12, 2026

suggestion: I suggest not putting the template names in the PR, as the content of the templates appears to be placeholders and will change dynamically. I suggest putting one or two placeholder template names like "Template 1"

Where should I apply these template names in fact? Are you referring to the sql script?

Hi, yes sorry - I'm reffering to the SQL patch I think we can defined new templates with the Create new template image . Would that work?

I removed the migration part from the DB script, that is, the email templates + status actions must be created manually after applying this feature.

Copy link
Contributor

@jekabs-karklins jekabs-karklins left a comment

Choose a reason for hiding this comment

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

👍🏻

@gnyiri gnyiri requested a review from TCMeldrum January 22, 2026 07:19
Copy link
Contributor

@mutambaraf mutambaraf left a comment

Choose a reason for hiding this comment

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

Looks good just the few comments.

@mutambaraf
Copy link
Contributor

I also tried to use it as is on my local set up and having this error Could not send email(s) because the email template with id CLF PI Co-I Submission Email does not exist.'. Do we need to do any set up to get it to work with our existing setup.

@gnyiri
Copy link
Collaborator Author

gnyiri commented Jan 27, 2026

I also tried to use it as is on my local set up and having this error Could not send email(s) because the email template with id CLF PI Co-I Submission Email does not exist.'. Do we need to do any set up to get it to work with our existing setup.

I guess you have status actions referencing email templates. These templates should be created with proper names, subjects and bodies. I can create the templates in this PR in the DB patch but I don't know the email bodies and subjects. Having this feature, would you move the email subjects/bodies completely into UOS? Or you still want to keep those details outside UOS?

@mutambaraf
Copy link
Contributor

I also tried to use it as is on my local set up and having this error Could not send email(s) because the email template with id CLF PI Co-I Submission Email does not exist.'. Do we need to do any set up to get it to work with our existing setup.

I guess you have status actions referencing email templates. These templates should be created with proper names, subjects and bodies. I can create the templates in this PR in the DB patch but I don't know the email bodies and subjects. Having this feature, would you move the email subjects/bodies completely into UOS? Or you still want to keep those details outside UOS?

So we need to move from files and create all our template into the database.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants