Skip to content

Commit 580fbd4

Browse files
committed
Added: yaml repr of email config (#284)
1 parent 42c4ebd commit 580fbd4

File tree

1 file changed

+93
-3
lines changed

1 file changed

+93
-3
lines changed

libreforms_fastapi/utils/jinja_emails.py

+93-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ def _fail_with_undefined_error(self, *args, **kwargs):
77
raise UndefinedError(f"{self._undefined_name} is undefined but is required for rendering the email template.")
88

99

10-
# Here we create a jinja env
11-
env = Environment(autoescape=select_autoescape(['html', 'xml']))
10+
# Here we create a jinja env and pass our custom undefined exception
11+
env = Environment(
12+
autoescape=select_autoescape(['html', 'xml']),
13+
undefined=RaiseExceptionUndefined,
14+
)
1215

1316

1417
default_templates = {
@@ -81,6 +84,93 @@ def _fail_with_undefined_error(self, *args, **kwargs):
8184

8285

8386

87+
EXAMPLE_EMAIL_CONFIG_YAML = '''
88+
transaction_log_error:
89+
subj: "Transaction Log Error"
90+
cont: |
91+
You are receiving this message because you are the designated help email for {{ config.SITE_NAME }}. This message is to notify you that there was an error when writing the following transaction to the transaction log for {{ config.SITE_NAME }}:
92+
93+
***
94+
95+
User: {{ user.username if not user.opt_out else 'N/A' }}
96+
Timestamp: {{ current_time }}
97+
Endpoint: {{ endpoint }}
98+
Query Params: {{ query_params if query_params else 'N/A' }}
99+
Remote Address: {{ remote_addr if not user.opt_out else 'N/A' }}
100+
api_key_rotation:
101+
subj: "{{ config.SITE_NAME }} API Key Rotated"
102+
cont: |
103+
This email serves to notify you that an API key for user {{ user.username }} has just rotated at {{ config.DOMAIN }}. Please note that your past API key will no longer work if you are employing it in applications. Your new key will be active for 365 days. You can see your new key by visiting {{ config.DOMAIN }}/profile.
104+
form_created:
105+
subj: "Form Created"
106+
cont: |
107+
This email serves to notify you that a form was submitted at {{ config.DOMAIN }} by the user registered at this email address. The form's document ID is '{{ document_id }}'. If you believe this was a mistake, or did not submit a form, please contact your system administrator.
108+
form_updated:
109+
subj: "Form Updated"
110+
cont: |
111+
This email serves to notify you that an existing form was updated at {{ config.DOMAIN }} by the user registered at this email address. The form's document ID is '{{ document_id }}'. If you believe this was a mistake, or did not submit a form, please contact your system administrator.
112+
form_deleted:
113+
subj: "Form Deleted"
114+
cont: |
115+
This email serves to notify you that a form was deleted at {{ config.DOMAIN }} by the user registered at this email address. The form's document ID is '{{ document_id }}'. If you believe this was a mistake, or did not submit a form, please contact your system administrator.
116+
form_restored:
117+
subj: "Form Restored"
118+
cont: |
119+
This email serves to notify you that a deleted form was restored at {{ config.DOMAIN }} by the user registered at this email address. The form's document ID is '{{ document_id }}'. If you believe this was a mistake, or did not submit a form, please contact your system administrator.
120+
form_signed:
121+
subj: "Form Signed"
122+
cont: |
123+
This email serves to notify you that a form was signed at {{ config.DOMAIN }} by the user registered at this email address. The form's document ID is '{{ document_id }}'. If you believe this was a mistake, or did not intend to sign this form, please contact your system administrator.
124+
form_unsigned:
125+
subj: "Form Unsigned"
126+
cont: |
127+
This email serves to notify you that a form was unsigned at {{ config.DOMAIN }} by the user registered at this email address. The form's document ID is '{{ document_id }}'. If you believe this was a mistake, or did not intend to unsign this form, please contact your system administrator.
128+
user_password_changed:
129+
subj: "{{ config.SITE_NAME }} User Password Changed"
130+
cont: |
131+
This email serves to notify you that the user {{ user.username }} has just had their password changed at {{ config.DOMAIN }}. If you believe this was a mistake, please contact your system administrator.
132+
password_reset_instructions:
133+
subj: "{{ config.SITE_NAME }} User Password Reset Instructions"
134+
cont: |
135+
This email serves to notify you that the user {{ user.username }} has just requested to reset their password at {{ config.DOMAIN }}. To do so, you may use the one-time password {{ otp }}. This one-time password will expire in three hours. If you have access to the user interface, you may reset your password at the following link: {{ config.DOMAIN }}/ui/auth/forgot_password/{{ otp }}. If you believe this was a mistake, please contact your system administrator.
136+
password_reset_complete:
137+
subj: "{{ config.SITE_NAME }} User Password Reset"
138+
cont: |
139+
This email serves to notify you that the user {{ user.username }} has just successfully reset their password at {{ config.DOMAIN }}. If you believe this was a mistake, please contact your system administrator.
140+
user_registered:
141+
subj: "{{ config.SITE_NAME }} User Registered"
142+
cont: |
143+
This email serves to notify you that the user {{ username }} has just been registered for this email address at {{ config.DOMAIN }}. Your user has been given the following temporary password:
144+
145+
{{ password }}
146+
147+
Please login to the system and update this password at your earliest convenience.
148+
user_registered_verification:
149+
subj: "{{ config.SITE_NAME }} User Registered"
150+
cont: |
151+
This email serves to notify you that the user {{ username }} has just been registered for this email address at {{ config.DOMAIN }}. Please verify your email by clicking the following link: {{ config.DOMAIN }}/verify/{{ key }}. Please note this link will expire after 48 hours.
152+
suspicious_activity:
153+
subj: "{{ config.SITE_NAME }} Suspicious Activity"
154+
cont: |
155+
This email serves to notify you that there was an attempt to register a user with the same email as the account registered to you at {{ config.DOMAIN }}. If this was you, you may safely disregard this email. If it was not you, you should consider contacting your system administrator and changing your password.
156+
help_request:
157+
subj: "Help Request from {{ user.username }}"
158+
cont: |
159+
You are receiving this message because a user has submitted a request for help at {{ config.DOMAIN }}. You can see the request details below.
160+
161+
****
162+
User: {{ user.username }}
163+
Email: {{ user.email }}
164+
Time of Submission: {{ time }}
165+
Category: {{ category }}
166+
Subject: {{ subject }}
167+
Message: {{ message }}
168+
****
169+
170+
You may reply directly to the user who submitted this request by replying to this email.
171+
'''
172+
173+
84174
def get_message_jinja(message_type):
85175
# Retrieve the unrendered Jinja templates from the dictionary
86176
subj_template_str = default_templates[message_type]['subj']
@@ -104,4 +194,4 @@ def render_email_message_from_jinja(message_type, **kwargs):
104194
rendered_subj = template_subj.render(**kwargs)
105195
rendered_cont = template_cont.render(**kwargs)
106196

107-
return rendered_subj, rendered_cont
197+
return rendered_subj, rendered_cont

0 commit comments

Comments
 (0)