Skip to content

Commit 637cbdd

Browse files
refactor: remove duplication while assigning
1 parent 75e61de commit 637cbdd

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

openedx_authz/api/roles.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,7 @@ def batch_assign_role_to_subjects_in_scope(
197197
role: The role to assign.
198198
"""
199199
for subject in subjects:
200-
201-
assert (
202-
get_subject_role_assignments_in_scope(subject, scope)
203-
== []
204-
), "Subject already has a role in the scope"
205-
206-
enforcer.add_role_for_user_in_domain(
207-
subject.subject_id, role.name, scope.scope_id
208-
)
200+
assign_role_to_subject_in_scope(subject, role, scope)
209201

210202

211203
def unassign_role_from_subject_in_scope(
@@ -234,7 +226,7 @@ def batch_unassign_role_from_subjects_in_scope(
234226
scope: The scope from which to unassign the role.
235227
"""
236228
for subject in subjects:
237-
enforcer.delete_roles_for_user_in_domain(subject, role.name, scope.scope_id)
229+
unassign_role_from_subject_in_scope(subject, role, scope)
238230

239231

240232
def get_subject_role_assignments(subject: SubjectData) -> list[RoleAssignmentData]:

0 commit comments

Comments
 (0)