diff --git a/wagtail/admin/templates/wagtailadmin/reports/listing/_list_unlock.html b/wagtail/admin/templates/wagtailadmin/reports/listing/_list_unlock.html index 22e7806cc..4e386f1b4 100644 --- a/wagtail/admin/templates/wagtailadmin/reports/listing/_list_unlock.html +++ b/wagtail/admin/templates/wagtailadmin/reports/listing/_list_unlock.html @@ -7,23 +7,27 @@ {% page_permissions page as perms %}

- {% with page.locked_at|date:"d M Y H:i" as locking_date %} - {% if page.locked_by %} - {% if page.locked_by_id == request.user.pk %} - {% blocktrans %} - Locked by you at {{ locking_date }} - {% endblocktrans %} + {% if page.locked_at %} + {% with page.locked_at|date:"d M Y H:i" as locking_date %} + {% if page.locked_by %} + {% if page.locked_by_id == request.user.pk %} + {% blocktrans %} + Locked by you at {{ locking_date }} + {% endblocktrans %} + {% else %} + {% blocktrans with locked_by=page.locked_by %} + Locked by {{ locked_by }} at {{ locking_date }} + {% endblocktrans %} + {% endif %} {% else %} - {% blocktrans with locked_by=page.locked_by %} - Locked by {{ locked_by }} at {{ locking_date }} + {% blocktrans %} + Locked at {{ locking_date }} {% endblocktrans %} {% endif %} - {% else %} - {% blocktrans %} - Locked at {{ locking_date }} - {% endblocktrans %} - {% endif %} - {% endwith %} + {% endwith %} + {% else %} + {% trans 'Locked' %} + {% endif %}

{% if perms.can_unlock %}
diff --git a/wagtail/core/models.py b/wagtail/core/models.py index 68750448e..3dcff0b4d 100644 --- a/wagtail/core/models.py +++ b/wagtail/core/models.py @@ -1833,6 +1833,30 @@ 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() + class PagePermissionTester: def __init__(self, user_perms, page):