Skip to content

Commit

Permalink
Account for missing locked_at
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtoppm committed Jan 3, 2020
1 parent 3de77ba commit 8a6165a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
24 changes: 24 additions & 0 deletions wagtail/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,30 @@ 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()


class PagePermissionTester:
def __init__(self, user_perms, page):
Expand Down

0 comments on commit 8a6165a

Please sign in to comment.