Skip to content

Commit 0ac1b28

Browse files
committed
Revert "feat: AuthZ for course authoring compatibility layer (#38013)"
This reverts commit 12a46e6.
1 parent 4121681 commit 0ac1b28

26 files changed

Lines changed: 174 additions & 628 deletions

File tree

cms/djangoapps/contentstore/tests/test_course_listing.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,13 @@
3535
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
3636
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
3737
from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES
38-
from openedx.core.djangolib.testing.utils import AUTHZ_TABLES
3938
from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order
4039
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
4140
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order
4241

4342
TOTAL_COURSES_COUNT = 10
4443
USER_COURSES_COUNT = 1
4544

46-
QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES + AUTHZ_TABLES
47-
4845

4946
@ddt.ddt
5047
class TestCourseListing(ModuleStoreTestCase):
@@ -306,10 +303,10 @@ def test_course_listing_performance(self):
306303
courses_list, __ = _accessible_courses_list_from_groups(self.request)
307304
self.assertEqual(len(courses_list), USER_COURSES_COUNT)
308305

309-
with self.assertNumQueries(2, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST):
306+
with self.assertNumQueries(1, table_ignorelist=WAFFLE_TABLES):
310307
_accessible_courses_list_from_groups(self.request)
311308

312-
with self.assertNumQueries(2, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST):
309+
with self.assertNumQueries(2, table_ignorelist=WAFFLE_TABLES):
313310
_accessible_courses_iter_for_tests(self.request)
314311

315312
def test_course_listing_errored_deleted_courses(self):

cms/djangoapps/contentstore/views/library.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,24 @@ def _user_can_create_library_for_org(user, org=None):
7373
elif user.is_staff:
7474
return True
7575
elif settings.FEATURES.get('ENABLE_CREATOR_GROUP', False):
76+
org_filter_params = {}
77+
if org:
78+
org_filter_params['org'] = org
7679
is_course_creator = get_course_creator_status(user) == 'granted'
77-
if is_course_creator:
78-
return True
79-
80-
has_org_staff_role = OrgStaffRole().has_org_for_user(user, org)
81-
if has_org_staff_role:
82-
return True
83-
84-
has_course_staff_role = UserBasedRole(user=user, role=CourseStaffRole.ROLE).has_courses_with_role(org)
85-
if has_course_staff_role:
86-
return True
87-
88-
has_course_admin_role = UserBasedRole(user=user, role=CourseInstructorRole.ROLE).has_courses_with_role(org)
89-
if has_course_admin_role:
90-
return True
91-
92-
return False
80+
has_org_staff_role = OrgStaffRole().get_orgs_for_user(user).filter(**org_filter_params).exists()
81+
has_course_staff_role = (
82+
UserBasedRole(user=user, role=CourseStaffRole.ROLE)
83+
.courses_with_role()
84+
.filter(**org_filter_params)
85+
.exists()
86+
)
87+
has_course_admin_role = (
88+
UserBasedRole(user=user, role=CourseInstructorRole.ROLE)
89+
.courses_with_role()
90+
.filter(**org_filter_params)
91+
.exists()
92+
)
93+
return is_course_creator or has_org_staff_role or has_course_staff_role or has_course_admin_role
9394
else:
9495
# EDUCATOR-1924: DISABLE_LIBRARY_CREATION overrides DISABLE_COURSE_CREATION, if present.
9596
disable_library_creation = settings.FEATURES.get('DISABLE_LIBRARY_CREATION', None)

common/djangoapps/student/role_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
from openedx.core.lib.cache_utils import request_cached
1616
from common.djangoapps.student.roles import (
17-
AuthzCompatCourseAccessRole,
17+
CourseAccessRole,
1818
CourseBetaTesterRole,
1919
CourseInstructorRole,
2020
CourseStaffRole,
@@ -66,7 +66,7 @@ def get_role_cache(user: User) -> RoleCache:
6666

6767

6868
@request_cached()
69-
def get_course_roles(user: User) -> list[AuthzCompatCourseAccessRole]:
69+
def get_course_roles(user: User) -> list[CourseAccessRole]:
7070
"""
7171
Returns a list of all course-level roles that this user has.
7272

0 commit comments

Comments
 (0)