From 8542f5d82fc0a600dfddf0778a04409630145c67 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Tue, 16 Oct 2018 17:28:31 +0200 Subject: [PATCH] If read isn't allowed, then display back button to parent article --- src/wiki/decorators.py | 12 ++++++++---- src/wiki/templates/wiki/permission_denied.html | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/wiki/decorators.py b/src/wiki/decorators.py index 05f16b58..3072b5a5 100644 --- a/src/wiki/decorators.py +++ b/src/wiki/decorators.py @@ -9,7 +9,7 @@ from wiki.conf import settings from wiki.core.exceptions import NoRootURL -def response_forbidden(request, article, urlpath): +def response_forbidden(request, article, urlpath, read_denied=False): if request.user.is_anonymous: qs = request.META.get('QUERY_STRING', '') if qs: @@ -21,14 +21,18 @@ def response_forbidden(request, article, urlpath): return HttpResponseForbidden( render_to_string( "wiki/permission_denied.html", - context={'article': article, 'urlpath': urlpath}, + context={ + 'article': article, + 'urlpath': urlpath, + 'read_denied': read_denied + }, request=request ) ) # TODO: This decorator is too complex (C901) -def get_article(func=None, can_read=True, can_write=False, # noqa +def get_article(func=None, can_read=True, can_write=False, # noqa: max-complexity=13 deleted_contents=False, not_locked=False, can_delete=False, can_moderate=False, can_create=False): @@ -130,7 +134,7 @@ def get_article(func=None, can_read=True, can_write=False, # noqa return response_forbidden(request, article, urlpath) if can_read and not article.can_read(request.user): - return response_forbidden(request, article, urlpath) + return response_forbidden(request, article, urlpath, read_denied=True) if (can_write or can_create) and not article.can_write(request.user): return response_forbidden(request, article, urlpath) diff --git a/src/wiki/templates/wiki/permission_denied.html b/src/wiki/templates/wiki/permission_denied.html index 5900fe62..50fa3506 100644 --- a/src/wiki/templates/wiki/permission_denied.html +++ b/src/wiki/templates/wiki/permission_denied.html @@ -17,10 +17,20 @@

{% endif %} + {% if not read_denied %}

{% trans "Back to article" %}

+ {% else %} +

+ {% if urlpath.parent %} + + {% trans "Back to article" %} + + {% endif %} +

+ {% endif %} {% endblock %} -- 2.45.2