Projet

Général

Profil

0001-commands-send-html-unused-account-alert-with-link-40.patch

Valentin Deniaud, 18 mars 2020 10:33

Télécharger (4,33 ko)

Voir les différences:

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
src/authentic2/management/commands/clean-unused-accounts.py
25 25
from django.contrib.humanize.templatetags.humanize import naturaltime
26 26
from django.core.management.base import BaseCommand, CommandError
27 27
from django.utils import timezone
28
from django.utils.six.moves.urllib import parse as urlparse
28 29
from django.template.loader import render_to_string
29 30
from django_rbac.utils import get_ou_model
30 31

  
......
94 95
        ctx = {
95 96
            'user': user,
96 97
            'days_to_deletion': days_to_deletion,
97
            'last_login_date': naturaltime(user.last_login)
98
            'last_login_date': naturaltime(user.last_login),
99
            'login_url': urlparse.urljoin(settings.SITE_BASE_URL, settings.LOGIN_URL)
98 100
        }
99 101
        try:
100 102
            self.send_mail('authentic2/unused_account_alert', user, ctx)
src/authentic2/templates/authentic2/unused_account_alert_body.html
1
{% load i18n %}{% autoescape off %}{% blocktrans %}Hi {{ user.get_full_name }},
2

  
3
Your last logging was {{ last_login_date }}.
4
In order to keep your account, you must <a href={{ login_url}}>log in</a> before {{ days_to_deletion }} days.
5
Otherwise, it will be deleted after this time.
6
{% endblocktrans %}{% endautoescape %}
src/authentic2/templates/authentic2/unused_account_alert_body.txt
1 1
{% load i18n %}{% autoescape off %}{% blocktrans %}Hi {{ user }},
2 2

  
3
Your last logging was {{ last_login_date }}. In {{ days_to_deletion }} days your account
4
will be deleted.{% endblocktrans %}{% endautoescape %}
3
Your last logging was {{ last_login_date }}.
4
In order to keep your account, you must log in before {{ days_to_deletion }} days.
5
Otherwise, it will be deleted after this time.
6
{% endblocktrans %}{% endautoescape %}
tests/settings.py
44 44
A2_AUTH_KERBEROS_ENABLED = False
45 45

  
46 46
A2_VALIDATE_EMAIL_DOMAIN = False
47

  
48
SITE_BASE_URL = 'http://localhost'
tests/test_commands.py
124 124
    assert formatted in mail.body
125 125

  
126 126

  
127
def test_clean_unused_account_login_url(simple_user, mailoutbox):
128
    simple_user.ou.clean_unused_accounts_alert = 1
129
    simple_user.ou.clean_unused_accounts_deletion = 2
130
    simple_user.ou.save()
131
    simple_user.last_login = now() - datetime.timedelta(days=1)
132
    simple_user.save()
133
    management.call_command('clean-unused-accounts')
134
    mail = mailoutbox[0]
135
    assert 'href=http://localhost/login' in mail.message().as_string()
136

  
137

  
127 138
def test_cleanupauthentic(db):
128 139
    management.call_command('cleanupauthentic')
129 140

  
130
-