From d4f9c575fdbaaeccd84685a0b166aaa1cfe5c98a Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Wed, 18 Mar 2020 10:25:23 +0100 Subject: [PATCH] commands: send html unused account alert with link (#40522) --- .../management/commands/clean-unused-accounts.py | 4 +++- .../authentic2/unused_account_alert_body.html | 6 ++++++ .../authentic2/unused_account_alert_body.txt | 6 ++++-- tests/settings.py | 2 ++ tests/test_commands.py | 11 +++++++++++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/authentic2/templates/authentic2/unused_account_alert_body.html diff --git a/src/authentic2/management/commands/clean-unused-accounts.py b/src/authentic2/management/commands/clean-unused-accounts.py index 14e425db..cf4db855 100644 --- a/src/authentic2/management/commands/clean-unused-accounts.py +++ b/src/authentic2/management/commands/clean-unused-accounts.py @@ -25,6 +25,7 @@ from django.contrib.auth import get_user_model from django.contrib.humanize.templatetags.humanize import naturaltime from django.core.management.base import BaseCommand, CommandError from django.utils import timezone +from django.utils.six.moves.urllib import parse as urlparse from django.template.loader import render_to_string from django_rbac.utils import get_ou_model @@ -94,7 +95,8 @@ class Command(BaseCommand): ctx = { 'user': user, 'days_to_deletion': days_to_deletion, - 'last_login_date': naturaltime(user.last_login) + 'last_login_date': naturaltime(user.last_login), + 'login_url': urlparse.urljoin(settings.SITE_BASE_URL, settings.LOGIN_URL) } try: self.send_mail('authentic2/unused_account_alert', user, ctx) diff --git a/src/authentic2/templates/authentic2/unused_account_alert_body.html b/src/authentic2/templates/authentic2/unused_account_alert_body.html new file mode 100644 index 00000000..f3a978b9 --- /dev/null +++ b/src/authentic2/templates/authentic2/unused_account_alert_body.html @@ -0,0 +1,6 @@ +{% load i18n %}{% autoescape off %}{% blocktrans %}Hi {{ user.get_full_name }}, + +Your last logging was {{ last_login_date }}. +In order to keep your account, you must log in before {{ days_to_deletion }} days. +Otherwise, it will be deleted after this time. +{% endblocktrans %}{% endautoescape %} diff --git a/src/authentic2/templates/authentic2/unused_account_alert_body.txt b/src/authentic2/templates/authentic2/unused_account_alert_body.txt index 3488c45c..67401fa1 100644 --- a/src/authentic2/templates/authentic2/unused_account_alert_body.txt +++ b/src/authentic2/templates/authentic2/unused_account_alert_body.txt @@ -1,4 +1,6 @@ {% load i18n %}{% autoescape off %}{% blocktrans %}Hi {{ user }}, -Your last logging was {{ last_login_date }}. In {{ days_to_deletion }} days your account -will be deleted.{% endblocktrans %}{% endautoescape %} +Your last logging was {{ last_login_date }}. +In order to keep your account, you must log in before {{ days_to_deletion }} days. +Otherwise, it will be deleted after this time. +{% endblocktrans %}{% endautoescape %} diff --git a/tests/settings.py b/tests/settings.py index 3161bc75..d8b3376c 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -44,3 +44,5 @@ ALLOWED_HOSTS = ALLOWED_HOSTS + ['example.net', 'cache1.example.com', 'cache2.ex A2_AUTH_KERBEROS_ENABLED = False A2_VALIDATE_EMAIL_DOMAIN = False + +SITE_BASE_URL = 'http://localhost' diff --git a/tests/test_commands.py b/tests/test_commands.py index 1a18efb3..f7138da4 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -124,6 +124,17 @@ def test_clean_unused_account_human_duration_format(simple_user, mailoutbox, del assert formatted in mail.body +def test_clean_unused_account_login_url(simple_user, mailoutbox): + simple_user.ou.clean_unused_accounts_alert = 1 + simple_user.ou.clean_unused_accounts_deletion = 2 + simple_user.ou.save() + simple_user.last_login = now() - datetime.timedelta(days=1) + simple_user.save() + management.call_command('clean-unused-accounts') + mail = mailoutbox[0] + assert 'href=http://localhost/login' in mail.message().as_string() + + def test_cleanupauthentic(db): management.call_command('cleanupauthentic') -- 2.20.1