diff --git a/.gitignore b/.gitignore index 1ff9b989f..8e64e73ab 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ logs/ # Pytest-cov .coverage + +# Jinja templates test output +tests/jinja_test_outputs/ diff --git a/assets/templates/README.md b/assets/templates/README.md new file mode 100644 index 000000000..b0deebc00 --- /dev/null +++ b/assets/templates/README.md @@ -0,0 +1,12 @@ +# Email Jinja Templates + +The directory contains the templates used in the automatic mails sent by Hyperion. +Each mail is based on the `base_mail.html` template. + +## Adding a new mail template + +To add a new mail template, simply copy the `custom_mail_template.html` and modify it. + +## Testing your template + +To test how the templates render, you can run the Python file `tests/template_tester.py`. diff --git a/assets/templates/account_exists_mail.html b/assets/templates/account_exists_mail.html index fc23099a2..712e41cdb 100644 --- a/assets/templates/account_exists_mail.html +++ b/assets/templates/account_exists_mail.html @@ -1,33 +1,23 @@ - +{% extends "base_mail.html" %} - - - - MyECL - Your account already exists! - +{% block title %}MyECL - Your account already exists!{% endblock %} - -

Ton compte MyECL existe déjà !

-

- Tu as demandé à créer un compte, mais ton adresse mail est déjà associée à un compte existant. Si tu as oublié ton mot de passe, tu peux utiliser la fonctionnalité de - mot de passe oublié. +{% block french_message %} +

Ton compte MyECL existe déjà !

+

+ Tu as demandé à créer un compte, mais ton adresse mail est déjà associée à un compte existant. + Si tu as oublié ton mot de passe, tu peux utiliser le réinitialiser en cliquant sur le lien suivant : + https://myecl.fr/forgot_password

-

Si tu n'es pas à l'origine de cette demande, c'est qu'un bon fyot a tenté de s'inscrire avec ton adresse mail... Bref tu peux ignorer ce message.

+

Si tu n'es pas à l'origine de cette demande, c'est qu'un bon fyot a tenté de s'inscrire avec ton adresse mail... Bref tu peux ignorer ce message.

+{% endblock %} -
- -

Your MyECL account already exists!

-

- You've asked to create an account, but your e-mail address is already linked to an existing account. If you've forgotten your password, you can use the - forgotten password feature. +{% block english_message %} +

Your MyECL account already exists!

+

+ You've asked to create an account, but your e-mail address is already linked to an existing account. + If you have forgotten your password, you can reset it by clicking on the following link: + https://myecl.fr/forgot_password

-

If you are not behind this request, it likely means that a fool has tried to sign up using your e-mail address... In short, you can ignore this message.

- -

-

Éclairement,

-
- - - - - \ No newline at end of file +

If you have not initiated this request, it likely means that some fool tried to sign up using your e-mail address... You can safely ignore this message.

+{% endblock %} diff --git a/assets/templates/activation_mail.html b/assets/templates/activation_mail.html index c4294ab85..c1b94cd3b 100644 --- a/assets/templates/activation_mail.html +++ b/assets/templates/activation_mail.html @@ -1,32 +1,18 @@ - +{% extends "base_mail.html" %} - - - - MyECL - Activate your account - +{% block title %}MyECL - Activate your account{% endblock %} - -

Bienvenue sur MyECL !

-

Pour continuer ton inscription, tu peux utiliser ce - lien unique. +{% block french_message %} +

Bienvenue sur MyECL !

+

Pour continuer ton inscription, clique sur le lien unique suivant : + {{ calypsso_activate_url }}

+{% endblock %} -
- -

Welcome on MyECL!

-

- To pursue your registration, you can use this - unique link. +{% block english_message %} +

Welcome to MyECL !

+

+ To complete your registration, click on the following one-time link : + {{ calypsso_activate_url }}

- -

-

Éclairement,

-
- - - - - - \ No newline at end of file +{% endblock %} diff --git a/assets/templates/base_mail.html b/assets/templates/base_mail.html new file mode 100644 index 000000000..cdbc9eb3d --- /dev/null +++ b/assets/templates/base_mail.html @@ -0,0 +1,27 @@ + + + + + + {% block title%}{% endblock %} + + + +
{% block french_message %} {% endblock %}
+
+ +
{% block english_message %} {% endblock %}
+ +

+ + + diff --git a/assets/templates/custom_mail_template.html b/assets/templates/custom_mail_template.html new file mode 100644 index 000000000..4198f1f9b --- /dev/null +++ b/assets/templates/custom_mail_template.html @@ -0,0 +1,9 @@ +{% extends "base_mail.html" %} + +{% block title %}{% endblock %} + +{% block french_message %} +{% endblock %} + +{% block english_message %} +{% endblock %} diff --git a/assets/templates/migration_mail.html b/assets/templates/migration_mail.html index faa51cec3..0db39c50f 100644 --- a/assets/templates/migration_mail.html +++ b/assets/templates/migration_mail.html @@ -1,31 +1,19 @@ - +{% extends "base_mail.html" %} - - - - MyECL - Confirm your new email address - +{% block title %}MyECL - Confirm your new email address{% endblock %} - -

Changement d'adresse mail MyECL

-

- Pour confirmer ta nouvelle adresse mail, tu peux utiliser ce - lien unique. +{% block french_message %} +

Changement d'adresse mail MyECL

+

+ Pour confirmer ta nouvelle adresse mail, tu peux utiliser le lien unique suivant : + {{ migration_link }}

+{% endblock %} -
- -

Changing your MyECL e-mail address

-

- To check your new e-mail address, you can use this - unique link. +{% block english_message %} +

Changing your MyECL e-mail address

+

+ To verify your new e-mail address, you can use the following one-time link : + {{ migration_link }}

- -

-

Éclairement,

-
- - - - - \ No newline at end of file +{% endblock %} diff --git a/assets/templates/migration_mail_already_used.html b/assets/templates/migration_mail_already_used.html index a387fa34c..f217e9fea 100644 --- a/assets/templates/migration_mail_already_used.html +++ b/assets/templates/migration_mail_already_used.html @@ -1,27 +1,13 @@ - +{% extends "base_mail.html" %} - - - - MyECL - Already used email address - +{% block title %}MyECL - Already used email address{% endblock %} - -

Changement d'adresse mail MyECL

-

Tu as demandé à modifier l'adresse mail de ton compte MyECL, mais celle-ci est déjà associée à un autre compte MyECL existant.

+{% block french_message %} +

Problème lors du changement d'adresse mail MyECL

+

L'adresse mail que tu as renseignée est déjà associée à un autre compte MyECL existant, rapproche-toi d'un Eclairman pour résoudre le problème.

+{% endblock %} -
- -

Changing your MyECL e-mail address

-

You've asked to change the e-mail address of your MyECL account, but it's already linked to another existing MyECL account.

- -

-

Éclairement,

-
- - - - - - \ No newline at end of file +{% block english_message %} +

Difficulties changing your MyECL e-mail address

+

Oops ! The email address you provided is already associated with another existing MyECL account. Please contact a member of Eclair to resolve this issue.

+{% endblock %} diff --git a/assets/templates/reset_mail.html b/assets/templates/reset_mail.html index 63a3df42d..28cf565ea 100644 --- a/assets/templates/reset_mail.html +++ b/assets/templates/reset_mail.html @@ -1,33 +1,19 @@ - +{% extends "base_mail.html" %} - - - - MyECL - Reset your password - +{% block title %}MyECL - Reset your password{% endblock %} - -

Réinitialisation de ton mot de passe MyECL

-

- Pour réinitialiser ton mot de passe, tu peux utiliser ce - lien unique. +{% block french_message %} +

Réinitialisation de ton mot de passe MyECL

+

+ Pour réinitialiser ton mot de passe, tu peux utiliser le lien unique suivant : + {{ calypsso_reset_url }}

+{% endblock %} -
- -

Reset your MyECL password

-

- To reset your password, you can use this - unique link. +{% block english_message %} +

Reset your MyECL password

+

+ To reset your password, you can use the following one-time link : + {{ calypsso_reset_url }}

- -

-

Éclairement,

-
- - - - - - \ No newline at end of file +{% endblock %} diff --git a/assets/templates/reset_mail_does_not_exist.html b/assets/templates/reset_mail_does_not_exist.html index 497416e7f..645df72b0 100644 --- a/assets/templates/reset_mail_does_not_exist.html +++ b/assets/templates/reset_mail_does_not_exist.html @@ -1,35 +1,21 @@ - +{% extends "base_mail.html" %} - - - - MyECL - Reset your password - +{% block title %}MyECL - Reset your password{% endblock %} - -

Réinitialisation de ton mot de passe MyECL impossible

-

- Il n'y as pas encore de compte MyECL associée à cette adresse email. Tu peux en créer un en utilisant ce lien : - - {{ calypsso_register_url }} - . -

+{% block french_message %} +

Réinitialisation de ton mot de passe MyECL impossible

+

+ Il n'y as pas encore de compte MyECL associée à cette adresse email. Tu peux + en créer un en utilisant ce lien : + {{ calypsso_register_url }} +

+{% endblock %} -
- -

Could not reset your MyECL password

-

- There is no MyECL account associated with this email address. You can create one using this link : - - {{ calypsso_register_url }} - . -

- -

-

Éclairement,

-
- - - - \ No newline at end of file +{% block english_message %} +

Difficulties resetting your MyECL password

+

+ There is currently no MyECL account linked to this email address. You can create + one using the following link : + {{ calypsso_register_url }} +

+{% endblock %} diff --git a/tests/template_tester.py b/tests/template_tester.py new file mode 100644 index 000000000..c9213f087 --- /dev/null +++ b/tests/template_tester.py @@ -0,0 +1,74 @@ +if __name__ == "__main__": + from pathlib import Path + + from jinja2 import Environment, FileSystemLoader + + # Please run from tests folder + # Initialize environnement with templates + path_to_file = Path(__file__) + env = Environment( + loader=FileSystemLoader(path_to_file.parents[1] / "assets/templates/"), + autoescape=True, + ) + + # Create output directory if it doesnt exist + directory = path_to_file.parents[0] / Path("jinja_test_outputs") + directory.mkdir(exist_ok=True) + + # Templates rendering + # URL are set to MyECL only to test that the links are working properly + template_account_exists_mail = env.get_template("account_exists_mail.html") + html_account_exists_mail = template_account_exists_mail.render() + file_account_exists_mail = directory / Path("test_account_exists_mail.html") + file_account_exists_mail.touch(exist_ok=True) + with file_account_exists_mail.open(mode="w") as f: + f.write(html_account_exists_mail) + + template_activation_mail = env.get_template("activation_mail.html") + html_activation_mail = template_activation_mail.render( + calypsso_activate_url="https://myecl.fr", + ) + file_activation_mail = directory / Path("test_activation_mail.html") + file_activation_mail.touch(exist_ok=True) + with file_activation_mail.open(mode="w") as f: + f.write(html_activation_mail) + + template_migration_mail = env.get_template("migration_mail.html") + html_migration_mail = template_migration_mail.render( + migration_link="https://myecl.fr", + ) + file_migration_mail = directory / Path("test_migration_mail.html") + file_migration_mail.touch(exist_ok=True) + with file_migration_mail.open(mode="w") as f: + f.write(html_migration_mail) + + template_migration_mail_already_used = env.get_template( + "migration_mail_already_used.html", + ) + html_migration_mail_already_used = template_migration_mail_already_used.render() + file_migration_mail_already_used = directory / Path( + "test_migration_mail_already_used.html", + ) + file_migration_mail_already_used.touch(exist_ok=True) + with file_migration_mail_already_used.open(mode="w") as f: + f.write(html_migration_mail_already_used) + + template_reset_mail = env.get_template("reset_mail.html") + html_reset_mail = template_reset_mail.render(calypsso_reset_url="https://myecl.fr") + file_reset_mail = directory / Path("test_reset_mail.html") + file_reset_mail.touch(exist_ok=True) + with file_reset_mail.open(mode="w") as f: + f.write(html_reset_mail) + + template_reset_mail_does_not_exist = env.get_template( + "reset_mail_does_not_exist.html", + ) + html_reset_mail_does_not_exist = template_reset_mail_does_not_exist.render( + calypsso_register_url="https://myecl.fr", + ) + file_reset_mail_does_not_exist = directory / Path( + "test_reset_mail_does_not_exist.html", + ) + file_reset_mail_does_not_exist.touch(exist_ok=True) + with file_reset_mail_does_not_exist.open(mode="w") as f: + f.write(html_reset_mail_does_not_exist)