Skip to content

Commit dfc8c96

Browse files
refactor: change user to subject
1 parent 4c0d56e commit dfc8c96

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

openedx_authz/api/data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ScopeData:
5151
This class assumes that the scope is already namespaced appropriately
5252
before being passed in, as scopes can vary widely (e.g., courses, organizations).
5353
"""
54-
54+
# TODO: figure out namespace for scopes
5555
scope_id: str
5656

5757

@@ -146,6 +146,6 @@ class RoleAssignmentData:
146146
scope: The scope in which the role is assigned.
147147
"""
148148

149-
subject: UserData
149+
subject: SubjectData
150150
role: RoleData
151151
scope: ScopeData

openedx_authz/api/roles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"get_all_roles_names",
3030
"get_permissions_for_active_roles_in_scope",
3131
"get_role_definitions_in_scope",
32-
"assign_role_to_user_in_scope",
32+
"assign_role_to_subject_in_scope",
3333
"batch_assign_role_to_subjects_in_scope",
3434
"unassign_role_from_subject_in_scope",
3535
"batch_unassign_role_from_subjects_in_scope",
@@ -170,7 +170,7 @@ def get_all_roles_names() -> list[str]:
170170
return enforcer.get_all_subjects()
171171

172172

173-
def assign_role_to_user_in_scope(
173+
def assign_role_to_subject_in_scope(
174174
subject: SubjectData, role: RoleData, scope: ScopeData
175175
) -> None:
176176
"""Assign a role to a subject.

openedx_authz/api/users.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from openedx_authz.api.data import RoleData, ScopeData, SubjectData, UserData
1313
from openedx_authz.api.roles import (
14-
assign_role_to_user_in_scope,
14+
assign_role_to_subject_in_scope,
1515
batch_assign_role_to_subjects_in_scope,
1616
batch_unassign_role_from_subjects_in_scope,
1717
get_role_assignments_for_subject,
@@ -20,7 +20,7 @@
2020
)
2121

2222

23-
def assign_role_to_user(username: str, role_name: str, scope_id: str) -> bool:
23+
def assign_role_to_user_in_scope(username: str, role_name: str, scope_id: str) -> bool:
2424
"""Assign a role to a user in a specific scope.
2525
2626
Args:
@@ -31,7 +31,7 @@ def assign_role_to_user(username: str, role_name: str, scope_id: str) -> bool:
3131
Returns:
3232
bool: True if the assignment was successful, False otherwise.
3333
"""
34-
return assign_role_to_user_in_scope(
34+
return assign_role_to_subject_in_scope(
3535
UserData(username=username),
3636
RoleData(name=role_name),
3737
ScopeData(scope_id=scope_id),
@@ -94,8 +94,8 @@ def batch_unassign_role_from_users(
9494
)
9595

9696

97-
def get_roles_for_user(username: str) -> list[dict]:
98-
"""Get all roles with metadata assigned to a user in a specific scope.
97+
def get_role_assignments_for_user(username: str) -> list[dict]:
98+
"""Get all roles for a user across all scopes.
9999
100100
Args:
101101
user (str): ID of the user (e.g., 'john_doe').
@@ -106,7 +106,7 @@ def get_roles_for_user(username: str) -> list[dict]:
106106
return get_role_assignments_for_subject(UserData(username=username))
107107

108108

109-
def get_roles_for_user_in_scope(username: str, scope_id: str) -> list[str]:
109+
def get_role_assignments_for_user_in_scope(username: str, scope_id: str) -> list[str]:
110110
"""Get the roles assigned to a user in a specific scope.
111111
112112
Args:

openedx_authz/tests/api/test_roles.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _assign_roles_to_users(
6363
global_enforcer.load_policy() # Load policies to avoid duplicates
6464
if assignments:
6565
for assignment in assignments:
66-
assign_role_to_user_in_scope(
66+
assign_role_to_subject_in_scope(
6767
subject=SubjectData(subject_id=assignment["subject"]),
6868
role=RoleData(name=assignment["role_name"]),
6969
scope=ScopeData(scope_id=assignment["scope"]),
@@ -80,7 +80,7 @@ def _assign_roles_to_users(
8080
global_enforcer.clear_policy() # Clear to simulate fresh start for each test
8181
return
8282

83-
assign_role_to_user_in_scope(
83+
assign_role_to_subject_in_scope(
8484
subject=SubjectData(subject_id=subjects),
8585
role=RoleData(name=role),
8686
scope=ScopeData(scope_id=scope),
@@ -677,7 +677,7 @@ def test_batch_assign_role_to_subjects_in_scope(self, subjects, role, scope, bat
677677
"""
678678
if batch:
679679
for subject in subjects:
680-
assign_role_to_user_in_scope(
680+
assign_role_to_subject_in_scope(
681681
SubjectData(subject_id=subject),
682682
RoleData(name=role),
683683
ScopeData(scope_id=scope)
@@ -686,7 +686,7 @@ def test_batch_assign_role_to_subjects_in_scope(self, subjects, role, scope, bat
686686
role_names = {assignment.role.name for assignment in user_roles}
687687
self.assertIn(role, role_names)
688688
else:
689-
assign_role_to_user_in_scope(
689+
assign_role_to_subject_in_scope(
690690
SubjectData(subject_id=subjects),
691691
RoleData(name=role),
692692
ScopeData(scope_id=scope)

0 commit comments

Comments
 (0)