Skip to content

Commit 6488237

Browse files
committed
squash!: Fix conflicts
1 parent 2b01f04 commit 6488237

4 files changed

Lines changed: 21 additions & 28 deletions

File tree

openedx_authz/api/roles.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,5 @@ def get_all_role_assignments_per_scope_type(scope_types: tuple[type[ScopeData],
571571
list[RoleAssignmentData]: All assignments whose scope is an instance of any of the given scope types.
572572
"""
573573
return [
574-
role_assignment for role_assignment in get_role_assignments()
575-
if isinstance(role_assignment.scope, scope_types)
574+
role_assignment for role_assignment in get_role_assignments() if isinstance(role_assignment.scope, scope_types)
576575
]

openedx_authz/engine/utils.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ def migrate_legacy_course_roles_to_authz(course_access_role_model, course_id_lis
264264

265265
# Permission applied to individual user
266266
logger.info(
267-
f"Migrating permission for User: {permission.user.username} "
268-
f"to Role: {role} in Scope: {scope_external_key}"
267+
f"Migrating permission for User: {permission.user.username} to Role: {role} in Scope: {scope_external_key}"
269268
)
270269

271270
is_user_added = assign_role_to_user_in_scope(
@@ -322,25 +321,26 @@ def migrate_authz_to_legacy_course_roles(
322321
_validate_migration_input(course_id_list, org_id)
323322

324323
role_assignments = get_all_role_assignments_per_scope_type(
325-
scope_types=(CourseOverviewData, OrgCourseOverviewGlobData,)
324+
scope_types=(
325+
CourseOverviewData,
326+
OrgCourseOverviewGlobData,
327+
)
326328
)
327329

328330
# Two cases here:
329331
# 1. org_id provided: filter by org — includes org-level glob and course-level scopes for that org.
330332
# 2. only course_id_list provided: filter by course_id — org-level glob scopes are excluded (no course_id).
331333
if org_id:
332334
role_assignments = [
333-
role_assignment
334-
for role_assignment in role_assignments
335-
if role_assignment.scope.org == org_id
335+
role_assignment for role_assignment in role_assignments if role_assignment.scope.org == org_id
336336
]
337337

338338
if course_id_list and not org_id:
339339
role_assignments = [
340340
role_assignment
341341
for role_assignment in role_assignments
342-
if isinstance(role_assignment.scope, CourseOverviewData) and
343-
role_assignment.scope.course_id in course_id_list
342+
if isinstance(role_assignment.scope, CourseOverviewData)
343+
and role_assignment.scope.course_id in course_id_list
344344
]
345345

346346
roles_with_errors = []
@@ -350,13 +350,10 @@ def migrate_authz_to_legacy_course_roles(
350350
user_external_keys = {assignment.subject.external_key for assignment in role_assignments}
351351
users_by_username = {
352352
subject.user.username: subject.user
353-
for subject in user_subject_model.objects.filter(
354-
user__username__in=user_external_keys
355-
).select_related("user")
353+
for subject in user_subject_model.objects.filter(user__username__in=user_external_keys).select_related("user")
356354
}
357355

358356
for role_assignment in role_assignments:
359-
360357
# Per valid role assignment, create corresponding CourseAccessRole entry
361358
# depending on whether the scope is course-level or org-level glob
362359
try:

openedx_authz/tests/rest_api/test_views.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from openedx_authz.models.scopes import get_content_library_model, get_course_overview_model
2626
from openedx_authz.rest_api.data import RoleOperationError, RoleOperationStatus
2727
from openedx_authz.rest_api.v1.permissions import AnyScopePermission, DynamicScopePermission
28-
from openedx_authz.rest_api.v1.views import UserValidationAPIView
28+
from openedx_authz.rest_api.v1.views import ScopesAPIView, UserValidationAPIView
2929
from openedx_authz.tests.api.test_roles import BaseRolesTestCase
3030
from openedx_authz.tests.stubs.models import LearningPackage
3131

@@ -966,7 +966,7 @@ def setUp(self):
966966

967967
# Patch _build_queryset so tests don't need real DB querysets.
968968
self.build_qs_patcher = patch.object(
969-
views.ScopesAPIView,
969+
ScopesAPIView,
970970
"_build_queryset",
971971
return_value=self.fake_scopes,
972972
)
@@ -1029,9 +1029,9 @@ def test_type_param_calls_only_expected_queryset(self, scope_type, called_method
10291029
"""When type=course only courses are fetched; when type=library only libraries."""
10301030
self.build_qs_patcher.stop()
10311031
with (
1032-
patch.object(views.ScopesAPIView, called_method, return_value=[]) as mock_called,
1033-
patch.object(views.ScopesAPIView, skipped_method) as mock_skipped,
1034-
patch.object(views.ScopesAPIView, "_build_queryset", return_value=[]),
1032+
patch.object(ScopesAPIView, called_method, return_value=[]) as mock_called,
1033+
patch.object(ScopesAPIView, skipped_method) as mock_skipped,
1034+
patch.object(ScopesAPIView, "_build_queryset", return_value=[]),
10351035
):
10361036
response = self.client.get(self.url, {"scope_type": scope_type})
10371037
self.build_qs_patcher.start()
@@ -1050,9 +1050,9 @@ def test_type_param_absent_returns_both(self):
10501050
"""When type is not specified, both courses and libraries are returned."""
10511051
self.build_qs_patcher.stop()
10521052
with (
1053-
patch.object(views.ScopesAPIView, "_get_courses_queryset", return_value=[]) as mock_courses,
1054-
patch.object(views.ScopesAPIView, "_get_libraries_queryset", return_value=[]) as mock_libraries,
1055-
patch.object(views.ScopesAPIView, "_build_queryset", return_value=[]),
1053+
patch.object(ScopesAPIView, "_get_courses_queryset", return_value=[]) as mock_courses,
1054+
patch.object(ScopesAPIView, "_get_libraries_queryset", return_value=[]) as mock_libraries,
1055+
patch.object(ScopesAPIView, "_build_queryset", return_value=[]),
10561056
):
10571057
response = self.client.get(self.url)
10581058
self.build_qs_patcher.start()
@@ -1102,7 +1102,7 @@ def test_pagination(self, query_params: dict, expected_page_count: int, has_next
11021102
{"scope_id": self.COURSE_ORG2, "display_name_col": "Course 2", "org_name": "Org2", "scope_type": "course"},
11031103
]
11041104
self.build_qs_patcher.stop()
1105-
with patch.object(views.ScopesAPIView, "_build_queryset", return_value=mixed):
1105+
with patch.object(ScopesAPIView, "_build_queryset", return_value=mixed):
11061106
response = self.client.get(self.url, query_params)
11071107
self.build_qs_patcher.start()
11081108

openedx_authz/tests/test_migrations.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,9 +1301,7 @@ def test_migrate_org_level_scope_creates_org_glob_assignment(self):
13011301
AuthzEnforcer.get_enforcer().load_policy()
13021302

13031303
org_scope = OrgCourseOverviewGlobData.build_external_key(org_short_name_new)
1304-
assignments = get_user_role_assignments_in_scope(
1305-
user_external_key=user.username, scope_external_key=org_scope
1306-
)
1304+
assignments = get_user_role_assignments_in_scope(user_external_key=user.username, scope_external_key=org_scope)
13071305
self.assertEqual(len(assignments), 1)
13081306
self.assertEqual(assignments[0].roles[0], COURSE_ADMIN)
13091307

@@ -1404,8 +1402,7 @@ def test_course_id_list_filter_excludes_glob_and_other_courses(self):
14041402
AuthzEnforcer.get_enforcer().load_policy()
14051403

14061404
errors, successes = migrate_authz_to_legacy_course_roles(
1407-
CourseAccessRole, UserSubject,
1408-
course_id_list=[self.course_id], org_id=None, delete_after_migration=False
1405+
CourseAccessRole, UserSubject, course_id_list=[self.course_id], org_id=None, delete_after_migration=False
14091406
)
14101407

14111408
migrated_users = {assignment.subject.external_key for assignment in successes}

0 commit comments

Comments
 (0)