0001-allow-redirect-after-user-edition-28779.patch
src/authentic2/manager/templates/authentic2/manager/user_edit.html | ||
---|---|---|
7 | 7 |
<a href="{% url 'a2-manager-user-detail' pk=object.pk %}">{{ object.get_full_name }}</a> |
8 | 8 |
<a href="#">{% trans "Edit" %}</a> |
9 | 9 |
{% endblock %} |
10 | ||
11 |
{% block hidden_inputs %} |
|
12 |
{{ block.super }} |
|
13 |
{% if next %}<input type="hidden" name="next" value="{{ next }}">{% endif %} |
|
14 |
{% endblock %} |
src/authentic2/manager/user_views.py | ||
---|---|---|
19 | 19 | |
20 | 20 |
from authentic2.constants import SWITCH_USER_SESSION_KEY |
21 | 21 |
from authentic2.models import Attribute, PasswordReset |
22 |
from authentic2.utils import switch_user, send_password_reset_mail, redirect, send_email_change_email
|
|
22 |
from authentic2.utils import switch_user, send_password_reset_mail, redirect, select_next_url
|
|
23 | 23 |
from authentic2.a2_rbac.utils import get_default_ou |
24 | 24 |
from authentic2 import hooks |
25 | 25 |
from django_rbac.utils import get_role_model, get_role_parenting_model, get_ou_model |
... | ... | |
291 | 291 |
form_class = UserEditForm |
292 | 292 |
permissions = ['custom_user.change_user'] |
293 | 293 |
fields = ['username', 'ou', 'first_name', 'last_name'] |
294 |
success_url = '..' |
|
295 | 294 |
slug_field = 'uuid' |
296 | 295 |
action = _('Change') |
297 | 296 |
title = _('Edit user') |
... | ... | |
307 | 306 |
fields.append('is_superuser') |
308 | 307 |
return fields |
309 | 308 | |
309 |
def _get_next_url(self): |
|
310 |
return select_next_url( |
|
311 |
self.request, |
|
312 |
default=reverse('a2-manager-user-detail', kwargs={'pk': self.object.pk}), |
|
313 |
include_post=True) |
|
314 | ||
315 |
def get_context_data(self, **kwargs): |
|
316 |
context = super(UserEditView, self).get_context_data(**kwargs) |
|
317 |
next_url = self._get_next_url() |
|
318 |
context['next'] = next_url |
|
319 |
context['cancel_url'] = next_url |
|
320 |
return context |
|
321 | ||
322 |
def get_success_url(self): |
|
323 |
return self._get_next_url() |
|
324 | ||
310 | 325 |
def form_valid(self, form): |
311 | 326 |
response = super(UserEditView, self).form_valid(form) |
312 | 327 |
hooks.call_hooks('event', name='manager-edit-user', user=self.request.user, |
tests/test_manager.py | ||
---|---|---|
790 | 790 |
response = app.get(url) |
791 | 791 | |
792 | 792 |
assert querystring in response.location |
793 | ||
794 | ||
795 |
def test_manager_edit_user_next(app, simple_user, superuser_or_admin): |
|
796 |
next_url = u'/example.nowhere.null/' |
|
797 |
url = u'/manage/users/%s/edit/?next=%s' % (simple_user.pk, next_url) |
|
798 |
login(app, superuser_or_admin, '/manage/') |
|
799 |
response = app.get(url) |
|
800 | ||
801 |
# cancel if not handled through form submission |
|
802 |
assert response.pyquery.remove_namespaces()('a.cancel').attr('href') == next_url |
|
803 | ||
804 |
form = response.form |
|
805 |
form.set('last_name', 'New name') |
|
806 |
assert urlparse(form.submit().location).path == next_url |
|
807 | ||
808 | ||
809 |
def test_manager_edit_user_next_form_error(superuser_or_admin, app, ou1, simple_user): |
|
810 |
next_url = u'/example.nowhere.null/' |
|
811 |
url = u'/manage/users/%s/edit/?next=%s' % (simple_user.pk, next_url) |
|
812 |
login(app, superuser_or_admin, '/manage/') |
|
813 |
response = app.get(url) |
|
814 |
form = response.form |
|
815 |
form.set('email', 'jd') # erroneous |
|
816 |
resp = form.submit() |
|
817 |
assert '<input type="hidden" name="next" value="%s">' % next_url in resp.ubody |
|
793 |
- |