~netlandish/django-wiki

209a5f8db9b01b4a361d82f5c47d9f40d3c6fbca — Benjamin Bach 6 years ago 4be3b53 + 6936562
Merge pull request #915 from benjaoming/article_back

If read isn't allowed, then display back button to parent article
2 files changed, 14 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 +6 -0
@@ 18,9 18,15 @@
  {% endif %}

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

{% endblock %}