|
13 | 13 | from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user |
14 | 14 | from common.djangoapps.student.signals.signals import emit_course_access_role_added, emit_course_access_role_removed |
15 | 15 | from opaque_keys.edx.django.models import CourseKeyField |
16 | | -from opaque_keys import InvalidKeyError |
17 | 16 | from opaque_keys.edx.keys import CourseKey |
18 | | -from opaque_keys.edx.locator import CourseLocator, LibraryLocatorV2 |
| 17 | +from opaque_keys.edx.locator import CourseLocator |
19 | 18 | from openedx_authz.api import users as authz_api |
20 | | -from openedx_authz.api.data import RoleAssignmentData |
| 19 | +from openedx_authz.api.data import RoleAssignmentData, CourseOverviewData |
21 | 20 | from openedx_authz.constants import roles as authz_roles |
22 | 21 |
|
23 | 22 | from common.djangoapps.student.models import CourseAccessRole |
@@ -81,17 +80,17 @@ def authz_get_all_course_assignments_for_user(user: User) -> list[RoleAssignment |
81 | 80 | """ |
82 | 81 | assignments = authz_api.get_user_role_assignments(user_external_key=user.username) |
83 | 82 | # filter courses only |
84 | | - filtered_assignments = [assignment for assignment in assignments if assignment.scope.NAMESPACE == 'course-v1'] |
| 83 | + filtered_assignments = [ |
| 84 | + assignment for assignment in assignments |
| 85 | + if isinstance(assignment.scope, CourseOverviewData) |
| 86 | + ] |
85 | 87 | return filtered_assignments |
86 | 88 |
|
87 | 89 | def get_org_from_key(key: str) -> str: |
88 | 90 | """ |
89 | 91 | Get the org from a course or library key. |
90 | 92 | """ |
91 | | - try: |
92 | | - parsed_key = CourseKey.from_string(key) |
93 | | - except InvalidKeyError: |
94 | | - parsed_key = LibraryLocatorV2.from_string(key) |
| 93 | + parsed_key = CourseKey.from_string(key) |
95 | 94 | return parsed_key.org |
96 | 95 |
|
97 | 96 | def register_access_role(cls): |
|
0 commit comments