-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add configurable email templates #1173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
23a1cb7
ecb009e
bbf6b81
16fc59e
c032423
892ca3b
4647053
537f445
2ade6c1
ac9919e
bb3ae4b
2ed631c
0a69611
0301e94
9828a7e
209bcb9
8ac3a81
e9cb621
593c1b0
7f035d1
8d04cd8
3884223
6e808f6
3306878
62e48a5
19fac52
97683e4
868727a
0336aec
048b88e
0061bcf
75ec614
e5adfe1
bbc250c
bcc44ae
2bd3ea2
7d15582
e0eb37e
ce7e11b
be11205
36e4341
5d5ecb0
f2af9bc
c441c9f
09ebc7c
f4a4f61
c3602ec
9124e43
434a482
61adfb7
eda5b1d
587ad82
5d66635
8e0c4c3
481d4b8
9cd5c9c
3bfb6bc
d561534
6381bc5
89d9645
bc4f54f
cdc1c05
b3fb8a6
d2657ca
18f6995
b599dc2
4fc0ff7
23b7078
039f3c8
60aa48c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| DO | ||
| $$ | ||
| DECLARE | ||
| email_template_id_var int; | ||
| connection_loop_var record; | ||
| array_size_var int; | ||
| array_loop_var int; | ||
| template_name varchar(200); | ||
| BEGIN | ||
| IF register_patch('CreateEmailTemplatesTable.sql', 'Gergely Nyiri', 'Create email templates table', '2025-07-15') THEN | ||
|
|
||
| CREATE TABLE IF NOT EXISTS email_templates ( | ||
| email_template_id serial PRIMARY KEY, | ||
| created_by INT NOT NULL REFERENCES users(user_id), | ||
| created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
| name varchar(100) NOT NULL UNIQUE, | ||
| description varchar(255) NOT NULL, | ||
| subject varchar(160) NOT NULL, | ||
| body text | ||
| ); | ||
|
|
||
gnyiri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'CLF PI Co-I Submission Email', 'CLF PI Co-I Submission Email', '= `Proposal submitted`', 'Proposal submitted'); | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'ISIS PI Co-I Submission Email', 'ISIS PI Co-I Submission Email', '= `Proposal submitted`', 'Proposal submitted'); | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'ISIS Rapid PI Co-I Submission Email', 'ISIS Rapid PI Co-I Submission Email', '= `Proposal submitted`', 'Proposal submitted'); | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'ISIS Rapid User Office Submission Email', 'ISIS Rapid User Office Submission Email', '= `Proposal submitted`', 'Proposal submitted'); | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'ISIS Xpress PI Co-I Submission Email', 'ISIS Xpress PI Co-I Submission Email', '= `Proposal submitted`', 'Proposal submitted'); | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'ISIS Xpress Scientist Submission Email', 'ISIS Xpress Scientist Submission Email', '= `Proposal submitted`', 'Proposal submitted'); | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'ISIS Xpress PI Co-I Under Review Email', 'ISIS Xpress PI Co-I Under Review Email', '= `Proposal under review`', 'Proposal under review'); | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'ISIS Xpress PI Co-I Approval Email', 'ISIS Xpress PI Co-I Approval Email', '= `Proposal approved`', 'Proposal approved'); | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'ISIS Xpress SRA Request Email', 'ISIS Xpress SRA Request Email', '= `Proposal SRA request`', 'Proposal SRA request'); | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'ISIS Xpress PI Co-I Reject Email', 'ISIS Xpress PI Co-I Reject Email', '= `Proposal unsuccessful`', 'Proposal unsuccessful'); | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'ISIS Xpress PI Co-I Finish Email', 'ISIS Xpress PI Co-I Finish Email', '= `Proposal finished`', 'Proposal finished'); | ||
|
|
||
| FOR connection_loop_var IN | ||
| SELECT * FROM workflow_connection_has_actions | ||
| LOOP | ||
| IF connection_loop_var.config IS NOT NULL THEN | ||
| SELECT jsonb_array_length(connection_loop_var.config->'recipientsWithEmailTemplate') INTO array_size_var; | ||
|
|
||
| IF array_size_var IS NULL THEN | ||
| array_size_var := 0; | ||
| END IF; | ||
|
|
||
| FOR array_loop_var IN 0..array_size_var-1 LOOP | ||
| SELECT connection_loop_var.config->'recipientsWithEmailTemplate'->array_loop_var->'emailTemplate'->>'name' INTO template_name; | ||
|
|
||
| IF template_name IS NOT NULL THEN | ||
| -- RAISE NOTICE 'Processing connection % % with template % to %', array_loop_var, connection_loop_var.connection_id, template_name, update_config; | ||
|
|
||
| SELECT email_templates.email_template_id INTO email_template_id_var FROM email_templates WHERE name = template_name; | ||
|
|
||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| WHERE connection_id = connection_loop_var.connection_id; | ||
| -- ELSE | ||
| -- RAISE WARNING 'No email template found for name %', template_name; | ||
| END IF; | ||
| -- ELSE | ||
| -- RAISE WARNING 'No email template found for connection %', template_name; | ||
| END IF; | ||
| END LOOP; | ||
| END IF; | ||
| END LOOP; | ||
| END IF; | ||
| END; | ||
| $$ | ||
| LANGUAGE plpgsql; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| DO | ||
| $DO$ | ||
| BEGIN | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'template-name-1', 'template-description-1', 'template-subject-1', 'template-body-1'); | ||
|
|
||
| INSERT INTO email_templates (created_by, name, description, subject, body) | ||
| VALUES | ||
| (0, 'template-name-2', 'template-description-2', 'template-subject-2', 'template-body-2'); | ||
|
|
||
| END; | ||
| $DO$ | ||
| LANGUAGE plpgsql; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.