mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 03:31:04 +01:00
Add 'private' indicator in page chooser for pages with view restrictions
This commit is contained in:
parent
1ee707f405
commit
9e94c83843
@ -1,24 +1,23 @@
|
||||
{% load i18n wagtailadmin_tags %}
|
||||
|
||||
{% test_page_is_public page as is_public %}
|
||||
{% if not page_perms %}
|
||||
{% page_permissions page as page_perms %}
|
||||
{% endif %}
|
||||
|
||||
{% with page.get_view_restrictions as has_view_restrictions %}
|
||||
{% if page_perms.can_set_view_restrictions %}
|
||||
<div class="view-permission-indicator {% if has_view_restrictions %}private{% else %}public{% endif %}">
|
||||
<a href="{% url 'wagtailadmin_pages_set_view_restrictions' page.id %}" class="button button-small action-set-view-permissions">
|
||||
{# labels are shown/hidden in CSS according to the 'private' / 'public' class on view-permission-indicator #}
|
||||
<span class="label-public">{% trans 'Public' %}</span>
|
||||
<span class="label-private">{% trans 'Private' %}</span>
|
||||
</a>
|
||||
</div>
|
||||
{% if page_perms.can_set_view_restrictions %}
|
||||
<div class="view-permission-indicator {% if is_public %}public{% else %}private{% endif %}">
|
||||
<a href="{% url 'wagtailadmin_pages_set_view_restrictions' page.id %}" class="button button-small action-set-view-permissions">
|
||||
{# labels are shown/hidden in CSS according to the 'private' / 'public' class on view-permission-indicator #}
|
||||
<span class="label-public">{% trans 'Public' %}</span>
|
||||
<span class="label-private">{% trans 'Private' %}</span>
|
||||
</a>
|
||||
</div>
|
||||
{% else %}
|
||||
{# Read-only display, for users who don't have permission to set view restrictions #}
|
||||
{% if is_public %}
|
||||
<div class="view-permission-indicator public"><span class="label-public">{% trans 'Public' %}</span></div>
|
||||
{% else %}
|
||||
{# Read-only display, for users who don't have permission to set view restrictions #}
|
||||
{% if has_view_restrictions %}
|
||||
<div class="view-permission-indicator private"><span class="label-private">{% trans 'Private' %}</span></div>
|
||||
{% else %}
|
||||
<div class="view-permission-indicator public"><span class="label-public">{% trans 'Public' %}</span></div>
|
||||
{% endif %}
|
||||
<div class="view-permission-indicator private"><span class="label-private">{% trans 'Private' %}</span></div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
@ -42,6 +42,11 @@
|
||||
{% else %}
|
||||
<h2>{{ parent_page.title }}</h2>
|
||||
{% endif %}
|
||||
|
||||
{% test_page_is_public parent_page as is_public %}
|
||||
{% if not is_public %}
|
||||
<em>(private)</em>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if parent_page_perms.can_edit and 'edit' not in hide_actions|default:'' %}
|
||||
<h2><a href="{% url 'wagtailadmin_pages_edit' parent_page.id %}">{{ parent_page.title }}</a></h2>
|
||||
@ -155,6 +160,11 @@
|
||||
{% else %}
|
||||
{{ page.title }}
|
||||
{% endif %}
|
||||
|
||||
{% test_page_is_public page as is_public %}
|
||||
{% if not is_public %}
|
||||
<em>(private)</em>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if page_perms.can_edit and 'edit' not in hide_actions|default:'' %}
|
||||
<a href="{% url 'wagtailadmin_pages_edit' page.id %}" title="{% trans 'Edit this page' %}">{{ page.title }}</a>
|
||||
|
@ -7,7 +7,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from wagtail.wagtailadmin.menu import MenuItem
|
||||
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.models import get_navigation_menu_items, UserPagePermissionsProxy
|
||||
from wagtail.wagtailcore.models import get_navigation_menu_items, UserPagePermissionsProxy, PageViewRestriction
|
||||
from wagtail.wagtailcore.utils import camelcase_to_underscore
|
||||
|
||||
|
||||
@ -88,6 +88,26 @@ def page_permissions(context, page):
|
||||
return context['user_page_permissions'].for_page(page)
|
||||
|
||||
|
||||
@register.assignment_tag(takes_context=True)
|
||||
def test_page_is_public(context, page):
|
||||
"""
|
||||
Usage: {% test_page_is_public page as is_public %}
|
||||
Sets 'is_public' to True iff there are no page view restrictions in place on
|
||||
this page.
|
||||
Caches the list of page view restrictions in the context, to avoid repeated
|
||||
DB queries on repeated calls.
|
||||
"""
|
||||
if 'all_page_view_restriction_paths' not in context:
|
||||
context['all_page_view_restriction_paths'] = PageViewRestriction.objects.select_related('page').values_list('page__path', flat=True)
|
||||
|
||||
is_private = any([
|
||||
page.path.startswith(restricted_path)
|
||||
for restricted_path in context['all_page_view_restriction_paths']
|
||||
])
|
||||
|
||||
return not is_private
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def hook_output(hook_name):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user