manager: use a proper sidebar in user detail view (#28114)

This commit is contained in:
Frédéric Péters 2020-07-26 13:49:29 +02:00
parent d1dda9c392
commit 6c4128e68b
4 changed files with 37 additions and 27 deletions

View File

@ -37,21 +37,6 @@
</div>
{% endblock %}
</div>
<div class="other_actions">
{% block other_actions %}
{% if other_actions %}
<strong>{% trans "Actions" %}</strong>
{% for action in other_actions %}
<button name="{{ action.name }}"
{% if action.confirm %}data-confirm="{{ action.confirm }}"{% endif %}
{% if action.url_name %}data-url="{% url action.url_name pk=object.pk %}"{% endif %}
{% if action.url %}data-url="{{ action.url }}"{% endif %}
{% if action.popup %}rel="popup"{% endif %}
>{{ action.title }}</button>
{% endfor %}
{% endif %}
{% endblock %}
</div>
<script>
$(function () {
if ($.fn.djangoSelect2) {
@ -63,3 +48,28 @@
{% endblock %}
</form>
{% endblock %}
{% block sidebar %}
{% if other_actions %}
<aside id="sidebar">
{% block other_actions %}
{% if other_actions %}
<div class="actions">
<h3>{% trans "Actions" %}</h3>
<form method="post" id="object-actions">
{% csrf_token %}
{% for action in other_actions %}
<p><button name="{{ action.name }}"
{% if action.confirm %}data-confirm="{{ action.confirm }}"{% endif %}
{% if action.url_name %}data-url="{% url action.url_name pk=object.pk %}"{% endif %}
{% if action.url %}data-url="{{ action.url }}"{% endif %}
{% if action.popup %}rel="popup"{% endif %}
>{{ action.title }}</button></p>
{% endfor %}
</form>
</div>
{% endif %}
{% endblock %}
</aside>
{% endif %}
{% endblock %}

View File

@ -1,8 +1,6 @@
{% extends "authentic2/manager/form.html" %}
{% load i18n staticfiles %}
{% block bodyclasses %}{{ block.super }} with-actions{% endblock %}
{% block appbar %}
{{ block.super }}
<span class="actions">
@ -40,7 +38,9 @@
{% block buttons %}
{% endblock %}
{% block other_actions %}
{% block sidebar %}
<aside id="sidebar">
<p class="a2-manager-user-last-login">
{% if object.last_login %}
{% blocktrans with date=object.last_login %}Last login on {{ date }}.{% endblocktrans %}
@ -63,11 +63,11 @@
{{ data }}
{% endfor %}
{{ block.super }}
{% block other_actions %}{{ block.super }}{% endblock %}
{% if roles_by_ou or can_change_roles %}
<div class="user-roles">
<strong>{% trans "Roles" %}</strong>
<h3>{% trans "Roles" %}</h3>
<ul>
{% for ou, ou_roles in roles_by_ou.items %}
{% if multiple_ou %}
@ -91,5 +91,5 @@
</div>
{% endif %}
</aside>
{% endblock %}

View File

@ -119,7 +119,7 @@ def test_manager_user_password_reset(app, superuser, simple_user):
resp = login(app, superuser,
reverse('a2-manager-user-detail', kwargs={'pk': simple_user.pk}))
assert len(mail.outbox) == 0
resp = resp.form.submit('password_reset')
resp = resp.forms['object-actions'].submit('password_reset')
assert 'A mail was sent to' in resp
assert len(mail.outbox) == 1
url = get_link_from_mail(mail.outbox[0])
@ -135,14 +135,14 @@ def test_manager_user_password_reset(app, superuser, simple_user):
def test_manager_user_detail_by_uuid(app, superuser, simple_user):
url = reverse('a2-manager-user-by-uuid-detail', kwargs={'slug': simple_user.uuid})
resp = login(app, superuser, url)
assert '<strong>Actions</strong>' in resp.text
assert '<h3>Actions</h3>' in resp.text
assert simple_user.first_name.encode('utf-8') in resp.content
def test_manager_user_edit_by_uuid(app, superuser, simple_user):
url = reverse('a2-manager-user-by-uuid-edit', kwargs={'slug': simple_user.uuid})
resp = login(app, superuser, url)
assert '<strong>Actions</strong>' not in resp.text
assert '<h3>Actions</h3>' not in resp.text
assert simple_user.first_name.encode('utf-8') in resp.content
@ -253,7 +253,7 @@ def test_manager_create_user(superuser_or_admin, app, settings):
# try to change user email from john.doe2@gmail.com to
# john.doe@gmail.com in OU2 : NOK
response.form.set('email', 'john.doe@gmail.com')
response.forms['id_user_edit_form'].set('email', 'john.doe@gmail.com')
response = form.submit()
assert 'This email address is already in use.' in response
@ -282,7 +282,7 @@ def test_manager_create_user(superuser_or_admin, app, settings):
# try to change user email from john.doe3@gmail.com to
# john.doe@gmail.com in OU2 : NOK
response.form.set('email', 'john.doe@gmail.com')
response.forms['id_user_edit_form'].set('email', 'john.doe@gmail.com')
response = form.submit()
assert 'This email address is already in use.' in response

View File

@ -467,7 +467,7 @@ def test_su_permission(app, admin, simple_user):
def test_su_superuser_post(app, app_factory, superuser, simple_user):
resp = login(app, superuser, '/manage/users/%s/' % simple_user.pk)
assert len(resp.pyquery('button[name="su"]')) == 1
su_resp = resp.form.submit(name='su')
su_resp = resp.forms['object-actions'].submit(name='su')
new_app = app_factory()
new_app.get(su_resp.location).maybe_follow()