Skip to content

Commit

Permalink
feat: fetch organizations list only for granted course creators
Browse files Browse the repository at this point in the history
  • Loading branch information
kaustavb12 committed Sep 20, 2023
1 parent d5e16f5 commit c64518c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 7 additions & 0 deletions cms/djangoapps/contentstore/tests/test_course_create_rerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ def test_course_creation_when_user_not_in_org(self):
self.assertEqual(response.status_code, 403)

@override_settings(FEATURES={'ENABLE_CREATOR_GROUP': True})
@mock.patch(
'cms.djangoapps.course_creators.admin.render_to_string',
mock.Mock(side_effect=mock_render_to_string, autospec=True)
)
def test_course_creation_when_user_in_org_with_creator_role(self):
"""
Tests course creation with user having the organization content creation role.
Expand All @@ -217,6 +221,9 @@ def test_course_creation_when_user_in_org_with_creator_role(self):
'description': 'Testing Organization Description',
})
update_org_role(self.global_admin, OrgContentCreatorRole, self.user, [self.source_course_key.org])
self.course_creator_entry.all_organizations = True
self.course_creator_entry.state = CourseCreator.GRANTED
self.creator_admin.save_model(self.request, self.course_creator_entry, None, True)
self.assertIn(self.source_course_key.org, get_allowed_organizations(self.user))
response = self.client.ajax_post(self.course_create_rerun_url, {
'org': self.source_course_key.org,
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,7 @@ def get_organizations(user):
Returns the list of organizations for which the user is allowed to create courses.
"""
course_creator = CourseCreator.objects.filter(user=user).first()
if not course_creator:
if not course_creator or course_creator.state != CourseCreator.GRANTED:
return []
elif course_creator.all_organizations:
organizations = Organization.objects.all().values_list('short_name', flat=True)
Expand Down
11 changes: 8 additions & 3 deletions cms/djangoapps/contentstore/views/tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,14 @@ def test_allowed_organizations_for_library(self):
# Assert that the method returned the expected value
self.assertEqual(organizations, [])
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
organizations = get_allowed_organizations_for_libraries(self.user)
# Assert that the method returned the expected value
self.assertEqual(organizations, ['org1', 'org2'])
# Assert that correct org values are returned based on course creator state
for course_creator_state in CourseCreator.STATES:
course_creator.state = course_creator_state
organizations = get_allowed_organizations_for_libraries(self.user)
if course_creator_state != CourseCreator.GRANTED:
self.assertEqual(organizations, [])
else:
self.assertEqual(organizations, ['org1', 'org2'])
with mock.patch.dict(
'django.conf.settings.FEATURES',
{"ENABLE_ORGANIZATION_STAFF_ACCESS_FOR_CONTENT_LIBRARIES": True}
Expand Down

0 comments on commit c64518c

Please sign in to comment.