From d07f7cc637c75ec062c72787edad4e40362e5add 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 | 5 +++++ tests/test_manager.py | 9 +++++++++ 3 files changed, 20 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 edbf3324..4b20c9c0 100644 --- a/combo/manager/views.py +++ b/combo/manager/views.py @@ -18,6 +18,7 @@ import datetime import hashlib import json import tarfile +import urllib.parse from operator import attrgetter from django.conf import settings @@ -442,6 +443,10 @@ class PageView(ManagedPageMixin, DetailView): } ) + if self.object.redirect_url: + parsed = urllib.parse.urlparse(self.object.redirect_url) + context['redirect_url_is_absolute'] = bool(parsed.netloc) + return context diff --git a/tests/test_manager.py b/tests/test_manager.py index 92aa12ba..8ecfe32d 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -278,7 +278,16 @@ 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 (error handling) resp = resp.click(href='.*/redirection') resp.form['redirect_url'].value = '{{ foo bar }}' -- 2.30.2