(backend) add document path and depth to accesses endpoint

The frontend requires this information about the ancestor document
to which each access is related. We make sure it does not generate
more db queries and does not fetch useless and heavy fields from
the document like "excerpt".
This commit is contained in:
Samuel Paccoud - DINUM
2025-05-07 18:48:08 +02:00
committed by Anthony LC
parent 433cead0ac
commit 50faf766c8
5 changed files with 118 additions and 92 deletions

View File

@@ -1123,9 +1123,7 @@ class DocumentAccess(BaseAccess):
if self.role == RoleChoices.OWNER:
can_delete = role == RoleChoices.OWNER and (
# check if document is not root trying to avoid an extra query
# "document_path" is annotated by the viewset's list method
len(getattr(self, "document_path", "")) > Document.steplen
or not self.document.is_root()
self.document.depth > 1
or DocumentAccess.objects.filter(
document_id=self.document_id, role=RoleChoices.OWNER
).count()