~netlandish/django-wiki

8542f5d82fc0a600dfddf0778a04409630145c67 — Benjamin Bach 6 years ago 4be3b53
If read isn't allowed, then display back button to parent article
2 files changed, 18 insertions(+), 4 deletions(-)

M src/wiki/decorators.py
M src/wiki/templates/wiki/permission_denied.html
M src/wiki/decorators.py => src/wiki/decorators.py +8 -4
@@ 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)

M src/wiki/templates/wiki/permission_denied.html => src/wiki/templates/wiki/permission_denied.html +10 -0
@@ 17,10 17,20 @@
  </p>
  {% endif %}

  {% if not read_denied %}
  <p>
    <a href="{% url 'wiki:get' article_id=article.id path=urlpath.path %}" class="btn btn-default">
      {% trans "Back to article" %}
    </a>
  </p>
  {% else %}
  <p>
    {% if urlpath.parent %}
    <a href="{% url 'wiki:get' path=urlpath.parent.path %}" class="btn btn-default">
      {% trans "Back to article" %}
    </a>
    {% endif %}
  </p>
  {% endif %}

{% endblock %}