From 06d4a53fbb7a195707b7009978af7d335094a898 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 4 Mar 2023 10:49:25 +0100 Subject: [PATCH] API - send an email when data export is successful --- fittrackee/emails/tasks.py | 10 ++ .../templates/data_export_ready/body.html | 26 +++ .../templates/data_export_ready/body.txt | 5 + .../templates/data_export_ready/subject.txt | 1 + .../translations/de/LC_MESSAGES/messages.mo | Bin 4997 -> 4997 bytes .../translations/de/LC_MESSAGES/messages.po | 34 +++- .../translations/en/LC_MESSAGES/messages.mo | Bin 4535 -> 5351 bytes .../translations/en/LC_MESSAGES/messages.po | 36 +++- .../translations/fr/LC_MESSAGES/messages.mo | Bin 5155 -> 6062 bytes .../translations/fr/LC_MESSAGES/messages.po | 37 +++- .../translations/it/LC_MESSAGES/messages.mo | Bin 4933 -> 4806 bytes .../translations/it/LC_MESSAGES/messages.po | 34 +++- .../translations/nb/LC_MESSAGES/messages.mo | Bin 445 -> 445 bytes .../translations/nb/LC_MESSAGES/messages.po | 34 +++- .../translations/nl/LC_MESSAGES/messages.mo | Bin 5022 -> 4893 bytes .../translations/nl/LC_MESSAGES/messages.po | 34 +++- .../email_data_export_ready.py | 167 ++++++++++++++++++ .../emails/test_email_data_export_ready.py | 89 ++++++++++ .../test_email_template_email_update.py | 5 - fittrackee/tests/fixtures/fixtures_emails.py | 6 + .../tests/users/test_users_export_data.py | 51 ++++++ fittrackee/users/auth.py | 10 +- fittrackee/users/export_data.py | 21 ++- fittrackee/users/users.py | 2 +- fittrackee/users/utils/language.py | 10 ++ messages.pot | 40 ++++- 26 files changed, 627 insertions(+), 25 deletions(-) create mode 100644 fittrackee/emails/templates/data_export_ready/body.html create mode 100644 fittrackee/emails/templates/data_export_ready/body.txt create mode 100644 fittrackee/emails/templates/data_export_ready/subject.txt create mode 100644 fittrackee/tests/emails/template_results/email_data_export_ready.py create mode 100644 fittrackee/tests/emails/test_email_data_export_ready.py create mode 100644 fittrackee/users/utils/language.py 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 e3f338a808b578a5a2c45159401ea78281e8158c..d8dda4788f2dbe9beef7eaa500d292802d490d5c 100644 GIT binary patch delta 38 scmZowZ&lwggHym**8qr26bucljE%Jo3^%XfOk!j<)HB%3%U!_%0K()6UjP6A delta 38 tcmZowZ&lwggHymr*T7uYz*xb++{)BK+rVh^3eF@(W&=Ir&Ai+d900^H32^`b 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 596301af6a90cc0d867a56e8ea3927b708209ebe..213c34d9596539c6addd97e1620ffc735d2d3416 100644 GIT binary patch delta 1197 zcmd_o%}W$<9LMqBj%z-YrfUX0;ZKA>ZDrRj5(}{i1S^olIz`Oxj<~eVxU&yx5K`VE zwuix+2_1|G>#~6q1x7@-ZhHzmbdfrFD7-}U{yN(e^dB_L%xk{C`OWt?^I=vx);nj{ zLcw{(*2%G-BN>qD_qJ>(6{dWGyYNHB4Q!>Zu2QN2_hB46u?cVCX}pg`{Dea|9aQQr zuHs3hX4ScBrRErz#{}-#<~O*8yQz!Vf=gI~&nxw7JWgH4ehhJQ5YM8#a1mqp65DYD zyD?O&R1^oWjrG+e7Y7-*Q*i~)Q?Fq&9;s8R3y1I+x;TnYaRiNerG{}7rOzTtl5epM zKjLjtHMaXNc5jEDBzY4FLoMR03_RpQqI`i80j5rCrNR&gh(@@Sp3l?s{XWn0ehXc;rgJr}1L0`pY~buJ(dq9PF+}PZ z6Gc<#V_wA+ZlNFZIE-JohXbV|gZPLUY;cM6<0;PLJF+e<6J;VnZY*LgZlD`8#W{;{ z<`eA0JVr27E)vBlY{6Z$@B};Y37gPlvo^Gfj^QNp8U}d3+;b7;#tV+4&m)q=IUK@s z)G|M)8`f8d>{BU@TIRO0;4^BO4@{w97RoH3mRUh9bAy98>g6YSzht@4G#0Bh%@S(T z2h=jJsAay9Z\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 e2868a61e0e8fd55da667d61927143eb2dc38324..7955dddecb9c9cfafe59e7c517aeda1d45972b2f 100644 GIT binary patch delta 1262 zcmaLVTWkzb7{KwaYsl+>LNMexFO=Ts+lXV&cOs>CHCBoZ1j zX(Hm%M2Ho`GGVIzLQ zW(*G(q74^g1NlXQ!4w{x3cQV5h~Hv0&K@B|6RyAo=wcV%#0?lK6=F4Zq2A{L>P|k! z2K<1}>1wD&#q@ca!fA#UOvS}=yI z@oeBn)bk^37QtOO6VG4_pQ0{cF4Z*Qc3g!=Yx%A|2G4ll;z|x&|B3FR-e~+7z5>_d zBs`8{i8P(PcFZwM8MEx&(n?ArZCEj*JEo*%%Y9DDl}0q`q-?L%UmI$!?ff-A|H_T_ zT4|L{hYpAQTSe8SUayj>FX6bJzo)Rr|5|i^u92Uk_qLtA(p84JPkN5*R=<-gQ}(z{ z{O@$x>%}T0dyTYW&7PD>dQ3CyV0-EG{G6WsR#H*WI3&lv_xHaKKUdY>65%&XwngT* zw>L-HvR6kK1xwpnBc)=qO#_rIO(nftCYH-YdkuG&iYwcbWR|9tOgOfs+hQ7aQl=fx zRWj(WnTTh^`7Pg+8g(O`%m3 zWKeJ|y3>Vsr(0J-p-^2Y;=+Zv5?u;L{09RL4Bt6(@62${Y}Kw+&76Ae%fhH&`kAjR zI(r;(t4JYfPsS9w$-iIC zaT>F6DU+{ajC>PY@dCqG?GTA#0-xhNhHw*K;t`gii^D20l(7#7$-kk8`{f@&4GU-3 zkM10iUQA*)Zlmr@8ufw2xg!7RQVeU!^IRe&*n;}|2rl4vEW(^8B4Zf9b^M7#7^IEs z+%MAveOQqv@*Y2<-gu6>vRe#bAYX){\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 ffcad1f479f4ec417f2240294e48aa1f5d75c079..b1c6ada7bf374bb9f86c1715259e7ad3eb1dd9b9 100644 GIT binary patch delta 821 zcmY+=F=!J}7{KwTX`7f>tF>CFMbB!ZHC(()0=7r1Nt#enQxlR{p$c+IuO-mlmCIG> zpqT_w5K9nLgbspR9PI99w^9d19K_;O+}w0f{2%F{j|ac+yL<2B``)|Y#^B?gy7*^h z_X^QNKDBEZJIQZj8Smji+`-HE3m;+HBg6!Lz*X#T6C#PPv4TI)y?3=;h@&`%hw)Ck zs0%N_>h6bUsF61@jyovhP=^pvyoM+7A%?JtDt^Wj7@$}XL%SAmntTNh;d?xX->`_C zKIYF8=sqDP@eTIlZ*&Xx?Gs{q4^80_@?!xZdQnApq72$NgWb4^H*g!*aBP38{ug{j z9_Bf-_z~xEpnjm$*#mSZdx37@w@8y>3*Ew>a1_7e7@p}8VgwDmgll*fzv3|ZC=$U0 z4x)oGe2!tjhzqg*AN@TL}L@HHC7mNOUt|X7!hVE1?Q%>oQp-B-X5|tHpOi~ps8VxC` zqHs_y7`Ljm|IS5Z)!mXhqQ!YmQv9b+fjhJC?0UDa#~~@`i0M*DNVGI=j>g z<4d;XSmvT$T?kjK#fw}u=a=<)TBtgW`~FI!5EyFw^v68Q&RpYs;8fp)VH!3)&dSLZ VO-kxzV?m09RW+=vKMgd!e*vpXgqi>V delta 956 zcmX}q&rcIU6u|LE(LxtQkt$X!u0;q)7K6|z4Jg%?if&ud0{%kDQdhD{mZVfpnjXCv zgK4~Y&=?y|HZdU{Ogwn;*FRt+@u>0W!Nij$ey23PWcD-D?ab`FdGEX5^{n}eM@7W+ z@E{uNMf~Wi*@-(C58(nvaTk{HJifvQShr0ifou2>zu;-Sxm_fO6;$(Dy&`)tgl#zD zm7+AzN!EUt!3bjq$FYnCe#aqf1Na)%f}inuoyc$8!}xKNNISknb)t`$$4%UgX0yl~&f`;jgKGUb z(zuQlG;z8`WD%bg>8LOB?c6$92dag~kV8lc)xxtliVlw9I*#BsJcXT1>cwk#0`K85 ze2d-q3x_elW&@bQD_FcsN1bdF593cfj(&EXM-!*;1*-RdF@zy5ki=A@i>Jzp3SJA> zUA-pu6wX)8q=x%wD!VG!M%7laI-p*vg`o!2)c@FD>jkirrixR2tP1rJDnlyBzI4#I zR-sfRNK*x-!b9WsM5mFgYH%weXO`U?&PK-b$LpUgSWAxO>b(8h_i zt4*bijJ@itILodPvkG=ZzZ8#VjAYt~MfJ1kNOH3Oayk{)OlzfJFx6dIvI@)jh(0l6 zntCdljO(NEWOULTkH%t|cs6^o6wq?brsXc)wia2=DU`}uxPE4OqV!ekD&5igf)|a1 c?b`XRbuQQotZ3`Q1A}4Xy1lv)XsR^)1D;oQGynhq 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 50f367c90b422bff3cbafc84ce9f78ca491e7ece..e67bf77ab4cc6d47a21a259f00eb12ec3477e276 100644 GIT binary patch delta 33 ncmdnXyq9@Gw}7#(0T7ue7#dg^8*3XFZk#R4$ZDu(z{LOnn1ctk delta 33 ocmdnXyq9@Gw}6qZfw``Mv4VlQm8pfcfzig\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 c881e1305ed6c1026cac79a5148f4a7975d63748..62fbc2fe170a87f866e709cbb1ebcefdb1414c08 100644 GIT binary patch delta 835 zcmY+=J!lhQ7{Kw@rXTTQtJW$QqMitq8ZX=>k($G5nkLlNe3`_$377O5QqqfD5=#fk zq)VY#;-a9q=~4wVIJ)R6Dmv&S1)<<1xHw4tUzTZ#6Kh1 zBg6=Ks%sGk$(ON+cklpi;T8OiYnX5eF^!*a9euq*#PB(m@FzO^uJs9V1Q+lS-tH4E zF+i~1op^vc`36RD3l$ve7b1k$@g%OIA2(3LFL(ky95#ynt~s0|U%`X;9?#$==5f%? z`?CawTZmbFi9Y;;&Vk;&LVVprQRpQ}{}}@~M72%<`UJr+!4o`-9lU|xFpZb^>9lYSkK%VchTFrPepl~6E1S#ACZ-DV zTq2jB$)u&6d9!9WlvKT3nO9=Xa$PCZbUBfloJmF}Q$pr zvvs++ShKBC)o3ou7k1*nP7=_f}oa^ h+J4U|@3d)|Hudq66aLs3!mZ-yo_rHMY8xB)pwn(B1druy*S${ z6*)vF*7zZVe#SYR!yPp6Cr+c6mj^L|t%jo*Kx zN^q3jsrMIg0-vBd(#j_~U33O{oW&WuhbG4HGpYzX*wt}d!G7FCf^lk?XK$m=>%wt6 z$Hdyg|8tVm@EA>{tBPgS-6DUA`{G;-)#pzAFBQ2ewXjM@CDlVyHALf>og#hdqp8HW zD$WK~imIAvoSx`3LUW2!5xJ7LS8}__=D)37!HrV(zCIexmC^+>`@piss(0PJDQzKP zB&~9;n9JKn&@5Sg{dOpjG-3%O7|^dK{IU7*JBfHmi<-rf!KZd{-7Mt`em$ItM)i0g z7Sb<-VuAVSTp$=shEl0Z)gI0CL`{2j!(3%Ld%arId@Y%DxVo\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"