Skip to content

Commit 59cd003

Browse files
refactor: use is_user_allowed instead of has permission to improve consistency
1 parent 769e223 commit 59cd003

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

openedx_authz/api/permissions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
__all__ = [
1818
"get_permission_from_policy",
1919
"get_all_permissions_in_scope",
20-
"has_permission",
20+
"is_subject_allowed",
2121
]
2222

2323

@@ -54,7 +54,7 @@ def get_all_permissions_in_scope(scope: ScopeData) -> list[PermissionData]:
5454
return [get_permission_from_policy(action) for action in actions]
5555

5656

57-
def has_permission(
57+
def is_subject_allowed(
5858
subject: SubjectData,
5959
action: ActionData,
6060
scope: ScopeData,

openedx_authz/api/users.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
ScopeData,
1717
UserData,
1818
)
19-
from openedx_authz.api.permissions import has_permission
19+
from openedx_authz.api.permissions import is_subject_allowed
2020
from openedx_authz.api.roles import (
2121
assign_role_to_subject_in_scope,
2222
batch_assign_role_to_subjects_in_scope,
@@ -37,7 +37,7 @@
3737
"get_user_role_assignments_in_scope",
3838
"get_user_role_assignments_for_role_in_scope",
3939
"get_all_user_role_assignments_in_scope",
40-
"user_has_permission",
40+
"is_user_allowed",
4141
]
4242

4343

@@ -169,7 +169,7 @@ def get_all_user_role_assignments_in_scope(
169169
)
170170

171171

172-
def user_has_permission(
172+
def is_user_allowed(
173173
user_external_key: str,
174174
action_external_key: str,
175175
scope_external_key: str,
@@ -184,7 +184,7 @@ def user_has_permission(
184184
Returns:
185185
bool: True if the user has the specified permission in the scope, False otherwise.
186186
"""
187-
return has_permission(
187+
return is_subject_allowed(
188188
UserData(external_key=user_external_key),
189189
ActionData(external_key=action_external_key),
190190
ScopeData(external_key=scope_external_key),

openedx_authz/tests/api/test_users.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
get_user_role_assignments_for_role_in_scope,
2020
get_user_role_assignments_in_scope,
2121
unassign_role_from_user,
22-
user_has_permission,
22+
is_user_allowed,
2323
)
2424
from openedx_authz.tests.api.test_roles import RolesTestSetupMixin
2525

@@ -401,13 +401,13 @@ class TestUserPermissions(UserAssignmentsSetupMixin):
401401
("peggy", "create_library_collection", "lib:Org2:physics_401", False),
402402
)
403403
@unpack
404-
def test_user_has_permission(self, username, action, scope_name, expected_result):
404+
def test_is_user_allowed(self, username, action, scope_name, expected_result):
405405
"""Test checking if a user has a specific permission in a given scope.
406406
407407
Expected result:
408408
- The function correctly identifies whether the user has the specified permission in the scope.
409409
"""
410-
result = user_has_permission(
410+
result = is_user_allowed(
411411
user_external_key=username,
412412
action_external_key=action,
413413
scope_external_key=scope_name,

0 commit comments

Comments
 (0)