mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Account for missing locked_at
This commit is contained in:
parent
3de77ba5d7
commit
8a6165add8
@ -7,23 +7,27 @@
|
||||
<td>
|
||||
{% page_permissions page as perms %}
|
||||
<p>
|
||||
{% 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 <b>you</b> at <b>{{ locking_date }}</b>
|
||||
{% 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 <b>you</b> at <b>{{ locking_date }}</b>
|
||||
{% endblocktrans %}
|
||||
{% else %}
|
||||
{% blocktrans with locked_by=page.locked_by %}
|
||||
Locked by <b>{{ locked_by }}</b> at <b>{{ locking_date }}</b>
|
||||
{% endblocktrans %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% blocktrans with locked_by=page.locked_by %}
|
||||
Locked by <b>{{ locked_by }}</b> at <b>{{ locking_date }}</b>
|
||||
{% blocktrans %}
|
||||
Locked at <b>{{ locking_date }}</b>
|
||||
{% endblocktrans %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% blocktrans %}
|
||||
Locked at <b>{{ locking_date }}</b>
|
||||
{% endblocktrans %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% else %}
|
||||
{% trans 'Locked' %}
|
||||
{% endif %}
|
||||
</p>
|
||||
{% if perms.can_unlock %}
|
||||
<form action="{% url 'wagtailadmin_pages:unlock' page.id %}" method="post">
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user