Skip to content

Commit

Permalink
Disable further checking permissions if at least one is False (#7803)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev authored Apr 25, 2024
1 parent 2915bdd commit 734e748
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20240425_161412_sekachev.bs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Extra requests in PolicyEnforcer when at least one policy is rejected, others are not checked
(<https://github.com/cvat-ai/cvat/pull/7803>)
16 changes: 6 additions & 10 deletions cvat/apps/iam/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,14 @@ def check_permission(self, request, view, obj) -> bool:
if self.is_metadata_request(request, view) or obj and is_public_obj(obj):
return True

permissions: List[OpenPolicyAgentPermission] = []
iam_context = get_iam_context(request, obj)
for perm_class in OpenPolicyAgentPermission.__subclasses__():
for perm in perm_class.create(request, view, obj, iam_context):
result = perm.check_access()
if not result.allow:
return False

for perm in OpenPolicyAgentPermission.__subclasses__():
permissions.extend(perm.create(request, view, obj, iam_context))

allow = True
for perm in permissions:
result = perm.check_access()
allow &= result.allow

return allow
return True

def has_permission(self, request, view):
if not view.detail:
Expand Down

0 comments on commit 734e748

Please sign in to comment.