Projet

Général

Profil

0001-manager-use-a-proper-sidebar-in-user-detail-view-281.patch

Frédéric Péters, 26 juillet 2020 14:19

Télécharger (6,75 ko)

Voir les différences:

Subject: [PATCH] manager: use a proper sidebar in user detail view (#28114)

 .../templates/authentic2/manager/form.html    | 40 ++++++++++++-------
 .../authentic2/manager/user_detail.html       | 12 +++---
 tests/test_manager.py                         | 10 ++---
 tests/test_user_manager.py                    |  2 +-
 4 files changed, 37 insertions(+), 27 deletions(-)
src/authentic2/manager/templates/authentic2/manager/form.html
37 37
      </div>
38 38
      {% endblock %}
39 39
    </div>
40
      <div class="other_actions">
41
      {% block other_actions %}
42
        {% if other_actions %}
43
            <strong>{% trans "Actions" %}</strong>
44
            {% for action in other_actions %}
45
              <button name="{{ action.name }}"
46
                {% if action.confirm %}data-confirm="{{ action.confirm }}"{% endif %}
47
                {% if action.url_name %}data-url="{% url action.url_name pk=object.pk %}"{% endif %}
48
                {% if action.url %}data-url="{{ action.url }}"{% endif %}
49
                {% if action.popup %}rel="popup"{% endif %}
50
                >{{ action.title }}</button>
51
            {% endfor %}
52
        {% endif %}
53
      {% endblock %}
54
      </div>
55 40
      <script>
56 41
        $(function () {
57 42
          if ($.fn.djangoSelect2) {
......
63 48
      {% endblock %}
64 49
  </form>
65 50
{% endblock %}
51

  
52
{% block sidebar %}
53
  {% if other_actions %}
54
  <aside id="sidebar">
55
      {% block other_actions %}
56
        {% if other_actions %}
57
        <div class="actions">
58
          <h3>{% trans "Actions" %}</h3>
59
          <form method="post" id="object-actions">
60
            {% csrf_token %}
61
            {% for action in other_actions %}
62
            <p><button name="{{ action.name }}"
63
                {% if action.confirm %}data-confirm="{{ action.confirm }}"{% endif %}
64
                {% if action.url_name %}data-url="{% url action.url_name pk=object.pk %}"{% endif %}
65
                {% if action.url %}data-url="{{ action.url }}"{% endif %}
66
                {% if action.popup %}rel="popup"{% endif %}
67
                >{{ action.title }}</button></p>
68
            {% endfor %}
69
          </form>
70
        </div>
71
        {% endif %}
72
      {% endblock %}
73
  </aside>
74
  {% endif %}
75
{% endblock %}
src/authentic2/manager/templates/authentic2/manager/user_detail.html
1 1
{% extends "authentic2/manager/form.html" %}
2 2
{% load i18n staticfiles %}
3 3

  
4
{% block bodyclasses %}{{ block.super }} with-actions{% endblock %}
5

  
6 4
{% block appbar %}
7 5
  {{ block.super }}
8 6
  <span class="actions">
......
40 38
{% block buttons %}
41 39
{% endblock %}
42 40

  
43
{% block other_actions %}
41
{% block sidebar %}
42
<aside id="sidebar">
43

  
44 44
  <p class="a2-manager-user-last-login">
45 45
    {% if object.last_login %}
46 46
      {% blocktrans with date=object.last_login %}Last login on {{ date }}.{% endblocktrans %}
......
63 63
    {{ data }}
64 64
  {% endfor %}
65 65

  
66
  {{ block.super }}
66
  {% block other_actions %}{{ block.super }}{% endblock %}
67 67

  
68 68
  {% if roles_by_ou or can_change_roles %}
69 69
  <div class="user-roles">
70
    <strong>{% trans "Roles" %}</strong>
70
    <h3>{% trans "Roles" %}</h3>
71 71
    <ul>
72 72
      {% for ou, ou_roles in roles_by_ou.items %}
73 73
        {% if multiple_ou %}
......
91 91
  </div>
92 92
  {% endif %}
93 93

  
94

  
94
</aside>
95 95
{% endblock %}
tests/test_manager.py
119 119
    resp = login(app, superuser,
120 120
                 reverse('a2-manager-user-detail', kwargs={'pk': simple_user.pk}))
121 121
    assert len(mail.outbox) == 0
122
    resp = resp.form.submit('password_reset')
122
    resp = resp.forms['object-actions'].submit('password_reset')
123 123
    assert 'A mail was sent to' in resp
124 124
    assert len(mail.outbox) == 1
125 125
    url = get_link_from_mail(mail.outbox[0])
......
135 135
def test_manager_user_detail_by_uuid(app, superuser, simple_user):
136 136
    url = reverse('a2-manager-user-by-uuid-detail', kwargs={'slug': simple_user.uuid})
137 137
    resp = login(app, superuser, url)
138
    assert '<strong>Actions</strong>' in resp.text
138
    assert '<h3>Actions</h3>' in resp.text
139 139
    assert simple_user.first_name.encode('utf-8') in resp.content
140 140

  
141 141

  
142 142
def test_manager_user_edit_by_uuid(app, superuser, simple_user):
143 143
    url = reverse('a2-manager-user-by-uuid-edit', kwargs={'slug': simple_user.uuid})
144 144
    resp = login(app, superuser, url)
145
    assert '<strong>Actions</strong>' not in resp.text
145
    assert '<h3>Actions</h3>' not in resp.text
146 146
    assert simple_user.first_name.encode('utf-8') in resp.content
147 147

  
148 148

  
......
253 253

  
254 254
    # try to change user email from john.doe2@gmail.com to
255 255
    # john.doe@gmail.com in OU2 : NOK
256
    response.form.set('email', 'john.doe@gmail.com')
256
    response.forms['id_user_edit_form'].set('email', 'john.doe@gmail.com')
257 257
    response = form.submit()
258 258
    assert 'This email address is already in use.' in response
259 259

  
......
282 282

  
283 283
    # try to change user email from john.doe3@gmail.com to
284 284
    # john.doe@gmail.com in OU2 : NOK
285
    response.form.set('email', 'john.doe@gmail.com')
285
    response.forms['id_user_edit_form'].set('email', 'john.doe@gmail.com')
286 286
    response = form.submit()
287 287
    assert 'This email address is already in use.' in response
288 288

  
tests/test_user_manager.py
467 467
def test_su_superuser_post(app, app_factory, superuser, simple_user):
468 468
    resp = login(app, superuser, '/manage/users/%s/' % simple_user.pk)
469 469
    assert len(resp.pyquery('button[name="su"]')) == 1
470
    su_resp = resp.form.submit(name='su')
470
    su_resp = resp.forms['object-actions'].submit(name='su')
471 471

  
472 472
    new_app = app_factory()
473 473
    new_app.get(su_resp.location).maybe_follow()
474
-