Skip to content
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

Explore using Jinja for templating #376

Merged
merged 40 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ed107ee
add jinja to setup
H-Shay Aug 9, 2021
338bd5d
update send_email function to render templates with jinja
H-Shay Aug 9, 2021
589c396
change templates to use jinja
H-Shay Aug 9, 2021
8e40335
lints
H-Shay Aug 9, 2021
7c81e22
Add changelog
H-Shay Aug 9, 2021
c34bd99
merge with main to update branch
H-Shay Aug 11, 2021
a2106c1
add .j2 templates
H-Shay Aug 11, 2021
35eea47
check if jinja templates available and if so use them
H-Shay Aug 11, 2021
3f22e70
rename changelog file, version jinja in setup.py
H-Shay Aug 11, 2021
a97b0ae
lints
H-Shay Aug 11, 2021
525be72
requested changes
H-Shay Aug 11, 2021
308f9dc
revoke change to terms.py
H-Shay Aug 11, 2021
a721485
add some tests
H-Shay Aug 11, 2021
a542201
use jinja environment and autoescape
H-Shay Aug 11, 2021
fb7db3c
format jinja templates for autoescape and test
H-Shay Aug 12, 2021
35c2640
fix tests, fix jinja templates
H-Shay Aug 12, 2021
a3adf42
lints + update tests
H-Shay Aug 12, 2021
dd46fae
reset terms
H-Shay Aug 12, 2021
96580b9
update templates with safe filter
H-Shay Aug 13, 2021
c35fd94
move jinja environment creation to startup, add env to sydent
H-Shay Aug 13, 2021
56e0750
update tests
H-Shay Aug 13, 2021
4606fde
lints
H-Shay Aug 13, 2021
a5f1416
update template files
H-Shay Aug 16, 2021
808b539
update tests and send_email function
H-Shay Aug 16, 2021
f0f25cd
reset terms
H-Shay Aug 16, 2021
e75c4d7
update templates
H-Shay Aug 18, 2021
ab9ccec
only manually escape old templates
H-Shay Aug 18, 2021
5c8dc2e
update tests
H-Shay Aug 18, 2021
e43f0f9
add smaple text for testing
H-Shay Aug 18, 2021
3e3b116
update tests name
H-Shay Aug 18, 2021
6c60693
lints + rename jinja tests
H-Shay Aug 18, 2021
9880e0c
update sydent.py
H-Shay Aug 18, 2021
5379f85
requested changes + lints
H-Shay Aug 19, 2021
611ee4a
update templates
H-Shay Aug 23, 2021
0baa33c
requested changes + add licence
H-Shay Aug 23, 2021
4010fd5
lints
H-Shay Aug 23, 2021
a9dcbcf
slight refactor
H-Shay Aug 23, 2021
d4d0486
requested change + lints
H-Shay Aug 24, 2021
2da3529
Merge branch 'main' into jinja
H-Shay Aug 24, 2021
b0599a7
fix error in redering emails
H-Shay Aug 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/376.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for using Jinja2 in e-mail templates.
H-Shay marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions matrix_is_test/res/is-test/invite_template.eml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"token": "{{ token }}",
"room_alias": "{{ room_alias }}",
"room_avatar_url": "{{ room_avatar_url }}",
"room_name": "{{ room_name }}",
"sender_display_name": "{{ sender_display_name }}",
"sender_avatar_url": "{{ sender_avatar_url }}"
}
2 changes: 1 addition & 1 deletion matrix_is_test/res/is-test/verification_template.eml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<<<%(token)s>>>
<<<%(token)>>>
H-Shay marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions matrix_is_test/res/is-test/verification_template.eml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<<<{{ token }}>>>
11 changes: 7 additions & 4 deletions res/matrix-org/invite_template.eml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Hi,
%(sender_display_name)s %(bracketed_verified_sender)shas invited you into a room
%(bracketed_room_name)son Matrix. To join the conversation, either pick a
H-Shay marked this conversation as resolved.
Show resolved Hide resolved
Matrix client from https://matrix.org/docs/projects/try-matrix-now.html or use
the single-click link below to join via Element (requires Chrome, Firefox,
Safari, iOS or Android)
the single-click link below to join via Element requires Chrome, Firefox,
Safari, iOS or Android


H-Shay marked this conversation as resolved.
Show resolved Hide resolved
%(web_client_location)s/#/room/%(room_id_forurl)s?email=%(to_forurl)s&signurl=https%%3A%%2F%%2Fmatrix.org%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D%(token)s%%26private_key%%3D%(ephemeral_private_key)s&room_name=%(room_name_forurl)s&room_avatar_url=%(room_avatar_url_forurl)s&inviter_name=%(sender_display_name_forurl)s&guest_access_token=%(guest_access_token_forurl)s&guest_user_id=%(guest_user_id_forurl)s

Expand Down Expand Up @@ -83,6 +84,8 @@ pre, code {
text-align: right;
margin-left: 20px;
}


</style>
</head>
<body>
Expand All @@ -104,11 +107,11 @@ pre, code {

<p>%(sender_display_name_forhtml)s <span class="low-contrast">%(bracketed_verified_sender_forhtml)s</span> has invited you into a room %(bracketed_room_name_forhtml)s on
Matrix. To join the conversation, either <a href="https://matrix.org/docs/projects/try-matrix-now.html">pick a Matrix client</a> or use the single-click
link below to join via Element (requires
link below to join via Element requires
<a href="https://www.google.com/chrome">Chrome</a>,
<a href="https://www.getfirefox.com">Firefox</a> or
<a href="https://www.apple.com/safari">Safari</a> on the web,
or iOS or Android on mobile.)</p>
or iOS or Android on mobile.</p>
</p>

<p>
Expand Down
145 changes: 145 additions & 0 deletions res/matrix-org/invite_template.eml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
Date: {{ date }}
From: {{ from }}
To: {{ to }}
Message-ID: {{ messageid }}
Subject: {{ subject_header_value }}
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="{{ multipart_boundary }}"

--{{ multipart_boundary }}
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline

Hi,

{{ sender_display_name }} {{ bracketed_verified_sender }}has invited you into a room
{{ bracketed_room_name }}on Matrix. To join the conversation, either pick a
Matrix client from https://matrix.org/docs/projects/try-matrix-now.html or use
the single-click link below to join via Element requires Chrome, Firefox,
Safari, iOS or Android
H-Shay marked this conversation as resolved.
Show resolved Hide resolved

{{ web_client_location }}/#/room/{{ room_id_forurl }}?email={{ to_forurl }}&signurl=https%%3A%%2F%%2Fmatrix.org%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D{{ token }}%%26private_key%%3D{{ ephemeral_private_key }}&room_name={{ room_name_forurl }}&room_avatar_url={{ room_avatar_url_forurl }}&inviter_name={{ sender_display_name_forurl }}&guest_access_token={{ guest_access_token_forurl }}&guest_user_id={{ guest_user_id_forurl }}


About Matrix:

Matrix.org is an open standard for interoperable, decentralised, real-time communication
over IP, supporting group chat, file transfer, voice and video calling, integrations to
other apps, bridges to other communication systems and much more. It can be used to power
Instant Messaging, VoIP/WebRTC signalling, Internet of Things communication - or anywhere
you need a standard HTTP API for publishing and subscribing to data whilst tracking the
conversation history.

Matrix defines the standard, and provides open source reference implementations of
Matrix-compatible Servers, Clients, Client SDKs and Application Services to help you
create new communication solutions or extend the capabilities and reach of existing ones.

Thanks,

Matrix

--{{ multipart_boundary }}
Content-Type: text/html; charset=UTF-8
Content-Disposition: inline

<!doctype html>
<html lang="en">
<head>
<style type="text/css">
body {
margin: 0px;
}

pre, code {
word-break: break-word;
white-space: pre-wrap;
}

#page {
font-family: 'Open Sans', Helvetica, Arial, Sans-Serif;
font-color: #454545;
font-size: 12pt;
width: 100%%;
padding: 20px;
}

.low-contrast {
color: #666666
}

#inner {
width: 640px;
}

.header {
width: 100%%;
height: 87px;
color: #454545;
border-bottom: 4px solid #e5e5e5;
}

.logo {
text-align: right;
margin-left: 20px;
}


</style>
</head>
<body>
<table id="page">
<tr>
<td> </td>
<td id="inner">
<table class="header">
<tr>
<td>
</td>
<td class="logo">
<img src="http://matrix.org/img/matrix-120x51.png" width="120" height="51" alt="[matrix]"/>
</td>
</tr>
</table>

<p>Hi,</p>

<p>{{ sender_display_name_forhtml }} <span class="low-contrast">{{ bracketed_verified_sender_forhtml }}</span> has invited you into a room {{ bracketed_room_name_forhtml }} on
H-Shay marked this conversation as resolved.
Show resolved Hide resolved
Matrix. To join the conversation, either <a href="https://matrix.org/docs/projects/try-matrix-now.html">pick a Matrix client</a> or use the single-click
link below to join via Element requires
<a href="https://www.google.com/chrome">Chrome</a>,
<a href="https://www.getfirefox.com">Firefox</a> or
<a href="https://www.apple.com/safari">Safari</a> on the web,
or iOS or Android on mobile.</p>
H-Shay marked this conversation as resolved.
Show resolved Hide resolved
</p>

<p>
<a
href="https://app.element.io/#/room/{{ room_id_forurl }}?email={{ to_forurl }}&signurl=https%%3A%%2F%%2Fmatrix.org%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D{{ token }}%%26private_key%%3D{{ ephemeral_private_key }}&room_name={{ room_name_forurl }}&room_avatar_url={{ room_avatar_url_forurl }}&inviter_name={{ sender_display_name_forurl }}&guest_access_token={{ guest_access_token_forurl }}&guest_user_id={{ guest_user_id_forurl }}">Join the conversation.</a>
</p>

<br>
<p>About Matrix:</p>

<p>Matrix.org is an open standard for interoperable, decentralised, real-time communication
over IP, supporting group chat, file transfer, voice and video calling, integrations to
other apps, bridges to other communication systems and much more. It can be used to power
Instant Messaging, VoIP/WebRTC signalling, Internet of Things communication - or anywhere
you need a standard HTTP API for publishing and subscribing to data whilst tracking the
conversation history.</p>

<p>Matrix defines the standard, and provides open source reference implementations of
Matrix-compatible Servers, Clients, Client SDKs and Application Services to help you
create new communication solutions or extend the capabilities and reach of existing ones.</p>

<p>Thanks,</p>

<p>Matrix</p>
</td>
<td> </td>
</tr>
</table>
</body>
</html>

--{{ multipart_boundary }}--
88 changes: 88 additions & 0 deletions res/matrix-org/verification_template.eml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Date: {{ date }}
From: {{ from }}
To: {{ to }}
Message-ID: {{ messageid }}
Subject: Confirm your email address for Matrix
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="{{ multipart_boundary }}"

--{{ multipart_boundary }}
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline

Hello,

We have received a request to use this email address with a matrix.org identity
server. If this was you who made this request, you may use the following link
to complete the verification of your email address:

{{ link }}

If your client requires a code, the code is {{ token }}

If you aren't aware of making such a request, please disregard this email.


About Matrix:

Matrix is an open standard for interoperable, decentralised, real-time communication
over IP. It can be used to power Instant Messaging, VoIP/WebRTC signalling, Internet
of Things communication - or anywhere you need a standard HTTP API for publishing and
subscribing to data whilst tracking the conversation history.

Matrix defines the standard, and provides open source reference implementations of
Matrix-compatible Servers, Clients, Client SDKs and Application Services to help you
create new communication solutions or extend the capabilities and reach of existing ones.

--{{ multipart_boundary }}
Content-Type: text/html; charset=UTF-8
Content-Disposition: inline

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
body {
font-family: "Myriad Pro", "Myriad", Helvetica, Arial, sans-serif;
font-size: 12pt;
margin: 0px;
}
</style>
</head>
<body>
<p>Hello,</p>

<p>We have received a request to use this email address with a matrix.org
identity server. If this was you who made this request, you may use the
following link to complete the verification of your email address:</p>

<p><a href="{{ link }}">Complete email verification</a></p>

<p>...or copy this link into your web browser:</p>

<p>{{ link }}</p>

<p>If your client requires a code, the code is {{ token }}</p>

<p>If you aren't aware of making such a request, please disregard this
email.</p>

<br>
<p>About Matrix:</p>

<p>Matrix is an open standard for interoperable, decentralised, real-time communication
over IP. It can be used to power Instant Messaging, VoIP/WebRTC signalling, Internet
of Things communication - or anywhere you need a standard HTTP API for publishing and
subscribing to data whilst tracking the conversation history.</p>

<p>Matrix defines the standard, and provides open source reference implementations of
Matrix-compatible Servers, Clients, Client SDKs and Application Services to help you
create new communication solutions or extend the capabilities and reach of existing ones.</p>

</body>
</html>

--{{ multipart_boundary }}--
2 changes: 2 additions & 0 deletions res/vector-im/invite_template.eml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ Hi,
%(bracketed_room_name)son Element. To join the conversation please follow the
link below.


H-Shay marked this conversation as resolved.
Show resolved Hide resolved
%(web_client_location)s/#/room/%(room_id_forurl)s?email=%(to_forurl)s&signurl=https%%3A%%2F%%2Fvector.im%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D%(token)s%%26private_key%%3D%(ephemeral_private_key)s&room_name=%(room_name_forurl)s&room_avatar_url=%(room_avatar_url_forurl)s&inviter_name=%(sender_display_name_forurl)s&guest_access_token=%(guest_access_token_forurl)s&guest_user_id=%(guest_user_id_forurl)s


Element is an open source collaboration app built on the Matrix.org
open standard for interoperable communication: supporting group chat,
file transfer, voice and video calling, integrations to other apps, bridges
Expand Down
Loading