@@ -1451,24 +1451,23 @@ def list(self, request, *args, **kwargs):
1451
1451
accesses = list (queryset .order_by ("document__path" ))
1452
1452
1453
1453
# Annotate more information on roles
1454
- path_to_key_to_max_ancestors_role = defaultdict (
1455
- lambda : defaultdict (lambda : None )
1456
- )
1454
+ # - accesses of the user (direct or via a team)
1457
1455
path_to_ancestors_roles = defaultdict (list )
1458
1456
path_to_role = defaultdict (lambda : None )
1457
+ # - accesses of other users and teams
1458
+ key_to_path_to_max_ancestors_role = defaultdict (
1459
+ lambda : defaultdict (lambda : None )
1460
+ )
1459
1461
for access in accesses :
1460
1462
key = access .target_key
1461
1463
path = access .document .path
1462
1464
parent_path = path [: - models .Document .steplen ]
1463
1465
1464
- path_to_key_to_max_ancestors_role [path ][key ] = choices .RoleChoices .max (
1465
- path_to_key_to_max_ancestors_role [path ][key ], access .role
1466
- )
1467
-
1468
1466
if parent_path :
1469
- path_to_key_to_max_ancestors_role [path ][key ] = choices .RoleChoices .max (
1470
- path_to_key_to_max_ancestors_role [parent_path ][key ],
1471
- path_to_key_to_max_ancestors_role [path ][key ],
1467
+ key_to_path_to_max_ancestors_role [key ][parent_path ] = (
1468
+ choices .RoleChoices .max (
1469
+ * key_to_path_to_max_ancestors_role [key ].values ()
1470
+ )
1472
1471
)
1473
1472
path_to_ancestors_roles [path ].extend (
1474
1473
path_to_ancestors_roles [parent_path ]
@@ -1477,6 +1476,10 @@ def list(self, request, *args, **kwargs):
1477
1476
else :
1478
1477
path_to_ancestors_roles [path ] = []
1479
1478
1479
+ key_to_path_to_max_ancestors_role [key ][path ] = choices .RoleChoices .max (
1480
+ key_to_path_to_max_ancestors_role [key ][parent_path ], access .role
1481
+ )
1482
+
1480
1483
if access .user_id == user .id or access .team in user .teams :
1481
1484
path_to_role [path ] = choices .RoleChoices .max (
1482
1485
path_to_role [path ], access .role
@@ -1490,7 +1493,7 @@ def list(self, request, *args, **kwargs):
1490
1493
path = access .document .path
1491
1494
parent_path = path [: - models .Document .steplen ]
1492
1495
access .max_ancestors_role = (
1493
- path_to_key_to_max_ancestors_role [ parent_path ][ access .target_key ]
1496
+ key_to_path_to_max_ancestors_role [ access .target_key ][ parent_path ]
1494
1497
if parent_path
1495
1498
else None
1496
1499
)
0 commit comments