API - send an email when data export is successful

This commit is contained in:
Sam 2023-03-04 10:49:25 +01:00
parent 32f358b8cb
commit 06d4a53fbb
26 changed files with 627 additions and 25 deletions

View File

@ -51,3 +51,13 @@ def account_confirmation_email(user: Dict, email_data: Dict) -> None:
recipient=user['email'], recipient=user['email'],
data=email_data, 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,
)

View File

@ -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 %}<p>{{ _('You have requested an export of your account on FitTrackee.') }} {{ _('The archive is now ready to be downloaded from your account.') }}</p>
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tr>
<td align="center">
<a href="{{account_url}}" class="f-fallback button button--green" target="_blank">{{ _('Download your archive') }}</a>
</td>
</tr>
</table>
</td>
</tr>
</table>{% 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 %}<table class="body-sub" role="presentation">
<tr>
<td>
<p class="f-fallback sub">{{ _("If you're having trouble with the button above, copy and paste the URL below into your web browser.") }}</p>
<p class="f-fallback sub">{{account_url}}</p>
</td>
</tr>
</table>{% endblock %}

View File

@ -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 %}

View File

@ -0,0 +1 @@
FitTrackee - {{ _('Your archive is ready to be downloaded') }}

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\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" "PO-Revision-Date: 2022-07-04 21:17+0000\n"
"Last-Translator: J. Lavoie <j.lavoie@net-c.ca>\n" "Last-Translator: J. Lavoie <j.lavoie@net-c.ca>\n"
"Language: de\n" "Language: de\n"
@ -84,6 +84,7 @@ msgstr ""
"E-Mail bitte." "E-Mail bitte."
#: fittrackee/emails/templates/account_confirmation/body.html:22 #: 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/email_update_to_new_email/body.html:22
#: fittrackee/emails/templates/password_reset_request/body.html:24 #: fittrackee/emails/templates/password_reset_request/body.html:24
msgid "" msgid ""
@ -97,6 +98,37 @@ msgstr ""
msgid "Use the link below to confirm your address email." msgid "Use the link below to confirm your address email."
msgstr "Verwende den unteren Link, um deine E-Mail-Adresse zu bestätigen." 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/body.html:2
#: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1
msgid "Email changed" msgid "Email changed"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\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" "PO-Revision-Date: 2022-07-02 18:25+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n" "Language: en\n"
@ -83,6 +83,7 @@ msgstr ""
"email." "email."
#: fittrackee/emails/templates/account_confirmation/body.html:22 #: 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/email_update_to_new_email/body.html:22
#: fittrackee/emails/templates/password_reset_request/body.html:24 #: fittrackee/emails/templates/password_reset_request/body.html:24
msgid "" msgid ""
@ -96,6 +97,39 @@ msgstr ""
msgid "Use the link below to confirm your address email." msgid "Use the link below to confirm your address email."
msgstr "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/body.html:2
#: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1
msgid "Email changed" msgid "Email changed"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\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" "PO-Revision-Date: 2022-07-04 21:17+0000\n"
"Last-Translator: J. Lavoie <j.lavoie@net-c.ca>\n" "Last-Translator: J. Lavoie <j.lavoie@net-c.ca>\n"
"Language: fr\n" "Language: fr\n"
@ -84,6 +84,7 @@ msgstr ""
"ignorer ce courriel." "ignorer ce courriel."
#: fittrackee/emails/templates/account_confirmation/body.html:22 #: 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/email_update_to_new_email/body.html:22
#: fittrackee/emails/templates/password_reset_request/body.html:24 #: fittrackee/emails/templates/password_reset_request/body.html:24
msgid "" msgid ""
@ -97,6 +98,40 @@ msgstr ""
msgid "Use the link below to confirm your address email." msgid "Use the link below to confirm your address email."
msgstr "Cliquez sur le lien ci-dessous pour confirmer votre adresse électronique." 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/body.html:2
#: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1
msgid "Email changed" msgid "Email changed"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\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" "PO-Revision-Date: 2022-12-12 19:48+0000\n"
"Last-Translator: Donato Perruso <dperruso@protonmail.com>\n" "Last-Translator: Donato Perruso <dperruso@protonmail.com>\n"
"Language: it\n" "Language: it\n"
@ -84,6 +84,7 @@ msgstr ""
"ignora quest'email." "ignora quest'email."
#: fittrackee/emails/templates/account_confirmation/body.html:22 #: 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/email_update_to_new_email/body.html:22
#: fittrackee/emails/templates/password_reset_request/body.html:24 #: fittrackee/emails/templates/password_reset_request/body.html:24
msgid "" msgid ""
@ -97,6 +98,37 @@ msgstr ""
msgid "Use the link below to confirm your address email." msgid "Use the link below to confirm your address email."
msgstr "Usa il link qui sotto per confermare la tua 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/body.html:2
#: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1
msgid "Email changed" msgid "Email changed"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\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" "PO-Revision-Date: 2022-10-31 10:19+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: nb\n" "Language: nb\n"
@ -79,6 +79,7 @@ msgid ""
msgstr "" msgstr ""
#: fittrackee/emails/templates/account_confirmation/body.html:22 #: 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/email_update_to_new_email/body.html:22
#: fittrackee/emails/templates/password_reset_request/body.html:24 #: fittrackee/emails/templates/password_reset_request/body.html:24
msgid "" msgid ""
@ -90,6 +91,37 @@ msgstr ""
msgid "Use the link below to confirm your address email." msgid "Use the link below to confirm your address email."
msgstr "" 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/body.html:2
#: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1
msgid "Email changed" msgid "Email changed"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\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" "PO-Revision-Date: 2022-11-29 00:47+0000\n"
"Last-Translator: bjornclauw <bjorn.clauw.1@gmail.com>\n" "Last-Translator: bjornclauw <bjorn.clauw.1@gmail.com>\n"
"Language: nl\n" "Language: nl\n"
@ -82,6 +82,7 @@ msgid ""
msgstr "Indien u deze account niet hebt aangemaakt, gelieve deze email te negeren." msgstr "Indien u deze account niet hebt aangemaakt, gelieve deze email te negeren."
#: fittrackee/emails/templates/account_confirmation/body.html:22 #: 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/email_update_to_new_email/body.html:22
#: fittrackee/emails/templates/password_reset_request/body.html:24 #: fittrackee/emails/templates/password_reset_request/body.html:24
msgid "" msgid ""
@ -95,6 +96,37 @@ msgstr ""
msgid "Use the link below to confirm your address email." msgid "Use the link below to confirm your address email."
msgstr "Gebruik de onderstaande link om uw email adres te bevestigen." 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/body.html:2
#: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1
msgid "Email changed" msgid "Email changed"

View File

@ -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 = """ <body>
<span class="preheader">A download link is available in your account.</span>
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td align="center">
<table class="email-content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="email-masthead">
<a href="http://localhost" class="f-fallback email-masthead-name">
FitTrackee
</a>
</td>
</tr>
<tr>
<td class="email-body" width="100%" cellpadding="0" cellspacing="0">
<table class="email-body-inner" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="content-cell">
<div class="f-fallback">
<h1>Hi test,</h1>
<p>You have requested an export of your account on FitTrackee. The archive is now ready to be downloaded from your account.</p>
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tr>
<td align="center">
<a href="http://localhost/profile/edit/account" class="f-fallback button button--green" target="_blank">Download your archive</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p>
If you did not request the export, please change your password immediately or contact your administrator if your account is locked.
</p>
<p>Thanks,
<br>The FitTrackee Team</p>
<table class="body-sub" role="presentation">
<tr>
<td>
<p class="f-fallback sub">If you're having trouble with the button above, copy and paste the URL below into your web browser.</p>
<p class="f-fallback sub">http://localhost/profile/edit/account</p>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="content-cell" align="center">
<p class="f-fallback sub align-center">&copy; FitTrackee.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>"""
expected_fr_html_body = """ <body>
<span class="preheader">Un lien de téléchargement est disponible dans votre compte.</span>
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td align="center">
<table class="email-content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="email-masthead">
<a href="http://localhost" class="f-fallback email-masthead-name">
FitTrackee
</a>
</td>
</tr>
<tr>
<td class="email-body" width="100%" cellpadding="0" cellspacing="0">
<table class="email-body-inner" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="content-cell">
<div class="f-fallback">
<h1>Bonjour test,</h1>
<p>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.</p>
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tr>
<td align="center">
<a href="http://localhost/profile/edit/account" class="f-fallback button button--green" target="_blank">Télécharger votre archive</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p>
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é.
</p>
<p>Merci,
<br>L'équipe FitTrackee</p>
<table class="body-sub" role="presentation">
<tr>
<td>
<p class="f-fallback sub">Si vous avez des problèmes avec le bouton, vous pouvez copier et coller le lien suivant dans votre navigateur.</p>
<p class="f-fallback sub">http://localhost/profile/edit/account</p>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation">
<tr>
<td class="content-cell" align="center">
<p class="f-fallback sub align-center">&copy; FitTrackee.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>"""

View File

@ -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

View File

@ -105,11 +105,6 @@ class TestEmailTemplateForEmailUpdateToCurrentEmail:
'email_update_to_current_email', 'fr', 'body.html', self.EMAIL_DATA '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 assert expected_fr_current_email_html_body in text_body

View File

@ -52,3 +52,9 @@ def user_email_updated_to_new_address_mock() -> Iterator[MagicMock]:
def account_confirmation_email_mock() -> Iterator[MagicMock]: def account_confirmation_email_mock() -> Iterator[MagicMock]:
with patch('fittrackee.users.auth.account_confirmation_email') as mock: with patch('fittrackee.users.auth.account_confirmation_email') as mock:
yield 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

View File

@ -375,6 +375,7 @@ class TestExportUserData:
self, self,
generate_archive_mock: Mock, generate_archive_mock: Mock,
logger_mock: Mock, logger_mock: Mock,
data_export_email_mock: Mock,
app: Flask, app: Flask,
user_1: User, user_1: User,
) -> None: ) -> None:
@ -414,3 +415,53 @@ class TestExportUserData:
assert export_request.updated_at is not None assert export_request.updated_at is not None
assert export_request.file_name is None assert export_request.file_name is None
assert export_request.file_size 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',
},
)

View File

@ -2,7 +2,7 @@ import datetime
import os import os
import re import re
import secrets import secrets
from typing import Dict, Optional, Tuple, Union from typing import Dict, Tuple, Union
import jwt import jwt
from flask import ( from flask import (
@ -43,6 +43,7 @@ from fittrackee.workouts.models import Sport
from .models import BlacklistedToken, User, UserDataExport, UserSportPreference from .models import BlacklistedToken, User, UserDataExport, UserSportPreference
from .tasks import export_data from .tasks import export_data
from .utils.controls import check_password, is_valid_email, register_controls from .utils.controls import check_password, is_valid_email, register_controls
from .utils.language import get_language
from .utils.token import decode_user_token from .utils.token import decode_user_token
auth_blueprint = Blueprint('auth', __name__) 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' 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: def send_account_confirmation_email(user: User) -> None:
if current_app.config['CAN_SEND_EMAILS']: if current_app.config['CAN_SEND_EMAILS']:
ui_url = current_app.config['UI_URL'] ui_url = current_app.config['UI_URL']

View File

@ -4,10 +4,14 @@ import secrets
from typing import Dict, List, Optional, Tuple, Union from typing import Dict, List, Optional, Tuple, Union
from zipfile import ZipFile from zipfile import ZipFile
from flask import current_app
from fittrackee import appLog, db from fittrackee import appLog, db
from fittrackee.emails.tasks import data_export_email
from fittrackee.files import get_absolute_file_path from fittrackee.files import get_absolute_file_path
from .models import User, UserDataExport from .models import User, UserDataExport
from .utils.language import get_language
class UserDataExporter: class UserDataExporter:
@ -108,4 +112,19 @@ def export_user_data(export_request_id: int) -> None:
if archive_file_name and archive_file_path: if archive_file_name and archive_file_path:
export_request.file_name = archive_file_name export_request.file_name = archive_file_name
export_request.file_size = os.path.getsize(archive_file_path) 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()

View File

@ -24,10 +24,10 @@ from fittrackee.responses import (
from fittrackee.utils import get_readable_duration from fittrackee.utils import get_readable_duration
from fittrackee.workouts.models import Record, Workout, WorkoutSegment from fittrackee.workouts.models import Record, Workout, WorkoutSegment
from .auth import get_language
from .exceptions import InvalidEmailException, UserNotFoundException from .exceptions import InvalidEmailException, UserNotFoundException
from .models import User, UserDataExport, UserSportPreference from .models import User, UserDataExport, UserSportPreference
from .utils.admin import UserManagerService from .utils.admin import UserManagerService
from .utils.language import get_language
users_blueprint = Blueprint('users', __name__) users_blueprint = Blueprint('users', __name__)

View File

@ -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

View File

@ -1,21 +1,21 @@
# Translations template for PROJECT. # Translations template for PROJECT.
# Copyright (C) 2022 ORGANIZATION # Copyright (C) 2023 ORGANIZATION
# This file is distributed under the same license as the PROJECT project. # This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2022. # FIRST AUTHOR <EMAIL@ADDRESS>, 2023.
# #
#, fuzzy #, fuzzy
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n" "Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\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.html:215
#: fittrackee/emails/templates/layout.txt:1 #: fittrackee/emails/templates/layout.txt:1
@ -78,6 +78,7 @@ msgid ""
msgstr "" msgstr ""
#: fittrackee/emails/templates/account_confirmation/body.html:22 #: 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/email_update_to_new_email/body.html:22
#: fittrackee/emails/templates/password_reset_request/body.html:24 #: fittrackee/emails/templates/password_reset_request/body.html:24
msgid "" msgid ""
@ -89,6 +90,37 @@ msgstr ""
msgid "Use the link below to confirm your address email." msgid "Use the link below to confirm your address email."
msgstr "" 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/body.html:2
#: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1 #: fittrackee/emails/templates/email_update_to_current_email/subject.txt:1
msgid "Email changed" msgid "Email changed"