Skip to content

Commit 4b52e99

Browse files
authored
fix: fetch org list only for course creator granted status and course admin can create new library (#588)
* feat: fetch organizations list only for granted course creators * fix: add ability for course instructors to create libraries same as course staff
1 parent 6e79a53 commit 4b52e99

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

cms/djangoapps/contentstore/tests/test_course_create_rerun.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ def test_course_creation_when_user_not_in_org(self):
207207
self.assertEqual(response.status_code, 403)
208208

209209
@override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True})
210+
@mock.patch(
211+
'cms.djangoapps.course_creators.admin.render_to_string',
212+
mock.Mock(side_effect=mock_render_to_string, autospec=True)
213+
)
210214
def test_course_creation_when_user_in_org_with_creator_role(self):
211215
"""
212216
Tests course creation with user having the organization content creation role.
@@ -217,6 +221,9 @@ def test_course_creation_when_user_in_org_with_creator_role(self):
217221
'description': 'Testing Organization Description',
218222
})
219223
update_org_role(self.global_admin, OrgContentCreatorRole, self.user, [self.source_course_key.org])
224+
self.course_creator_entry.all_organizations = True
225+
self.course_creator_entry.state = CourseCreator.GRANTED
226+
self.creator_admin.save_model(self.request, self.course_creator_entry, None, True)
220227
self.assertIn(self.source_course_key.org, get_allowed_organizations(self.user))
221228
response = self.client.ajax_post(self.course_create_rerun_url, {
222229
'org': self.source_course_key.org,

cms/djangoapps/contentstore/views/course.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ def get_organizations(user):
18341834
Returns the list of organizations for which the user is allowed to create courses.
18351835
"""
18361836
course_creator = CourseCreator.objects.filter(user=user).first()
1837-
if not course_creator:
1837+
if not course_creator or course_creator.state != CourseCreator.GRANTED:
18381838
return []
18391839
elif course_creator.all_organizations:
18401840
organizations = Organization.objects.all().values_list('short_name', flat=True)

cms/djangoapps/contentstore/views/library.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ def user_can_create_library(user, org=None):
8383
is_course_creator = get_course_creator_status(user) == 'granted'
8484
has_org_staff_role = OrgStaffRole().get_orgs_for_user(user).exists()
8585
has_course_staff_role = UserBasedRole(user=user, role=CourseStaffRole.ROLE).courses_with_role().exists()
86+
has_course_admin_role = UserBasedRole(user=user, role=CourseInstructorRole.ROLE).courses_with_role().exists()
8687

87-
return is_course_creator or has_org_staff_role or has_course_staff_role
88+
return is_course_creator or has_org_staff_role or has_course_staff_role or has_course_admin_role
8889
else:
8990
# EDUCATOR-1924: DISABLE_LIBRARY_CREATION overrides DISABLE_COURSE_CREATION, if present.
9091
disable_library_creation = settings.FEATURES.get('DISABLE_LIBRARY_CREATION', None)

cms/djangoapps/contentstore/views/tests/test_library.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from cms.djangoapps.contentstore.tests.utils import AjaxEnabledTestClient, CourseTestCase, parse_json
2020
from cms.djangoapps.contentstore.utils import reverse_course_url, reverse_library_url
2121
from cms.djangoapps.course_creators.views import add_user_with_status_granted as grant_course_creator_status
22-
from common.djangoapps.student.roles import LibraryUserRole, CourseStaffRole
22+
from common.djangoapps.student.roles import LibraryUserRole, CourseStaffRole, CourseInstructorRole
2323
from xmodule.modulestore.tests.factories import LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order
2424
from cms.djangoapps.course_creators.models import CourseCreator
2525

@@ -101,6 +101,14 @@ def test_library_creator_status_with_course_staff_role_for_enabled_creator_group
101101
auth.add_users(self.user, CourseStaffRole(self.course.id), nostaff_user)
102102
self.assertEqual(user_can_create_library(nostaff_user), True)
103103

104+
# When creator groups are enabled, course instructor members can create libraries
105+
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True)
106+
def test_library_creator_status_with_course_instructor_role_for_enabled_creator_group_setting(self):
107+
_, nostaff_user = self.create_non_staff_authed_user_client()
108+
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
109+
auth.add_users(self.user, CourseInstructorRole(self.course.id), nostaff_user)
110+
self.assertEqual(user_can_create_library(nostaff_user), True)
111+
104112
@ddt.data(
105113
(False, False, True),
106114
(False, True, False),
@@ -480,9 +488,14 @@ def test_allowed_organizations_for_library(self):
480488
# Assert that the method returned the expected value
481489
self.assertEqual(organizations, [])
482490
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
483-
organizations = get_allowed_organizations_for_libraries(self.user)
484-
# Assert that the method returned the expected value
485-
self.assertEqual(organizations, ['org1', 'org2'])
491+
# Assert that correct org values are returned based on course creator state
492+
for course_creator_state in CourseCreator.STATES:
493+
course_creator.state = course_creator_state
494+
organizations = get_allowed_organizations_for_libraries(self.user)
495+
if course_creator_state != CourseCreator.GRANTED:
496+
self.assertEqual(organizations, [])
497+
else:
498+
self.assertEqual(organizations, ['org1', 'org2'])
486499
with mock.patch.dict(
487500
'django.conf.settings.FEATURES',
488501
{"ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES": True}

0 commit comments

Comments
 (0)