♻️(backend) stop requiring owner for non-root documents

If root documents are guaranteed to have a owner, non-root documents
will automatically have them as owner by inheritance. We should not
require non-root documents to have their own direct owner because
this will make it difficult to manage access rights when we move
documents around or when we want to remove access rights for someone
on a document subtree... There should be as few overrides as possible.
This commit is contained in:
Samuel Paccoud - DINUM
2025-05-04 22:16:34 +02:00
committed by Anthony LC
parent 1ab237af3b
commit 184b5c015b
7 changed files with 298 additions and 74 deletions

View File

@@ -1121,9 +1121,12 @@ class DocumentAccess(BaseAccess):
is_owner_or_admin = role in PRIVILEGED_ROLES
if self.role == RoleChoices.OWNER:
can_delete = (
role == RoleChoices.OWNER
and DocumentAccess.objects.filter(
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()
or DocumentAccess.objects.filter(
document_id=self.document_id, role=RoleChoices.OWNER
).count()
> 1