From 8dff2185f659046840861388010ed69dd6091969 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Wed, 10 Nov 2021 17:46:33 +0100 Subject: [PATCH] manager: mention template only on absolute redirect url (#58073) --- combo/manager/templates/combo/page_view.html | 7 ++++++- combo/manager/views.py | 3 +++ tests/test_manager.py | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/combo/manager/templates/combo/page_view.html b/combo/manager/templates/combo/page_view.html index f15f228b..f06bacd4 100644 --- a/combo/manager/templates/combo/page_view.html +++ b/combo/manager/templates/combo/page_view.html @@ -132,7 +132,12 @@ {% if object.redirect_url %}
-

{% blocktrans with redirect_url=object.redirect_url %}This page is configured as a redirection to the URL "{{ redirect_url }}", it can also be used as a template for the pages behind this URL.{% endblocktrans %}

+

+ {% blocktrans with redirect_url=object.redirect_url %}This page is configured as a redirection to the URL "{{ redirect_url }}".{% endblocktrans %} + {% if redirect_url_is_absolute %} + {% trans "It can also be used as a template for the pages behind this URL." } + {% endif %} +

{% endif %} diff --git a/combo/manager/views.py b/combo/manager/views.py index 31eec4bb..afb60680 100644 --- a/combo/manager/views.py +++ b/combo/manager/views.py @@ -442,6 +442,9 @@ class PageView(ManagedPageMixin, DetailView): } ) + if self.object.redirect_url: + context['redirect_url_is_absolute'] = not self.object.redirect_url.startswith('/') + return context diff --git a/tests/test_manager.py b/tests/test_manager.py index 210bfca7..236af1f0 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -278,7 +278,24 @@ def test_edit_page(app, admin_user): resp = resp.form.submit() resp = resp.follow() assert 'http://www.example.net' in resp.text + assert 'It can also be used as a template for the pages behind this URL.' in resp.text assert Page.objects.all()[0].redirect_url == 'http://www.example.net' + # redirection (relative url) + resp = resp.click(href='.*/redirection') + resp.form['redirect_url'].value = '/some-page/' + resp = resp.form.submit() + resp = resp.follow() + assert '/some-page/' in resp.text + assert 'It can also be used as a template for the pages behind this URL.' not in resp.text + assert Page.objects.all()[0].redirect_url == '/some-page/' + # redirection (templated url) + resp = resp.click(href='.*/redirection') + resp.form['redirect_url'].value = '{{idp_url}}/whatever' + resp = resp.form.submit() + resp = resp.follow() + assert '{{idp_url}}/whatever' in resp.text + assert 'It can also be used as a template for the pages behind this URL.' in resp.text + assert Page.objects.all()[0].redirect_url == '{{idp_url}}/whatever' # redirection (error handling) resp = resp.click(href='.*/redirection') resp.form['redirect_url'].value = '{{ foo bar }}' -- 2.30.2