Skip to content

Commit 4b66f36

Browse files
committed
perf: Improve batch permission check
1 parent 2fecb3b commit 4b66f36

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

apps/common/auth/authentication.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ def is_permissions(*permission, compare=CompareConstants.OR):
9595

9696
def check_batch_permissions(request: Request, id_list: List[str], id_key: str, permissions: tuple,
9797
compare=CompareConstants.OR, **kwargs) -> List[str]:
98+
99+
if not id_list:
100+
return []
101+
102+
# workspace manager 直接放行
103+
# 预检
104+
kwargs[id_key] = '__workspace_level_pre_check__'
105+
pre_check = list(
106+
map(lambda p: exist(request.auth.role_list, request.auth.permission_list, p, request, **kwargs),
107+
permissions)
108+
)
109+
if any(pre_check) if compare == CompareConstants.OR else all(pre_check):
110+
return list(id_list)
111+
# 逐个资源校验
98112
result_list = []
99113
for resource_id in id_list:
100114
kwargs[id_key] = resource_id

0 commit comments

Comments
 (0)