Projet

Général

Profil

0001-misc-use-native-404-page-if-all-pages-are-private-41.patch

Frédéric Péters, 09 avril 2020 08:31

Télécharger (2,21 ko)

Voir les différences:

Subject: [PATCH] misc: use native 404 page if ~all pages are private (#41514)

 combo/public/views.py | 7 ++++++-
 tests/test_public.py  | 8 ++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
combo/public/views.py
36 36
from django.utils.six.moves.urllib import parse as urlparse
37 37
from django.utils.six.moves.urllib import parse as urllib
38 38
from django.views.decorators.csrf import csrf_exempt
39
from django.views.defaults import page_not_found
39 40

  
40 41
from django.utils.translation import ugettext as _
41 42
from django.forms.widgets import Media
......
554 555
    if not hasattr(request, 'user'):
555 556
        # this happens when the 404 handler is called early on, for example
556 557
        # when the given hostname doesn't exist as a tenant
557
        from django.views.defaults import page_not_found
558
        return page_not_found(request, *args, **kwargs)
559

  
560
    if Page.objects.exists() and all((not x.is_visible(request.user) for x in Page.objects.filter(parent_id__isnull=True))):
561
        # if none of the first-level pages can be viewed by the user, display
562
        # native django error page.
558 563
        return page_not_found(request, *args, **kwargs)
559 564

  
560 565
    try:
tests/test_public.py
474 474
        resp = app.get('/foobar/', status=404)
475 475
        assert "can't find the requested page" in resp.text
476 476

  
477
    # check native django handler is used if all pages are private
478
    page.public = False
479
    page.save()
480
    resp = app.get('/foobar/', status=404)
481
    assert 'Custom 404 Text' not in resp.text
482
    assert "This page doesn't exist" not in resp.text
483

  
484

  
477 485
def test_style_demo(app, admin_user):
478 486
    TextCell.objects.all().delete()
479 487
    Page.objects.all().delete()
480
-