fix: allow_to_create_new_org checks org autocreate [FC-0076] (#36094)
Updates the StudioHome API's allow_to_create_new_org to require both organization-creation permissions and ORGANIZATION_AUTOCREATE to be enabled. It also adds the list of "allowed organizations for libraries" to the Studio Home API so that the Authoring MFE can use it.
This commit is contained in:
@@ -50,6 +50,10 @@ class StudioHomeSerializer(serializers.Serializer):
|
||||
child=serializers.CharField(),
|
||||
allow_empty=True
|
||||
)
|
||||
allowed_organizations_for_libraries = serializers.ListSerializer(
|
||||
child=serializers.CharField(),
|
||||
allow_empty=True
|
||||
)
|
||||
archived_courses = CourseCommonSerializer(required=False, many=True)
|
||||
can_access_advanced_settings = serializers.BooleanField()
|
||||
can_create_organizations = serializers.BooleanField()
|
||||
|
||||
@@ -5,6 +5,7 @@ from django.conf import settings
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from organizations import api as org_api
|
||||
from openedx.core.lib.api.view_utils import view_auth_classes
|
||||
|
||||
from ....utils import get_home_context, get_course_context, get_library_context
|
||||
@@ -51,6 +52,7 @@ class HomePageView(APIView):
|
||||
"allow_to_create_new_org": true,
|
||||
"allow_unicode_course_id": false,
|
||||
"allowed_organizations": [],
|
||||
"allowed_organizations_for_libraries": [],
|
||||
"archived_courses": [],
|
||||
"can_access_advanced_settings": true,
|
||||
"can_create_organizations": true,
|
||||
@@ -79,7 +81,12 @@ class HomePageView(APIView):
|
||||
|
||||
home_context = get_home_context(request, True)
|
||||
home_context.update({
|
||||
'allow_to_create_new_org': settings.FEATURES.get('ENABLE_CREATOR_GROUP', True) and request.user.is_staff,
|
||||
# 'allow_to_create_new_org' is actually about auto-creating organizations
|
||||
# (e.g. when creating a course or library), so we add an additional test.
|
||||
'allow_to_create_new_org': (
|
||||
home_context['can_create_organizations'] and
|
||||
org_api.is_autocreate_enabled()
|
||||
),
|
||||
'studio_name': settings.STUDIO_NAME,
|
||||
'studio_short_name': settings.STUDIO_SHORT_NAME,
|
||||
'studio_request_email': settings.FEATURES.get('STUDIO_REQUEST_EMAIL', ''),
|
||||
|
||||
@@ -32,9 +32,10 @@ class HomePageViewTest(CourseTestCase):
|
||||
self.url = reverse("cms.djangoapps.contentstore:v1:home")
|
||||
self.expected_response = {
|
||||
"allow_course_reruns": True,
|
||||
"allow_to_create_new_org": False,
|
||||
"allow_to_create_new_org": True,
|
||||
"allow_unicode_course_id": False,
|
||||
"allowed_organizations": [],
|
||||
"allowed_organizations_for_libraries": [],
|
||||
"archived_courses": [],
|
||||
"can_access_advanced_settings": True,
|
||||
"can_create_organizations": True,
|
||||
@@ -78,6 +79,17 @@ class HomePageViewTest(CourseTestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertDictEqual(expected_response, response.data)
|
||||
|
||||
@override_settings(ORGANIZATIONS_AUTOCREATE=False)
|
||||
def test_home_page_studio_with_org_autocreate_disabled(self):
|
||||
"""Check response content when Organization autocreate is disabled"""
|
||||
response = self.client.get(self.url)
|
||||
|
||||
expected_response = self.expected_response
|
||||
expected_response["allow_to_create_new_org"] = False
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertDictEqual(expected_response, response.data)
|
||||
|
||||
def test_taxonomy_list_link(self):
|
||||
response = self.client.get(self.url)
|
||||
self.assertTrue(response.data['taxonomies_enabled'])
|
||||
|
||||
Reference in New Issue
Block a user