0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-30 11:10:43 +01:00

Make use of descendant_of in PagePermissionTester

This commit is contained in:
Sage Abdullah 2023-06-07 17:25:10 +01:00
parent 28db7624b2
commit 56d6e25fae
No known key found for this signature in database
GPG Key ID: EB1A33CC51CC0217

View File

@ -1,6 +1,3 @@
import operator
from functools import reduce
from django.contrib.auth import get_user_model
from django.db.models import (
CharField,
@ -80,14 +77,16 @@ class PagePermissionPolicy(BasePermissionPolicy):
if base_permission is True:
return self.model._default_manager.all()
or_queries = [
Q(path__startswith=perm.page.path, depth__gte=perm.page.depth)
perm_pages = [
perm.page
for perm in self.get_cached_permissions_for_user(user)
if perm.permission_type in actions
]
if not or_queries:
return self.model._default_manager.none()
return self.model._default_manager.filter(reduce(operator.or_, or_queries))
pages = self.model._default_manager.none()
for page in perm_pages:
pages |= self.model._default_manager.descendant_of(page, inclusive=True)
return pages
def users_with_any_permission_for_instance(self, actions, instance):
permissions = GroupPagePermission.objects.annotate(