(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

@@ -1530,11 +1530,7 @@ class DocumentAccessViewSet(
if role not in choices.PRIVILEGED_ROLES:
queryset = queryset.filter(role__in=choices.PRIVILEGED_ROLES)
accesses = list(
queryset.annotate(document_path=db.F("document__path")).order_by(
"document_path"
)
)
accesses = list(queryset.order_by("document__path"))
# Annotate more information on roles
path_to_key_to_max_ancestors_role = defaultdict(