Projet

Général

Profil

0001-manager-mention-template-only-on-absolute-redirect-u.patch

Valentin Deniaud, 16 novembre 2021 17:51

Télécharger (3,12 ko)

Voir les différences:

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(-)
combo/manager/templates/combo/page_view.html
132 132

  
133 133
{% if object.redirect_url %}
134 134
<div class="infonotice">
135
    <p>{% 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 %}</p>
135
  <p>
136
    {% blocktrans with redirect_url=object.redirect_url %}This page is configured as a redirection to the URL "{{ redirect_url }}".{% endblocktrans %}
137
    {% if redirect_url_is_absolute %}
138
    {% trans "It can also be used as a template for the pages behind this URL." }
139
    {% endif %}
140
  </p>
136 141
</div>
137 142
{% endif %}
138 143

  
combo/manager/views.py
442 442
            }
443 443
        )
444 444

  
445
        if self.object.redirect_url:
446
            context['redirect_url_is_absolute'] = not self.object.redirect_url.startswith('/')
447

  
445 448
        return context
446 449

  
447 450

  
tests/test_manager.py
278 278
    resp = resp.form.submit()
279 279
    resp = resp.follow()
280 280
    assert 'http://www.example.net' in resp.text
281
    assert 'It can also be used as a template for the pages behind this URL.' in resp.text
281 282
    assert Page.objects.all()[0].redirect_url == 'http://www.example.net'
283
    # redirection (relative url)
284
    resp = resp.click(href='.*/redirection')
285
    resp.form['redirect_url'].value = '/some-page/'
286
    resp = resp.form.submit()
287
    resp = resp.follow()
288
    assert '/some-page/' in resp.text
289
    assert 'It can also be used as a template for the pages behind this URL.' not in resp.text
290
    assert Page.objects.all()[0].redirect_url == '/some-page/'
291
    # redirection (templated url)
292
    resp = resp.click(href='.*/redirection')
293
    resp.form['redirect_url'].value = '{{idp_url}}/whatever'
294
    resp = resp.form.submit()
295
    resp = resp.follow()
296
    assert '{{idp_url}}/whatever' in resp.text
297
    assert 'It can also be used as a template for the pages behind this URL.' in resp.text
298
    assert Page.objects.all()[0].redirect_url == '{{idp_url}}/whatever'
282 299
    # redirection (error handling)
283 300
    resp = resp.click(href='.*/redirection')
284 301
    resp.form['redirect_url'].value = '{{ foo bar }}'
285
-