mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-03-16 22:10:28 +00:00
Display locked pages report only if user has 'unlock any page' permission for consistency with rfc
This commit is contained in:
parent
8a6165add8
commit
df194b40f3
4 changed files with 9 additions and 26 deletions
|
|
@ -3,7 +3,9 @@
|
|||
<div class="panel nice-padding">{# TODO try moving these classes onto the section tag #}
|
||||
<section>
|
||||
<h2>{% trans "Your locked pages" %}</h2>
|
||||
<a href="{% url 'wagtailadmin_reports:locked_pages' %}" class="button button-small button-secondary">{% trans "See all locked pages" %}</a>
|
||||
{% if can_remove_locks %}
|
||||
<a href="{% url 'wagtailadmin_reports:locked_pages' %}" class="button button-small button-secondary">{% trans "See all locked pages" %}</a>
|
||||
{% endif %}
|
||||
<table class="listing listing-page">
|
||||
<col />
|
||||
<col width="15%"/>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,8 @@ class LockedPagesPanel:
|
|||
'locked_pages': Page.objects.filter(
|
||||
locked=True,
|
||||
locked_by=self.request.user,
|
||||
)
|
||||
),
|
||||
'can_remove_locks': UserPagePermissionsProxy(self.request.user).can_remove_locks()
|
||||
}, request=self.request)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -622,7 +622,7 @@ class ReportsMenuItem(SubmenuMenuItem):
|
|||
|
||||
class LockedPagesMenuItem(MenuItem):
|
||||
def is_shown(self, request):
|
||||
return UserPagePermissionsProxy(request.user).can_unlock_pages()
|
||||
return UserPagePermissionsProxy(request.user).can_remove_locks()
|
||||
|
||||
|
||||
@hooks.register('register_reports_menu_item')
|
||||
|
|
|
|||
|
|
@ -1833,29 +1833,9 @@ class UserPagePermissionsProxy:
|
|||
"""Return True if the user has permission to publish any pages"""
|
||||
return self.publishable_pages().exists()
|
||||
|
||||
def unlockable_pages(self):
|
||||
"""Return a queryset of the pages that this user has permission to unlock"""
|
||||
# Deal with the trivial cases first...
|
||||
if not self.user.is_active:
|
||||
return Page.objects.none()
|
||||
if self.user.is_superuser:
|
||||
return Page.objects.all()
|
||||
|
||||
unlockable_pages = Page.objects.none()
|
||||
|
||||
for perm in self.permissions.filter(permission_type='unlock'):
|
||||
# user has publish permission on any subpage of perm.page
|
||||
# (including perm.page itself)
|
||||
unlockable_pages |= Page.objects.descendant_of(perm.page, inclusive=True)
|
||||
|
||||
pages_locked_by_user = Page.objects.filter(locked_by=self.user)
|
||||
unlockable_pages |= pages_locked_by_user
|
||||
|
||||
return unlockable_pages
|
||||
|
||||
def can_unlock_pages(self):
|
||||
"""Return True if the user has permission to unlock any pages"""
|
||||
return self.unlockable_pages().exists()
|
||||
def can_remove_locks(self):
|
||||
"""Returns True if the user has permission to unlock pages they have not locked"""
|
||||
return self.user.is_superuser or self.permissions.filter(permission_type='unlock').exists()
|
||||
|
||||
|
||||
class PagePermissionTester:
|
||||
|
|
|
|||
Loading…
Reference in a new issue