From 15b5dcab35a5ec4db359ff0a1efa4a53ddbe08dd Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 10 Apr 2019 12:11:20 +0200 Subject: [PATCH 4/5] manager: accept a cancel_url parameter on UserAddView (#32140) --- src/authentic2/manager/user_views.py | 5 ++++- tests/test_manager.py | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/authentic2/manager/user_views.py b/src/authentic2/manager/user_views.py index 7f67854b..76398afa 100644 --- a/src/authentic2/manager/user_views.py +++ b/src/authentic2/manager/user_views.py @@ -144,7 +144,10 @@ class UserAddView(BaseAddView): def get_context_data(self, **kwargs): context = super(UserAddView, self).get_context_data(**kwargs) - context['cancel_url'] = select_next_url(self.request, default='../..', include_post=True) + context['cancel_url'] = select_next_url( + self.request, + default='../..', + field_name='cancel') context['next'] = select_next_url(self.request, default=None, include_post=True) context['ou'] = self.ou return context diff --git a/tests/test_manager.py b/tests/test_manager.py index 7ee3fa9e..399e2728 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -735,13 +735,24 @@ def test_return_on_logout(superuser, app): def test_manager_create_user_next(superuser_or_admin, app, ou1): + login(app, superuser_or_admin, '/manage/') + next_url = u'/example.nowhere.null/' url = u'/manage/users/%s/add/?next=%s' % (ou1.pk, next_url) - login(app, superuser_or_admin, '/manage/') response = app.get(url) - # cancel if not handled through form submission - assert response.pyquery.remove_namespaces()('a.cancel').attr('href') == next_url + # cancel is not handled through form submission, it's a link + # next without cancel, no cancel button + assert response.pyquery.remove_namespaces()('a.cancel').attr('href') == '../..' + assert response.pyquery.remove_namespaces()('input[name="next"]').attr('value') == next_url + + next_url = u'/example.nowhere.null/' + cancel_url = u'/example.nowhere.cancel/' + url = u'/manage/users/%s/add/?next=%s&cancel=%s' % (ou1.pk, next_url, cancel_url) + response = app.get(url) + + assert response.pyquery.remove_namespaces()('a.cancel').attr('href') == cancel_url + assert response.pyquery.remove_namespaces()('input[name="next"]').attr('value') == next_url form = response.form form.set('first_name', 'John') -- 2.20.1