Projet

Général

Profil

0001-manager-add-sidebar-info-on-users-linked-to-FC-27392.patch

Frédéric Péters, 26 juillet 2020 17:46

Télécharger (2,97 ko)

Voir les différences:

Subject: [PATCH] manager: add sidebar info on users linked to FC (#27392)

 src/authentic2_auth_fc/__init__.py                 |  5 +++++
 .../authentic2_auth_fc/manager_user_sidebar.html   |  6 ++++++
 tests/auth_fc/test_auth_fc.py                      | 14 ++++++++++++++
 3 files changed, 25 insertions(+)
 create mode 100644 src/authentic2_auth_fc/templates/authentic2_auth_fc/manager_user_sidebar.html
src/authentic2_auth_fc/__init__.py
18 18

  
19 19

  
20 20
import django.apps
21
from django import template
21 22

  
22 23

  
23 24
class AppConfig(django.apps.AppConfig):
......
53 54
            serializer.get_franceconnect = get_franceconnect
54 55
            serializer.fields['franceconnect'] = serializers.SerializerMethodField()
55 56

  
57
    def a2_hook_manager_user_data(self, view, user):
58
        context = {'user': user}
59
        return [template.loader.get_template('authentic2_auth_fc/manager_user_sidebar.html').render(context)]
60

  
56 61
    def a2_hook_user_can_reset_password(self, user):
57 62
        if user.fc_accounts.exists():
58 63
            return True
src/authentic2_auth_fc/templates/authentic2_auth_fc/manager_user_sidebar.html
1
{% load i18n %}
2
{% for account in user.fc_accounts.all %}
3
<div class="auth-fc-user-sidebar">
4
<p>{% trans "Link with FranceConnect created on" %} {{ account.created }}</p>
5
</div>
6
{% endfor %}
tests/auth_fc/test_auth_fc.py
35 35
from authentic2_auth_fc import models
36 36
from authentic2_auth_fc.utils import requests_retry_session
37 37

  
38
from ..utils import login
39

  
38 40

  
39 41
User = get_user_model()
40 42

  
......
655 657

  
656 658
def test_invalid_next_url(app, fc_settings, caplog, hooks):
657 659
    assert app.get('/fc/callback/?code=coin&next=JJJ72QQQ').location == 'JJJ72QQQ'
660

  
661

  
662
def test_manager_user_sidebar(app, fc_settings, superuser, simple_user):
663
    login(app, superuser, '/manage/')
664
    response = app.get('/manage/users/%s/' % simple_user.id)
665
    assert 'FranceConnect' not in response
666

  
667
    fc_account = models.FcAccount(user=simple_user)
668
    fc_account.save()
669

  
670
    response = app.get('/manage/users/%s/' % simple_user.id)
671
    assert 'FranceConnect' in response
658
-