mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-22 15:44:46 +00:00
move Page.check_view_restrictions back into the body of the check_view_restrictions hook - it's view-level functionality, not model level, and its presence in the Page model is confusing (and the reason it was there has now been superseded). See https://groups.google.com/d/msg/wagtail/085Z7Mp73gE/dqfxW0sC72IJ
This commit is contained in:
parent
7d4f4c2edd
commit
e23975eb93
2 changed files with 21 additions and 22 deletions
|
|
@ -13,7 +13,6 @@ from django.http import Http404
|
|||
from django.core.cache import cache
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.core.handlers.base import BaseHandler
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.auth.models import Group
|
||||
from django.conf import settings
|
||||
|
|
@ -821,26 +820,6 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, Indexed)):
|
|||
"""Return a query set of all page view restrictions that apply to this page"""
|
||||
return PageViewRestriction.objects.filter(page__in=self.get_ancestors(inclusive=True))
|
||||
|
||||
def check_view_restrictions(self, request):
|
||||
"""
|
||||
Check whether there are any view restrictions on this page which are
|
||||
not fulfilled by the given request object. If there are, return an
|
||||
HttpResponse that will notify the user of that restriction (and possibly
|
||||
include a password / login form that will allow them to proceed). If
|
||||
there are no such restrictions, return None
|
||||
"""
|
||||
restrictions = self.get_view_restrictions()
|
||||
|
||||
if restrictions:
|
||||
passed_restrictions = request.session.get('passed_page_view_restrictions', [])
|
||||
for restriction in restrictions:
|
||||
if restriction.id not in passed_restrictions:
|
||||
from wagtail.wagtailcore.forms import PasswordPageViewRestrictionForm
|
||||
form = PasswordPageViewRestrictionForm(instance=restriction,
|
||||
initial={'return_url': request.get_full_path()})
|
||||
action_url = reverse('wagtailcore_authenticate_with_password', args=[restriction.id, self.id])
|
||||
return self.serve_password_required_response(request, form, action_url)
|
||||
|
||||
password_required_template = getattr(settings, 'PASSWORD_REQUIRED_TEMPLATE', 'wagtailcore/password_required.html')
|
||||
def serve_password_required_response(self, request, form, action_url):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,5 +1,25 @@
|
|||
from django.core.urlresolvers import reverse
|
||||
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
def check_view_restrictions(page, request, serve_args, serve_kwargs):
|
||||
return page.check_view_restrictions(request)
|
||||
"""
|
||||
Check whether there are any view restrictions on this page which are
|
||||
not fulfilled by the given request object. If there are, return an
|
||||
HttpResponse that will notify the user of that restriction (and possibly
|
||||
include a password / login form that will allow them to proceed). If
|
||||
there are no such restrictions, return None
|
||||
"""
|
||||
restrictions = page.get_view_restrictions()
|
||||
|
||||
if restrictions:
|
||||
passed_restrictions = request.session.get('passed_page_view_restrictions', [])
|
||||
for restriction in restrictions:
|
||||
if restriction.id not in passed_restrictions:
|
||||
from wagtail.wagtailcore.forms import PasswordPageViewRestrictionForm
|
||||
form = PasswordPageViewRestrictionForm(instance=restriction,
|
||||
initial={'return_url': request.get_full_path()})
|
||||
action_url = reverse('wagtailcore_authenticate_with_password', args=[restriction.id, page.id])
|
||||
return page.serve_password_required_response(request, form, action_url)
|
||||
|
||||
hooks.register('before_serve_page', check_view_restrictions)
|
||||
|
|
|
|||
Loading…
Reference in a new issue