@@ -1454,24 +1454,23 @@ def list(self, request, *args, **kwargs):
14541454 accesses = list (queryset .order_by ("document__path" ))
14551455
14561456 # Annotate more information on roles
1457- path_to_key_to_max_ancestors_role = defaultdict (
1458- lambda : defaultdict (lambda : None )
1459- )
1457+ # - accesses of the user (direct or via a team)
14601458 path_to_ancestors_roles = defaultdict (list )
14611459 path_to_role = defaultdict (lambda : None )
1460+ # - accesses of other users and teams
1461+ key_to_path_to_max_ancestors_role = defaultdict (
1462+ lambda : defaultdict (lambda : None )
1463+ )
14621464 for access in accesses :
14631465 key = access .target_key
14641466 path = access .document .path
14651467 parent_path = path [: - models .Document .steplen ]
14661468
1467- path_to_key_to_max_ancestors_role [path ][key ] = choices .RoleChoices .max (
1468- path_to_key_to_max_ancestors_role [path ][key ], access .role
1469- )
1470-
14711469 if parent_path :
1472- path_to_key_to_max_ancestors_role [path ][key ] = choices .RoleChoices .max (
1473- path_to_key_to_max_ancestors_role [parent_path ][key ],
1474- path_to_key_to_max_ancestors_role [path ][key ],
1470+ key_to_path_to_max_ancestors_role [key ][parent_path ] = (
1471+ choices .RoleChoices .max (
1472+ * key_to_path_to_max_ancestors_role [key ].values ()
1473+ )
14751474 )
14761475 path_to_ancestors_roles [path ].extend (
14771476 path_to_ancestors_roles [parent_path ]
@@ -1480,6 +1479,10 @@ def list(self, request, *args, **kwargs):
14801479 else :
14811480 path_to_ancestors_roles [path ] = []
14821481
1482+ key_to_path_to_max_ancestors_role [key ][path ] = choices .RoleChoices .max (
1483+ key_to_path_to_max_ancestors_role [key ][parent_path ], access .role
1484+ )
1485+
14831486 if access .user_id == user .id or access .team in user .teams :
14841487 path_to_role [path ] = choices .RoleChoices .max (
14851488 path_to_role [path ], access .role
@@ -1493,7 +1496,7 @@ def list(self, request, *args, **kwargs):
14931496 path = access .document .path
14941497 parent_path = path [: - models .Document .steplen ]
14951498 access .max_ancestors_role = (
1496- path_to_key_to_max_ancestors_role [ parent_path ][ access .target_key ]
1499+ key_to_path_to_max_ancestors_role [ access .target_key ][ parent_path ]
14971500 if parent_path
14981501 else None
14991502 )
0 commit comments