From df194b40f348fcfe0b447286b7c57ac96b2a12d1 Mon Sep 17 00:00:00 2001 From: jacobtm Date: Tue, 7 Jan 2020 14:57:00 +0000 Subject: [PATCH] Display locked pages report only if user has 'unlock any page' permission for consistency with rfc --- .../wagtailadmin/home/locked_pages.html | 4 ++- wagtail/admin/views/home.py | 3 ++- wagtail/admin/wagtail_hooks.py | 2 +- wagtail/core/models.py | 26 +++---------------- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/wagtail/admin/templates/wagtailadmin/home/locked_pages.html b/wagtail/admin/templates/wagtailadmin/home/locked_pages.html index 5e649d1cf..9f579cd21 100644 --- a/wagtail/admin/templates/wagtailadmin/home/locked_pages.html +++ b/wagtail/admin/templates/wagtailadmin/home/locked_pages.html @@ -3,7 +3,9 @@
{# TODO try moving these classes onto the section tag #}

{% trans "Your locked pages" %}

- {% trans "See all locked pages" %} + {% if can_remove_locks %} + {% trans "See all locked pages" %} + {% endif %} diff --git a/wagtail/admin/views/home.py b/wagtail/admin/views/home.py index cd9edc0d8..80ad25fc4 100644 --- a/wagtail/admin/views/home.py +++ b/wagtail/admin/views/home.py @@ -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) diff --git a/wagtail/admin/wagtail_hooks.py b/wagtail/admin/wagtail_hooks.py index 1d27c57fd..19842168d 100644 --- a/wagtail/admin/wagtail_hooks.py +++ b/wagtail/admin/wagtail_hooks.py @@ -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') diff --git a/wagtail/core/models.py b/wagtail/core/models.py index 3dcff0b4d..9c8ff9495 100644 --- a/wagtail/core/models.py +++ b/wagtail/core/models.py @@ -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: