diff --git a/fittrackee/emails/tasks.py b/fittrackee/emails/tasks.py index 3fd3462f..8be6608b 100644 --- a/fittrackee/emails/tasks.py +++ b/fittrackee/emails/tasks.py @@ -51,3 +51,13 @@ def account_confirmation_email(user: Dict, email_data: Dict) -> None: recipient=user['email'], data=email_data, ) + + +@dramatiq.actor(queue_name='fittrackee_emails') +def data_export_email(user: Dict, email_data: Dict) -> None: + email_service.send( + template='data_export_ready', + lang=user['language'], + recipient=user['email'], + data=email_data, + ) diff --git a/fittrackee/emails/templates/data_export_ready/body.html b/fittrackee/emails/templates/data_export_ready/body.html new file mode 100644 index 00000000..af0437be --- /dev/null +++ b/fittrackee/emails/templates/data_export_ready/body.html @@ -0,0 +1,26 @@ +{% extends "layout.html" %} +{% block title %}{{ _('Your archive is ready to be downloaded') }}{% endblock %} +{% block preheader %}{{ _('A download link is available in your account.') }}{% endblock %} +{% block content %}

{{ _('You have requested an export of your account on FitTrackee.') }} {{ _('The archive is now ready to be downloaded from your account.') }}

+ + + + + {% endblock %} +{% block not_initiated %}{{ _("If you did not request the export, please change your password immediately or contact your administrator if your account is locked.") }}{% endblock %} +{% block url_to_paste %} + + + + {% endblock %} diff --git a/fittrackee/emails/templates/data_export_ready/body.txt b/fittrackee/emails/templates/data_export_ready/body.txt new file mode 100644 index 00000000..3745df66 --- /dev/null +++ b/fittrackee/emails/templates/data_export_ready/body.txt @@ -0,0 +1,5 @@ +{% extends "layout.txt" %}{% block content %}{{ _('You have requested an export of your account on FitTrackee.') }} +{{ _('The archive is now ready to be downloaded from your account.') }} + +{{ _('Download your archive') }}: {{ account_url }} +{{ _('If you did not request the export, please change your password immediately or contact your administrator if your account is locked.') }}{% endblock %} \ No newline at end of file diff --git a/fittrackee/emails/templates/data_export_ready/subject.txt b/fittrackee/emails/templates/data_export_ready/subject.txt new file mode 100644 index 00000000..874f36a1 --- /dev/null +++ b/fittrackee/emails/templates/data_export_ready/subject.txt @@ -0,0 +1 @@ +FitTrackee - {{ _('Your archive is ready to be downloaded') }} \ No newline at end of file diff --git a/fittrackee/emails/translations/de/LC_MESSAGES/messages.mo b/fittrackee/emails/translations/de/LC_MESSAGES/messages.mo index e3f338a8..d8dda478 100644 Binary files a/fittrackee/emails/translations/de/LC_MESSAGES/messages.mo and b/fittrackee/emails/translations/de/LC_MESSAGES/messages.mo differ diff --git a/fittrackee/emails/translations/de/LC_MESSAGES/messages.po b/fittrackee/emails/translations/de/LC_MESSAGES/messages.po index 229b7b44..42838550 100644 --- a/fittrackee/emails/translations/de/LC_MESSAGES/messages.po +++ b/fittrackee/emails/translations/de/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2022-07-03 07:58+0200\n" +"POT-Creation-Date: 2023-03-04 10:33+0100\n" "PO-Revision-Date: 2022-07-04 21:17+0000\n" "Last-Translator: J. Lavoie \n" "Language: de\n" @@ -84,6 +84,7 @@ msgstr "" "E-Mail bitte." #: fittrackee/emails/templates/account_confirmation/body.html:22 +#: fittrackee/emails/templates/data_export_ready/body.html:22 #: fittrackee/emails/templates/email_update_to_new_email/body.html:22 #: fittrackee/emails/templates/password_reset_request/body.html:24 msgid "" @@ -97,6 +98,37 @@ msgstr "" msgid "Use the link below to confirm your address email." msgstr "Verwende den unteren Link, um deine E-Mail-Adresse zu bestätigen." +#: fittrackee/emails/templates/data_export_ready/body.html:2 +#: fittrackee/emails/templates/data_export_ready/subject.txt:1 +msgid "Your archive is ready to be downloaded" +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:3 +msgid "A download link is available in your account." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:1 +msgid "You have requested an export of your account on FitTrackee." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:2 +msgid "The archive is now ready to be downloaded from your account." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:11 +#: fittrackee/emails/templates/data_export_ready/body.txt:4 +msgid "Download your archive" +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:18 +#: fittrackee/emails/templates/data_export_ready/body.txt:5 +msgid "" +"If you did not request the export, please change your password " +"immediately or contact your administrator if your account is locked." +msgstr "" + #: fittrackee/emails/templates/email_update_to_current_email/body.html:2 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 msgid "Email changed" diff --git a/fittrackee/emails/translations/en/LC_MESSAGES/messages.mo b/fittrackee/emails/translations/en/LC_MESSAGES/messages.mo index 596301af..213c34d9 100644 Binary files a/fittrackee/emails/translations/en/LC_MESSAGES/messages.mo and b/fittrackee/emails/translations/en/LC_MESSAGES/messages.mo differ diff --git a/fittrackee/emails/translations/en/LC_MESSAGES/messages.po b/fittrackee/emails/translations/en/LC_MESSAGES/messages.po index 84fb2306..23829c50 100644 --- a/fittrackee/emails/translations/en/LC_MESSAGES/messages.po +++ b/fittrackee/emails/translations/en/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2022-07-03 07:58+0200\n" +"POT-Creation-Date: 2023-03-04 10:33+0100\n" "PO-Revision-Date: 2022-07-02 18:25+0200\n" "Last-Translator: FULL NAME \n" "Language: en\n" @@ -83,6 +83,7 @@ msgstr "" "email." #: fittrackee/emails/templates/account_confirmation/body.html:22 +#: fittrackee/emails/templates/data_export_ready/body.html:22 #: fittrackee/emails/templates/email_update_to_new_email/body.html:22 #: fittrackee/emails/templates/password_reset_request/body.html:24 msgid "" @@ -96,6 +97,39 @@ msgstr "" msgid "Use the link below to confirm your address email." msgstr "Use the link below to confirm your address email." +#: fittrackee/emails/templates/data_export_ready/body.html:2 +#: fittrackee/emails/templates/data_export_ready/subject.txt:1 +msgid "Your archive is ready to be downloaded" +msgstr "Your archive is ready to be downloaded" + +#: fittrackee/emails/templates/data_export_ready/body.html:3 +msgid "A download link is available in your account." +msgstr "A download link is available in your account." + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:1 +msgid "You have requested an export of your account on FitTrackee." +msgstr "You have requested an export of your account on FitTrackee." + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:2 +msgid "The archive is now ready to be downloaded from your account." +msgstr "The archive is now ready to be downloaded from your account." + +#: fittrackee/emails/templates/data_export_ready/body.html:11 +#: fittrackee/emails/templates/data_export_ready/body.txt:4 +msgid "Download your archive" +msgstr "Download your archive" + +#: fittrackee/emails/templates/data_export_ready/body.html:18 +#: fittrackee/emails/templates/data_export_ready/body.txt:5 +msgid "" +"If you did not request the export, please change your password " +"immediately or contact your administrator if your account is locked." +msgstr "" +"If you did not request the export, please change your password " +"immediately or contact your administrator if your account is locked." + #: fittrackee/emails/templates/email_update_to_current_email/body.html:2 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 msgid "Email changed" diff --git a/fittrackee/emails/translations/fr/LC_MESSAGES/messages.mo b/fittrackee/emails/translations/fr/LC_MESSAGES/messages.mo index e2868a61..7955ddde 100644 Binary files a/fittrackee/emails/translations/fr/LC_MESSAGES/messages.mo and b/fittrackee/emails/translations/fr/LC_MESSAGES/messages.mo differ diff --git a/fittrackee/emails/translations/fr/LC_MESSAGES/messages.po b/fittrackee/emails/translations/fr/LC_MESSAGES/messages.po index 7cf165a0..004bfe43 100644 --- a/fittrackee/emails/translations/fr/LC_MESSAGES/messages.po +++ b/fittrackee/emails/translations/fr/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2022-07-03 07:58+0200\n" +"POT-Creation-Date: 2023-03-04 10:33+0100\n" "PO-Revision-Date: 2022-07-04 21:17+0000\n" "Last-Translator: J. Lavoie \n" "Language: fr\n" @@ -84,6 +84,7 @@ msgstr "" "ignorer ce courriel." #: fittrackee/emails/templates/account_confirmation/body.html:22 +#: fittrackee/emails/templates/data_export_ready/body.html:22 #: fittrackee/emails/templates/email_update_to_new_email/body.html:22 #: fittrackee/emails/templates/password_reset_request/body.html:24 msgid "" @@ -97,6 +98,40 @@ msgstr "" msgid "Use the link below to confirm your address email." msgstr "Cliquez sur le lien ci-dessous pour confirmer votre adresse électronique." +#: fittrackee/emails/templates/data_export_ready/body.html:2 +#: fittrackee/emails/templates/data_export_ready/subject.txt:1 +msgid "Your archive is ready to be downloaded" +msgstr "Votre archive est prête à être téléchargée" + +#: fittrackee/emails/templates/data_export_ready/body.html:3 +msgid "A download link is available in your account." +msgstr "Un lien de téléchargement est disponible dans votre compte." + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:1 +msgid "You have requested an export of your account on FitTrackee." +msgstr "Vous avez demandé un export des données de votre compte sur FitTrackee." + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:2 +msgid "The archive is now ready to be downloaded from your account." +msgstr "L'archive est maintenant prête à être téléchargée depuis votre compte." + +#: fittrackee/emails/templates/data_export_ready/body.html:11 +#: fittrackee/emails/templates/data_export_ready/body.txt:4 +msgid "Download your archive" +msgstr "Télécharger votre archive" + +#: fittrackee/emails/templates/data_export_ready/body.html:18 +#: fittrackee/emails/templates/data_export_ready/body.txt:5 +msgid "" +"If you did not request the export, please change your password " +"immediately or contact your administrator if your account is locked." +msgstr "" +"Si vous n'êtes pas à l'origine de cette demande, veuillez changer " +"votre mot de passe immédiatement ou contacter l'administrateur si votre " +"compte est bloqué." + #: fittrackee/emails/templates/email_update_to_current_email/body.html:2 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 msgid "Email changed" diff --git a/fittrackee/emails/translations/it/LC_MESSAGES/messages.mo b/fittrackee/emails/translations/it/LC_MESSAGES/messages.mo index ffcad1f4..b1c6ada7 100644 Binary files a/fittrackee/emails/translations/it/LC_MESSAGES/messages.mo and b/fittrackee/emails/translations/it/LC_MESSAGES/messages.mo differ diff --git a/fittrackee/emails/translations/it/LC_MESSAGES/messages.po b/fittrackee/emails/translations/it/LC_MESSAGES/messages.po index 652aa66f..dfaad04f 100644 --- a/fittrackee/emails/translations/it/LC_MESSAGES/messages.po +++ b/fittrackee/emails/translations/it/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2022-07-03 07:58+0200\n" +"POT-Creation-Date: 2023-03-04 10:33+0100\n" "PO-Revision-Date: 2022-12-12 19:48+0000\n" "Last-Translator: Donato Perruso \n" "Language: it\n" @@ -84,6 +84,7 @@ msgstr "" "ignora quest'email." #: fittrackee/emails/templates/account_confirmation/body.html:22 +#: fittrackee/emails/templates/data_export_ready/body.html:22 #: fittrackee/emails/templates/email_update_to_new_email/body.html:22 #: fittrackee/emails/templates/password_reset_request/body.html:24 msgid "" @@ -97,6 +98,37 @@ msgstr "" msgid "Use the link below to confirm your address email." msgstr "Usa il link qui sotto per confermare la tua email." +#: fittrackee/emails/templates/data_export_ready/body.html:2 +#: fittrackee/emails/templates/data_export_ready/subject.txt:1 +msgid "Your archive is ready to be downloaded" +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:3 +msgid "A download link is available in your account." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:1 +msgid "You have requested an export of your account on FitTrackee." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:2 +msgid "The archive is now ready to be downloaded from your account." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:11 +#: fittrackee/emails/templates/data_export_ready/body.txt:4 +msgid "Download your archive" +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:18 +#: fittrackee/emails/templates/data_export_ready/body.txt:5 +msgid "" +"If you did not request the export, please change your password " +"immediately or contact your administrator if your account is locked." +msgstr "" + #: fittrackee/emails/templates/email_update_to_current_email/body.html:2 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 msgid "Email changed" diff --git a/fittrackee/emails/translations/nb/LC_MESSAGES/messages.mo b/fittrackee/emails/translations/nb/LC_MESSAGES/messages.mo index 50f367c9..e67bf77a 100644 Binary files a/fittrackee/emails/translations/nb/LC_MESSAGES/messages.mo and b/fittrackee/emails/translations/nb/LC_MESSAGES/messages.mo differ diff --git a/fittrackee/emails/translations/nb/LC_MESSAGES/messages.po b/fittrackee/emails/translations/nb/LC_MESSAGES/messages.po index 2e28daf4..1604c01e 100644 --- a/fittrackee/emails/translations/nb/LC_MESSAGES/messages.po +++ b/fittrackee/emails/translations/nb/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2022-07-03 07:58+0200\n" +"POT-Creation-Date: 2023-03-04 10:33+0100\n" "PO-Revision-Date: 2022-10-31 10:19+0100\n" "Last-Translator: FULL NAME \n" "Language: nb\n" @@ -79,6 +79,7 @@ msgid "" msgstr "" #: fittrackee/emails/templates/account_confirmation/body.html:22 +#: fittrackee/emails/templates/data_export_ready/body.html:22 #: fittrackee/emails/templates/email_update_to_new_email/body.html:22 #: fittrackee/emails/templates/password_reset_request/body.html:24 msgid "" @@ -90,6 +91,37 @@ msgstr "" msgid "Use the link below to confirm your address email." msgstr "" +#: fittrackee/emails/templates/data_export_ready/body.html:2 +#: fittrackee/emails/templates/data_export_ready/subject.txt:1 +msgid "Your archive is ready to be downloaded" +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:3 +msgid "A download link is available in your account." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:1 +msgid "You have requested an export of your account on FitTrackee." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:2 +msgid "The archive is now ready to be downloaded from your account." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:11 +#: fittrackee/emails/templates/data_export_ready/body.txt:4 +msgid "Download your archive" +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:18 +#: fittrackee/emails/templates/data_export_ready/body.txt:5 +msgid "" +"If you did not request the export, please change your password " +"immediately or contact your administrator if your account is locked." +msgstr "" + #: fittrackee/emails/templates/email_update_to_current_email/body.html:2 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 msgid "Email changed" diff --git a/fittrackee/emails/translations/nl/LC_MESSAGES/messages.mo b/fittrackee/emails/translations/nl/LC_MESSAGES/messages.mo index c881e130..62fbc2fe 100644 Binary files a/fittrackee/emails/translations/nl/LC_MESSAGES/messages.mo and b/fittrackee/emails/translations/nl/LC_MESSAGES/messages.mo differ diff --git a/fittrackee/emails/translations/nl/LC_MESSAGES/messages.po b/fittrackee/emails/translations/nl/LC_MESSAGES/messages.po index e5d01cff..75ba02c5 100644 --- a/fittrackee/emails/translations/nl/LC_MESSAGES/messages.po +++ b/fittrackee/emails/translations/nl/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2022-07-03 07:58+0200\n" +"POT-Creation-Date: 2023-03-04 10:33+0100\n" "PO-Revision-Date: 2022-11-29 00:47+0000\n" "Last-Translator: bjornclauw \n" "Language: nl\n" @@ -82,6 +82,7 @@ msgid "" msgstr "Indien u deze account niet hebt aangemaakt, gelieve deze email te negeren." #: fittrackee/emails/templates/account_confirmation/body.html:22 +#: fittrackee/emails/templates/data_export_ready/body.html:22 #: fittrackee/emails/templates/email_update_to_new_email/body.html:22 #: fittrackee/emails/templates/password_reset_request/body.html:24 msgid "" @@ -95,6 +96,37 @@ msgstr "" msgid "Use the link below to confirm your address email." msgstr "Gebruik de onderstaande link om uw email adres te bevestigen." +#: fittrackee/emails/templates/data_export_ready/body.html:2 +#: fittrackee/emails/templates/data_export_ready/subject.txt:1 +msgid "Your archive is ready to be downloaded" +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:3 +msgid "A download link is available in your account." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:1 +msgid "You have requested an export of your account on FitTrackee." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:2 +msgid "The archive is now ready to be downloaded from your account." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:11 +#: fittrackee/emails/templates/data_export_ready/body.txt:4 +msgid "Download your archive" +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:18 +#: fittrackee/emails/templates/data_export_ready/body.txt:5 +msgid "" +"If you did not request the export, please change your password " +"immediately or contact your administrator if your account is locked." +msgstr "" + #: fittrackee/emails/templates/email_update_to_current_email/body.html:2 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 msgid "Email changed" diff --git a/fittrackee/tests/emails/template_results/email_data_export_ready.py b/fittrackee/tests/emails/template_results/email_data_export_ready.py new file mode 100644 index 00000000..61bb75ac --- /dev/null +++ b/fittrackee/tests/emails/template_results/email_data_export_ready.py @@ -0,0 +1,167 @@ +# flake8: noqa + +expected_en_text_body = """Hi test, + +You have requested an export of your account on FitTrackee. +The archive is now ready to be downloaded from your account. + +Download your archive: http://localhost/profile/edit/account +If you did not request the export, please change your password immediately or contact your administrator if your account is locked. + +Thanks, +The FitTrackee Team +http://localhost""" + +expected_fr_text_body = """Bonjour test, + +Vous avez demandé un export des données de votre compte sur FitTrackee. +L'archive est maintenant prête à être téléchargée depuis votre compte. + +Télécharger votre archive: http://localhost/profile/edit/account +Si vous n'êtes pas à l'origine de cette demande, veuillez changer votre mot de passe immédiatement ou contacter l'administrateur si votre compte est bloqué. + +Merci, +L'équipe FitTrackee +http://localhost""" + +expected_en_html_body = """ + A download link is available in your account. + + + + + + +""" + +expected_fr_html_body = """ + Un lien de téléchargement est disponible dans votre compte. + + + + + + +""" diff --git a/fittrackee/tests/emails/test_email_data_export_ready.py b/fittrackee/tests/emails/test_email_data_export_ready.py new file mode 100644 index 00000000..ecced053 --- /dev/null +++ b/fittrackee/tests/emails/test_email_data_export_ready.py @@ -0,0 +1,89 @@ +import pytest +from flask import Flask + +from fittrackee.emails.email import EmailTemplate + +from .template_results.email_data_export_ready import ( + expected_en_html_body, + expected_en_text_body, + expected_fr_html_body, + expected_fr_text_body, +) + + +class TestEmailTemplateForDataExport: + EMAIL_DATA = { + 'username': 'test', + 'account_url': 'http://localhost/profile/edit/account', + 'fittrackee_url': 'http://localhost', + } + + @pytest.mark.parametrize( + 'lang, expected_subject', + [ + ('en', 'FitTrackee - Your archive is ready to be downloaded'), + ('fr', 'FitTrackee - Votre archive est prête à être téléchargée'), + ], + ) + def test_it_gets_subject( + self, app: Flask, lang: str, expected_subject: str + ) -> None: + email_template = EmailTemplate( + app.config['TEMPLATES_FOLDER'], + app.config['TRANSLATIONS_FOLDER'], + app.config['LANGUAGES'], + ) + + subject = email_template.get_content( + 'data_export_ready', lang, 'subject.txt', {} + ) + + assert subject == expected_subject + + @pytest.mark.parametrize( + 'lang, expected_text_body', + [ + ('en', expected_en_text_body), + ('fr', expected_fr_text_body), + ], + ) + def test_it_gets_text_body( + self, app: Flask, lang: str, expected_text_body: str + ) -> None: + email_template = EmailTemplate( + app.config['TEMPLATES_FOLDER'], + app.config['TRANSLATIONS_FOLDER'], + app.config['LANGUAGES'], + ) + + text_body = email_template.get_content( + 'data_export_ready', lang, 'body.txt', self.EMAIL_DATA + ) + + assert text_body == expected_text_body + + def test_it_gets_en_html_body(self, app: Flask) -> None: + email_template = EmailTemplate( + app.config['TEMPLATES_FOLDER'], + app.config['TRANSLATIONS_FOLDER'], + app.config['LANGUAGES'], + ) + + text_body = email_template.get_content( + 'data_export_ready', 'en', 'body.html', self.EMAIL_DATA + ) + + assert expected_en_html_body in text_body + + def test_it_gets_fr_html_body(self, app: Flask) -> None: + email_template = EmailTemplate( + app.config['TEMPLATES_FOLDER'], + app.config['TRANSLATIONS_FOLDER'], + app.config['LANGUAGES'], + ) + + text_body = email_template.get_content( + 'data_export_ready', 'fr', 'body.html', self.EMAIL_DATA + ) + + assert expected_fr_html_body in text_body diff --git a/fittrackee/tests/emails/test_email_template_email_update.py b/fittrackee/tests/emails/test_email_template_email_update.py index 9893ee50..cd445165 100644 --- a/fittrackee/tests/emails/test_email_template_email_update.py +++ b/fittrackee/tests/emails/test_email_template_email_update.py @@ -105,11 +105,6 @@ class TestEmailTemplateForEmailUpdateToCurrentEmail: 'email_update_to_current_email', 'fr', 'body.html', self.EMAIL_DATA ) - print('') - print(expected_fr_current_email_html_body) - print('') - print(text_body) - assert expected_fr_current_email_html_body in text_body diff --git a/fittrackee/tests/fixtures/fixtures_emails.py b/fittrackee/tests/fixtures/fixtures_emails.py index fac3441a..f40894ab 100644 --- a/fittrackee/tests/fixtures/fixtures_emails.py +++ b/fittrackee/tests/fixtures/fixtures_emails.py @@ -52,3 +52,9 @@ def user_email_updated_to_new_address_mock() -> Iterator[MagicMock]: def account_confirmation_email_mock() -> Iterator[MagicMock]: with patch('fittrackee.users.auth.account_confirmation_email') as mock: yield mock + + +@pytest.fixture() +def data_export_email_mock() -> Iterator[MagicMock]: + with patch('fittrackee.users.export_data.data_export_email') as mock: + yield mock diff --git a/fittrackee/tests/users/test_users_export_data.py b/fittrackee/tests/users/test_users_export_data.py index 85e783be..36b0c494 100644 --- a/fittrackee/tests/users/test_users_export_data.py +++ b/fittrackee/tests/users/test_users_export_data.py @@ -375,6 +375,7 @@ class TestExportUserData: self, generate_archive_mock: Mock, logger_mock: Mock, + data_export_email_mock: Mock, app: Flask, user_1: User, ) -> None: @@ -414,3 +415,53 @@ class TestExportUserData: assert export_request.updated_at is not None assert export_request.file_name is None assert export_request.file_size is None + + def test_it_does_not_call_data_export_email_when_export_failed( + self, + generate_archive_mock: Mock, + logger_mock: Mock, + data_export_email_mock: Mock, + app: Flask, + user_1: User, + ) -> None: + export_request = UserDataExport(user_id=user_1.id) + db.session.add(export_request) + db.session.commit() + generate_archive_mock.return_value = (None, None) + + export_user_data(export_request_id=export_request.id) + + data_export_email_mock.send.assert_not_called() + + def test_it_calls_data_export_email_when_export_is_successful( + self, + generate_archive_mock: Mock, + logger_mock: Mock, + data_export_email_mock: Mock, + app: Flask, + user_1: User, + ) -> None: + export_request = UserDataExport(user_id=user_1.id) + db.session.add(export_request) + db.session.commit() + archive_name = random_string() + generate_archive_mock.return_value = (random_string(), archive_name) + archive_size = random_int() + + with patch( + 'fittrackee.users.export_data.os.path.getsize', + return_value=archive_size, + ): + export_user_data(export_request_id=export_request.id) + + data_export_email_mock.send.assert_called_once_with( + { + 'language': 'en', + 'email': user_1.email, + }, + { + 'username': user_1.username, + 'account_url': 'http://0.0.0.0:5000/profile/edit/account', + 'fittrackee_url': 'http://0.0.0.0:5000', + }, + ) diff --git a/fittrackee/users/auth.py b/fittrackee/users/auth.py index 06a2b570..1727b06c 100644 --- a/fittrackee/users/auth.py +++ b/fittrackee/users/auth.py @@ -2,7 +2,7 @@ import datetime import os import re import secrets -from typing import Dict, Optional, Tuple, Union +from typing import Dict, Tuple, Union import jwt from flask import ( @@ -43,6 +43,7 @@ from fittrackee.workouts.models import Sport from .models import BlacklistedToken, User, UserDataExport, UserSportPreference from .tasks import export_data from .utils.controls import check_password, is_valid_email, register_controls +from .utils.language import get_language from .utils.token import decode_user_token auth_blueprint = Blueprint('auth', __name__) @@ -51,13 +52,6 @@ HEX_COLOR_REGEX = regex = "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$" NOT_FOUND_MESSAGE = 'the requested URL was not found on the server' -def get_language(language: Optional[str]) -> str: - # Note: some users may not have language preferences set - if not language or language not in current_app.config['LANGUAGES']: - language = 'en' - return language - - def send_account_confirmation_email(user: User) -> None: if current_app.config['CAN_SEND_EMAILS']: ui_url = current_app.config['UI_URL'] diff --git a/fittrackee/users/export_data.py b/fittrackee/users/export_data.py index 00472ed4..34fa463e 100644 --- a/fittrackee/users/export_data.py +++ b/fittrackee/users/export_data.py @@ -4,10 +4,14 @@ import secrets from typing import Dict, List, Optional, Tuple, Union from zipfile import ZipFile +from flask import current_app + from fittrackee import appLog, db +from fittrackee.emails.tasks import data_export_email from fittrackee.files import get_absolute_file_path from .models import User, UserDataExport +from .utils.language import get_language class UserDataExporter: @@ -108,4 +112,19 @@ def export_user_data(export_request_id: int) -> None: if archive_file_name and archive_file_path: export_request.file_name = archive_file_name export_request.file_size = os.path.getsize(archive_file_path) - db.session.commit() + db.session.commit() + + if current_app.config['CAN_SEND_EMAILS']: + ui_url = current_app.config['UI_URL'] + email_data = { + 'username': user.username, + 'fittrackee_url': ui_url, + 'account_url': f'{ui_url}/profile/edit/account', + } + user_data = { + 'language': get_language(user.language), + 'email': user.email, + } + data_export_email.send(user_data, email_data) + else: + db.session.commit() diff --git a/fittrackee/users/users.py b/fittrackee/users/users.py index c5801c23..73a02d07 100644 --- a/fittrackee/users/users.py +++ b/fittrackee/users/users.py @@ -24,10 +24,10 @@ from fittrackee.responses import ( from fittrackee.utils import get_readable_duration from fittrackee.workouts.models import Record, Workout, WorkoutSegment -from .auth import get_language from .exceptions import InvalidEmailException, UserNotFoundException from .models import User, UserDataExport, UserSportPreference from .utils.admin import UserManagerService +from .utils.language import get_language users_blueprint = Blueprint('users', __name__) diff --git a/fittrackee/users/utils/language.py b/fittrackee/users/utils/language.py new file mode 100644 index 00000000..a9b42a00 --- /dev/null +++ b/fittrackee/users/utils/language.py @@ -0,0 +1,10 @@ +from typing import Optional + +from flask import current_app + + +def get_language(language: Optional[str]) -> str: + # Note: some users may not have language preferences set + if not language or language not in current_app.config['LANGUAGES']: + language = 'en' + return language diff --git a/messages.pot b/messages.pot index 621e08bb..6f7e87db 100644 --- a/messages.pot +++ b/messages.pot @@ -1,21 +1,21 @@ # Translations template for PROJECT. -# Copyright (C) 2022 ORGANIZATION +# Copyright (C) 2023 ORGANIZATION # This file is distributed under the same license as the PROJECT project. -# FIRST AUTHOR , 2022. +# FIRST AUTHOR , 2023. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2022-07-03 07:58+0200\n" +"POT-Creation-Date: 2023-03-04 10:33+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.10.3\n" +"Generated-By: Babel 2.11.0\n" #: fittrackee/emails/templates/layout.html:215 #: fittrackee/emails/templates/layout.txt:1 @@ -78,6 +78,7 @@ msgid "" msgstr "" #: fittrackee/emails/templates/account_confirmation/body.html:22 +#: fittrackee/emails/templates/data_export_ready/body.html:22 #: fittrackee/emails/templates/email_update_to_new_email/body.html:22 #: fittrackee/emails/templates/password_reset_request/body.html:24 msgid "" @@ -89,6 +90,37 @@ msgstr "" msgid "Use the link below to confirm your address email." msgstr "" +#: fittrackee/emails/templates/data_export_ready/body.html:2 +#: fittrackee/emails/templates/data_export_ready/subject.txt:1 +msgid "Your archive is ready to be downloaded" +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:3 +msgid "A download link is available in your account." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:1 +msgid "You have requested an export of your account on FitTrackee." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:4 +#: fittrackee/emails/templates/data_export_ready/body.txt:2 +msgid "The archive is now ready to be downloaded from your account." +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:11 +#: fittrackee/emails/templates/data_export_ready/body.txt:4 +msgid "Download your archive" +msgstr "" + +#: fittrackee/emails/templates/data_export_ready/body.html:18 +#: fittrackee/emails/templates/data_export_ready/body.txt:5 +msgid "" +"If you did not request the export, please change your password " +"immediately or contact your administrator if your account is locked." +msgstr "" + #: fittrackee/emails/templates/email_update_to_current_email/body.html:2 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 msgid "Email changed"