From 1c7055a615c55d5a9519cc5026fde94602e89316 Mon Sep 17 00:00:00 2001 From: Paul Marillonnet Date: Wed, 12 Dec 2018 14:58:53 +0100 Subject: [PATCH] user post-creation redirect based on 'next' keyword (#28931) --- .../templates/authentic2/manager/user_add.html | 2 +- src/authentic2/manager/user_views.py | 6 +++--- tests/test_manager.py | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/authentic2/manager/templates/authentic2/manager/user_add.html b/src/authentic2/manager/templates/authentic2/manager/user_add.html index 7cc73e9f..2e4f3192 100644 --- a/src/authentic2/manager/templates/authentic2/manager/user_add.html +++ b/src/authentic2/manager/templates/authentic2/manager/user_add.html @@ -7,7 +7,7 @@ {% block hidden_inputs %} {{ block.super }} - {% if next_url %}{% endif %} + {% if next %}{% endif %} {% endblock %} {% block breadcrumb %} diff --git a/src/authentic2/manager/user_views.py b/src/authentic2/manager/user_views.py index 762f5ff7..65f13977 100644 --- a/src/authentic2/manager/user_views.py +++ b/src/authentic2/manager/user_views.py @@ -129,15 +129,15 @@ class UserAddView(BaseAddView): return fields def get_success_url(self): - return self.request.POST.get('next_url') or \ + return self.request.POST.get('next') or \ reverse('a2-manager-user-detail', kwargs={'pk': self.object.pk}) def get_context_data(self, **kwargs): context = super(UserAddView, self).get_context_data(**kwargs) context['cancel_url'] = '../..' context['ou'] = self.ou - if hasattr(self.request, 'GET') and 'next_url' in self.request.GET: - context['next_url'] = self.request.GET['next_url'] + if hasattr(self.request, 'GET') and 'next' in self.request.GET: + context['next'] = self.request.GET['next'] return context def form_valid(self, form): diff --git a/tests/test_manager.py b/tests/test_manager.py index 33bec66b..27c29ad9 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -741,9 +741,9 @@ def test_return_on_logout(superuser, app): assert response.request.query_string == 'next=/manage/' -def test_manager_create_user_next_url(superuser_or_admin, app, ou1): +def test_manager_create_user_next(superuser_or_admin, app, ou1): next_url = u'https://example.nowhere.null/' - url = u'/manage/users/%s/add/?next_url=%s' % (ou1.pk, next_url) + url = u'/manage/users/%s/add/?next=%s' % (ou1.pk, next_url) login(app, superuser_or_admin, '/manage/') response = app.get(url) form = response.form @@ -755,9 +755,9 @@ def test_manager_create_user_next_url(superuser_or_admin, app, ou1): assert form.submit().location == next_url -def test_manager_create_user_next_url_form_cancelation(superuser_or_admin, app, ou1): +def test_manager_create_user_next_form_cancelation(superuser_or_admin, app, ou1): next_url = u'https://example.nowhere.null/' - url = u'/manage/users/%s/add/?next_url=%s' % (ou1.pk, next_url) + url = u'/manage/users/%s/add/?next=%s' % (ou1.pk, next_url) login(app, superuser_or_admin, '/manage/') response = app.get(url) form = response.form @@ -769,9 +769,9 @@ def test_manager_create_user_next_url_form_cancelation(superuser_or_admin, app, assert form.submit('cancel').location == next_url -def test_manager_create_user_next_url_form_error(superuser_or_admin, app, ou1): +def test_manager_create_user_next_form_error(superuser_or_admin, app, ou1): next_url = u'https://example.nowhere.null/' - url = u'/manage/users/%s/add/?next_url=%s' % (ou1.pk, next_url) + url = u'/manage/users/%s/add/?next=%s' % (ou1.pk, next_url) login(app, superuser_or_admin, '/manage/') response = app.get(url) form = response.form @@ -779,4 +779,4 @@ def test_manager_create_user_next_url_form_error(superuser_or_admin, app, ou1): form.set('last_name', 'Doe') form.set('email', 'jd') # erroneous form.set('password1', 'notvalid') # erroneous - assert '' % next_url in form.submit().body + assert '' % next_url in form.submit().body -- 2.20.0