Skip to content

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
@gnyiri gnyiri requested a review from a team as a code owner October 13, 2025 08:37
@gnyiri gnyiri requested review from William-Edwards-STFC, jekabs-karklins and yoganandaness and removed request for a team October 13, 2025 08:37
@yoganandaness
Copy link
Contributor

@gnyiri Could you resolve the conflicts?

Copy link
Contributor

@yoganandaness yoganandaness left a comment

Choose a reason for hiding this comment

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

@gnyiri

Apologies for the late review.

Good work this. However, there are few areas that i felt could be improved and have commented here. Feel free to mail me or msg me, in case you need a call and we can talk.

And there are few conflicts in the PR

Thanks


IF email_template_id_var IS NOT NULL THEN
UPDATE workflow_connection_has_actions
SET config = jsonb_set(config::jsonb, ('{recipientsWithEmailTemplate, ' || array_loop_var || ', emailTemplate, id}')::text[], to_jsonb(email_template_id_var), false)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is good, as i can see instead of saving the hardcoded template id(ISIS Xpress PI Co-I Finish Email), we are going to save the primary key from the new table(email_templates)

Given that case, is it a good idea to go for a new table with foreign constraint for a safer transaction. This can exist only for smtp related operations and not for sparkpost. sparkpost can stay as it is.

with fk, it will be easy to handle deletion of email templates. for ex., if we delete an email template, we can add a cascading effect, so that the corresponding status actions will also be cleared with the email template.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we have more time, this can be done as a part of this PR. Or else, this can be taken up on the later phase.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am still struggling with the spark post emails. What should be the email template id in these cases? Should it be zero? If so, the validation will fail. In the recent update I use the unique template name for identifying templates instead of the template id because for Spark Post emails there is no associated db id.

proposals: [proposal],
template: recipientsWithEmailTemplate.emailTemplate.id,
template: recipientsWithEmailTemplate.emailTemplate.name,
templateId: recipientsWithEmailTemplate.emailTemplate.id,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, flipping this will cause variability in the app behaviour especially in terms of logging and saving event logs

const getEmailTemplate = (foundRecipientWithEmailTemplateIndex: number) => {
if (foundRecipientWithEmailTemplateIndex !== -1) {
return (
emailTemplates.find(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we are doing this to ensure that the setted up Email template is present in the Overall list, and if it does not, return null. If we could implement the foreign key relationship, then we will not have this issue.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

⚠️ Automatic rebase failed due to conflicts. Please rebase manually.

5 similar comments
@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

⚠️ Automatic rebase failed due to conflicts. Please rebase manually.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

⚠️ Automatic rebase failed due to conflicts. Please rebase manually.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

⚠️ Automatic rebase failed due to conflicts. Please rebase manually.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

⚠️ Automatic rebase failed due to conflicts. Please rebase manually.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

⚠️ Automatic rebase failed due to conflicts. Please rebase manually.

@github-actions
Copy link
Contributor

⚠️ Automatic rebase failed due to conflicts. Please rebase manually.

@github-actions
Copy link
Contributor

⚠️ Automatic rebase failed due to conflicts. Please rebase manually.

@github-actions
Copy link
Contributor

⚠️ Automatic rebase failed due to conflicts. Please rebase manually.

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.

3 participants