Skip to content

Commit 20c5f96

Browse files
committed
feat: Port get_allowed_object_conditions() from Golang to Python (#369)
1 parent f3fc678 commit 20c5f96

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

casbin/enforcer.py

+19
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,22 @@ def get_implicit_users_for_resource_by_domain(self, resource, domain):
335335

336336
permissions = [list(t) for t in (list(key) for key in permissions.keys())]
337337
return permissions
338+
339+
def get_allowed_object_conditions(self, user, action, prefix):
340+
"""
341+
GetAllowedObjectConditions returns a string array of object conditions that the user can access.
342+
"""
343+
Permissions = self.get_implicit_permissions_for_user(user)
344+
345+
object_conditions = []
346+
347+
for policy in Permissions:
348+
if policy[2] == action:
349+
if not policy[1].startswith(prefix):
350+
return None
351+
object_conditions.append(policy[1].removeprefix(prefix))
352+
353+
if len(object_conditions) == 0:
354+
return None
355+
356+
return object_conditions

0 commit comments

Comments
 (0)