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 | ||
---|---|---|
307 | 307 |
fields.append('is_superuser') |
308 | 308 |
return fields |
309 | 309 | |
310 |
def get_context_data(self, **kwargs): |
|
311 |
context = super(UserEditView, self).get_context_data(**kwargs) |
|
312 |
if hasattr(self.request, 'GET') and 'next' in self.request.GET: |
|
313 |
context['next'] = self.request.GET['next'] |
|
314 |
context['cancel_url'] = self.request.GET['next'] |
|
315 |
return context |
|
316 | ||
317 |
def get_success_url(self): |
|
318 |
return self.request.POST.get('next') or \ |
|
319 |
reverse('a2-manager-user-detail', kwargs={'pk': self.object.pk}) |
|
320 | ||
310 | 321 |
def form_valid(self, form): |
311 | 322 |
response = super(UserEditView, self).form_valid(form) |
312 | 323 |
hooks.call_hooks('event', name='manager-edit-user', user=self.request.user, |
tests/test_manager.py | ||
---|---|---|
789 | 789 |
response = app.get(url) |
790 | 790 | |
791 | 791 |
assert querystring in response.location |
792 | ||
793 | ||
794 |
def test_manager_edit_user_next(app, simple_user, superuser_or_admin): |
|
795 |
next_url = u'https://example.nowhere.null/' |
|
796 |
url = u'/manage/users/%s/edit/?next=%s' % (simple_user.pk, next_url) |
|
797 |
login(app, superuser_or_admin, '/manage/') |
|
798 |
response = app.get(url) |
|
799 | ||
800 |
# cancel if not handled through form submission |
|
801 |
assert response.pyquery.remove_namespaces()('a.cancel').attr('href') == next_url |
|
802 | ||
803 |
form = response.form |
|
804 |
form.set('last_name', 'New name') |
|
805 |
assert form.submit().location == next_url |
|
806 | ||
807 | ||
808 |
def test_manager_edit_user_next_form_error(superuser_or_admin, app, ou1, simple_user): |
|
809 |
next_url = u'https://example.nowhere.null/' |
|
810 |
url = u'/manage/users/%s/edit/?next=%s' % (simple_user.pk, next_url) |
|
811 |
login(app, superuser_or_admin, '/manage/') |
|
812 |
response = app.get(url) |
|
813 |
form = response.form |
|
814 |
form.set('email', 'jd') # erroneous |
|
815 |
resp = form.submit() |
|
816 |
assert '<input type="hidden" name="next" value="%s">' % next_url in resp.ubody |
|
792 |
- |