Skip to content

Commit

Permalink
Display locked pages report only if user has 'unlock any page' permis…
Browse files Browse the repository at this point in the history
…sion for consistency with rfc
  • Loading branch information
jacobtoppm committed Jan 7, 2020
1 parent 8a6165a commit df194b4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
4 changes: 3 additions & 1 deletion wagtail/admin/templates/wagtailadmin/home/locked_pages.html
Original file line number Diff line number Diff line change
Expand Up @@ -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%"/>
Expand Down
3 changes: 2 additions & 1 deletion wagtail/admin/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def render(self):
'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)


Expand Down
2 changes: 1 addition & 1 deletion wagtail/admin/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
26 changes: 3 additions & 23 deletions wagtail/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,29 +1833,9 @@ def can_publish_pages(self):
"""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:
Expand Down

0 comments on commit df194b4

Please sign in to comment.