Skip to content

Commit bc38745

Browse files
committed
feat: add email wiring for tool_request notification category
Add ToolRequestEmailNotificationTemplateBuilder and register it in email_templates_by_category. Add HTML and plain-text email templates for tool installation request notifications.
1 parent e5fcc34 commit bc38745

3 files changed

Lines changed: 226 additions & 0 deletions

File tree

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
Use this template to customize the HTML email your admins will receive
2+
when a user submits a tool installation request.
3+
Copy the file to {{ templates_dir }}/mail/notifications/tool_request-email.html and modify as required.
4+
5+
If you are adding URLs, remember that only absolute URLs (with
6+
a domain name) make sense in email! They can be served from any stable
7+
location, including your Galaxy server or GitHub.
8+
9+
The following variables are available for inserting into the HTML with Jinja2
10+
syntax, like {{ variable_name }}. They will be rendered into the text before
11+
the email is sent:
12+
13+
- name The admin's name
14+
- user_email The admin's email
15+
- date Date and time of the notification
16+
- hostname Your galaxy's hostname (i.e. usegalaxy.* or the value in `server_name` from the galaxy config file)
17+
- contact_email Your galaxy's contact email
18+
- notification_settings_url The URL to the admin's notification settings to manage their subscriptions
19+
- variant The notification variant indicates the level of importance of the notification (i.e. info, warning, urgent)
20+
- content The tool_request payload
21+
- tool_name The name of the requested tool
22+
- tool_url Homepage or repository URL for the tool (optional)
23+
- description Description of the tool and its use case
24+
- scientific_domain Scientific domain (optional)
25+
- requested_version Requested version (optional)
26+
- conda_available Whether a Conda package is available (optional)
27+
- test_data_available Whether test data is available (optional)
28+
- requester_name The username of the requester
29+
- requester_email The email address of the requester
30+
- requester_affiliation The affiliation/lab of the requester (optional)
31+
- workflow_name Name of the workflow requiring these tools (optional)
32+
- tool_ids List of tool shed IDs for workflow install requests (optional)
33+
- galaxy_url The URL to the Galaxy instance (i.e. https://usegalaxy.*)
34+
35+
Template begins here >>>>>>
36+
<!DOCTYPE html>
37+
<html lang="en" dir="ltr">
38+
<head>
39+
<meta charset="utf-8">
40+
<title>[Galaxy] Tool installation request: {{ content['tool_name'] }}</title>
41+
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
42+
</head>
43+
<body style="font-family: 'Roboto', sans-serif;">
44+
45+
<p style="font-size: 12pt;">
46+
Hello {{ name }},<br><br>
47+
48+
A user has submitted a request to install a new tool on <b>{{ hostname }}</b> on <b>{{ date }}</b>.
49+
</p>
50+
51+
<table style="font-size: 12pt; border-collapse: collapse; width: 100%;">
52+
<tr>
53+
<td style="padding: 4px 8px; font-weight: bold; white-space: nowrap;">Tool name</td>
54+
<td style="padding: 4px 8px;">{{ content['tool_name'] }}</td>
55+
</tr>
56+
{% if content['tool_url'] %}
57+
<tr>
58+
<td style="padding: 4px 8px; font-weight: bold; white-space: nowrap;">URL</td>
59+
<td style="padding: 4px 8px;">{{ content['tool_url'] }}</td>
60+
</tr>
61+
{% endif %}
62+
<tr>
63+
<td style="padding: 4px 8px; font-weight: bold; white-space: nowrap; vertical-align: top;">Description</td>
64+
<td style="padding: 4px 8px;">{{ content['description'] }}</td>
65+
</tr>
66+
{% if content['scientific_domain'] %}
67+
<tr>
68+
<td style="padding: 4px 8px; font-weight: bold; white-space: nowrap;">Scientific domain</td>
69+
<td style="padding: 4px 8px;">{{ content['scientific_domain'] }}</td>
70+
</tr>
71+
{% endif %}
72+
{% if content['requested_version'] %}
73+
<tr>
74+
<td style="padding: 4px 8px; font-weight: bold; white-space: nowrap;">Requested version</td>
75+
<td style="padding: 4px 8px;">{{ content['requested_version'] }}</td>
76+
</tr>
77+
{% endif %}
78+
{% if content['conda_available'] is not none %}
79+
<tr>
80+
<td style="padding: 4px 8px; font-weight: bold; white-space: nowrap;">Conda package available</td>
81+
<td style="padding: 4px 8px;">{{ "Yes" if content['conda_available'] else "No" }}</td>
82+
</tr>
83+
{% endif %}
84+
{% if content['test_data_available'] is not none %}
85+
<tr>
86+
<td style="padding: 4px 8px; font-weight: bold; white-space: nowrap;">Test data available</td>
87+
<td style="padding: 4px 8px;">{{ "Yes" if content['test_data_available'] else "No" }}</td>
88+
</tr>
89+
{% endif %}
90+
{% if content['workflow_name'] %}
91+
<tr>
92+
<td style="padding: 4px 8px; font-weight: bold; white-space: nowrap;">Workflow</td>
93+
<td style="padding: 4px 8px;">{{ content['workflow_name'] }}</td>
94+
</tr>
95+
{% endif %}
96+
<tr>
97+
<td style="padding: 4px 8px; font-weight: bold; white-space: nowrap;">Requested by</td>
98+
<td style="padding: 4px 8px;">
99+
{{ content['requester_name'] }}
100+
{% if content['requester_affiliation'] %} ({{ content['requester_affiliation'] }}){% endif %}
101+
{% if content['requester_email'] %} &mdash; {{ content['requester_email'] }}{% endif %}
102+
</td>
103+
</tr>
104+
</table>
105+
106+
<p style="font-size: 12pt;">
107+
{% if galaxy_url %}
108+
You can review the notification in Galaxy: <a href="{{ galaxy_url }}/user/notifications">View notifications</a>
109+
{% endif %}
110+
</p>
111+
112+
<p style="font-size: 12pt;">
113+
Thank you for administering Galaxy!
114+
</p>
115+
116+
<p style="font-size: 12pt;">
117+
Regards,<br>
118+
Your Galaxy Team at <a href="{{ galaxy_url }}">{{ hostname }}</a>
119+
</p>
120+
121+
<p style="font-size: 10pt;">
122+
You received this email because you are an administrator of this Galaxy instance.
123+
{% if notification_settings_url %}
124+
You can manage your notification settings <a href="{{ notification_settings_url }}">here</a>.
125+
{% endif %}
126+
127+
<br>
128+
129+
{% if contact_email %}
130+
This is an automated email. If you have any questions or concerns, please do not reply to this email, instead, contact us at <a href="mailto:{{ contact_email }}">{{ contact_email }}</a>.
131+
{% endif %}
132+
</p>
133+
134+
<img
135+
style="width: 130px; height: auto; margin: 15px 0;"
136+
src="https://galaxyproject.org/images/galaxy-logos/galaxy_project_logo_square.png"
137+
alt="Galaxy project logo"
138+
>
139+
140+
<br>
141+
142+
</body>
143+
</html>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Use this template to customize the text email your admins will receive
2+
when a user submits a tool installation request.
3+
Copy the file to {{ templates_dir }}/mail/notifications/tool_request-email.txt and modify as required.
4+
5+
If you are adding URLs, remember that only absolute URLs (with
6+
a domain name) make sense in email! They can be served from any stable
7+
location, including your Galaxy server or GitHub.
8+
9+
The following variables are available for inserting into the text like
10+
{{ variable_name }}. They will be rendered into the text before the email is
11+
sent:
12+
13+
- name The admin's name
14+
- user_email The admin's email
15+
- date Date and time of the notification
16+
- hostname Your galaxy's hostname (i.e. usegalaxy.* or the value in `server_name` from the galaxy config file)
17+
- contact_email Your galaxy's contact email
18+
- notification_settings_url The URL to the admin's notification settings to manage their subscriptions
19+
- variant The notification variant indicates the level of importance of the notification (i.e. info, warning, urgent)
20+
- content The tool_request payload
21+
- tool_name The name of the requested tool
22+
- tool_url Homepage or repository URL for the tool (optional)
23+
- description Description of the tool and its use case
24+
- scientific_domain Scientific domain (optional)
25+
- requested_version Requested version (optional)
26+
- conda_available Whether a Conda package is available (optional)
27+
- test_data_available Whether test data is available (optional)
28+
- requester_name The username of the requester
29+
- requester_email The email address of the requester
30+
- requester_affiliation The affiliation/lab of the requester (optional)
31+
- workflow_name Name of the workflow requiring these tools (optional)
32+
- tool_ids List of tool shed IDs for workflow install requests (optional)
33+
- galaxy_url The URL to the Galaxy instance (i.e. https://usegalaxy.*)
34+
35+
Template begins here>>>>>>
36+
Hello {{ name }},
37+
38+
A user has submitted a request to install a new tool on {{ hostname }} on {{ date }}.
39+
40+
Tool name: {{ content['tool_name'] }}
41+
{% if content['tool_url'] %}URL: {{ content['tool_url'] }}
42+
{% endif %}Description: {{ content['description'] }}
43+
{% if content['scientific_domain'] %}Domain: {{ content['scientific_domain'] }}
44+
{% endif %}{% if content['requested_version'] %}Version: {{ content['requested_version'] }}
45+
{% endif %}{% if content['conda_available'] is not none %}Conda pkg: {{ "Yes" if content['conda_available'] else "No" }}
46+
{% endif %}{% if content['test_data_available'] is not none %}Test data: {{ "Yes" if content['test_data_available'] else "No" }}
47+
{% endif %}{% if content['workflow_name'] %}Workflow: {{ content['workflow_name'] }}
48+
{% endif %}Requested by: {{ content['requester_name'] }}{% if content['requester_affiliation'] %} ({{ content['requester_affiliation'] }}){% endif %}{% if content['requester_email'] %} — {{ content['requester_email'] }}{% endif %}
49+
50+
{% if galaxy_url %}
51+
You can review the notification in Galaxy: {{ galaxy_url }}/user/notifications
52+
{% endif %}
53+
54+
Thank you for administering Galaxy!
55+
56+
Regards,
57+
Your Galaxy Team at {{ hostname }}
58+
59+
---
60+
61+
You received this email because you are an administrator of this Galaxy instance.
62+
{% if notification_settings_url %}
63+
To manage your notification settings, please visit {{ notification_settings_url }}.
64+
{% endif %}
65+
66+
{% if contact_email %}
67+
This is an automated email. If you have any questions or concerns, please do not reply to this email, instead, contact us at {{ contact_email }}.
68+
{% endif %}
69+
70+

lib/galaxy/managers/notification.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
NotificationResponse,
6767
NotificationVariant,
6868
PersonalNotificationCategory,
69+
ToolRequestNotificationContent,
6970
UpdateUserNotificationPreferencesRequest,
7071
UserNotificationPreferences,
7172
UserNotificationUpdateRequest,
@@ -809,11 +810,23 @@ def get_subject(self) -> str:
809810
return f"[Galaxy] New {content.item_type} shared with you: {content.item_name}"
810811

811812

813+
class ToolRequestEmailNotificationTemplateBuilder(EmailNotificationTemplateBuilder):
814+
815+
def get_content(self, template_format: TemplateFormats) -> AnyNotificationContent:
816+
content = ToolRequestNotificationContent.model_construct(**self.notification.content) # type: ignore[arg-type]
817+
return content
818+
819+
def get_subject(self) -> str:
820+
content = cast(ToolRequestNotificationContent, self.get_content(TemplateFormats.TXT))
821+
return f"[Galaxy] Tool installation request: {content.tool_name}"
822+
823+
812824
class EmailNotificationChannelPlugin(NotificationChannelPlugin):
813825
# Register the supported email templates here
814826
email_templates_by_category: dict[PersonalNotificationCategory, type[EmailNotificationTemplateBuilder]] = {
815827
PersonalNotificationCategory.message: MessageEmailNotificationTemplateBuilder,
816828
PersonalNotificationCategory.new_shared_item: NewSharedItemEmailNotificationTemplateBuilder,
829+
PersonalNotificationCategory.tool_request: ToolRequestEmailNotificationTemplateBuilder,
817830
}
818831

819832
def send(self, notification: Notification, user: User):

0 commit comments

Comments
 (0)