diff --git a/wagtail/wagtailcore/wagtail_hooks.py b/wagtail/wagtailcore/wagtail_hooks.py index 67065dc082..c3553fc78c 100644 --- a/wagtail/wagtailcore/wagtail_hooks.py +++ b/wagtail/wagtailcore/wagtail_hooks.py @@ -4,7 +4,6 @@ from django.conf import settings from django.contrib.auth.views import redirect_to_login from django.core.urlresolvers import reverse -from wagtail.utils.compat import user_is_authenticated from wagtail.wagtailcore import hooks from wagtail.wagtailcore.models import PageViewRestriction @@ -23,24 +22,14 @@ def check_view_restrictions(page, request, serve_args, serve_kwargs): 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: + for restriction in page.get_view_restrictions(): + if not restriction.accept_request(request): if restriction.restriction_type == PageViewRestriction.PASSWORD: - 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) - elif restriction.restriction_type == PageViewRestriction.LOGIN: - if not user_is_authenticated(request.user): - return require_wagtail_login(next=request.get_full_path()) - elif restriction.restriction_type == PageViewRestriction.GROUPS: - if not request.user.is_superuser: - current_user_groups = request.user.groups.all() + 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) - if not any(group in current_user_groups for group in restriction.groups.all()): - return require_wagtail_login(next=request.get_full_path()) + elif restriction.restriction_type in [PageViewRestriction.LOGIN, PageViewRestriction.GROUPS]: + return require_wagtail_login(next=request.get_full_path())