Skip to content

Commit

Permalink
feat: adds waffle flags for legacy libraries v1 and new libraries v2 …
Browse files Browse the repository at this point in the history
…in new Studio Home

These waffle flags replace the MFE env flag LIBRARY_MODE.
  • Loading branch information
pomegranited committed Oct 18, 2024
1 parent df7ad6d commit 0fdbc72
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cms/djangoapps/contentstore/rest_api/v1/serializers/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class StudioHomeSerializer(serializers.Serializer):
in_process_course_actions = UnsucceededCourseSerializer(many=True, required=False, allow_null=True)
libraries = LibraryViewSerializer(many=True, required=False, allow_null=True)
libraries_enabled = serializers.BooleanField()
libraries_v1_enabled = serializers.BooleanField()
libraries_v2_enabled = serializers.BooleanField()
taxonomies_enabled = serializers.BooleanField()
taxonomy_list_mfe_url = serializers.CharField()
optimization_enabled = serializers.BooleanField()
Expand Down
3 changes: 3 additions & 0 deletions cms/djangoapps/contentstore/rest_api/v1/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def get(self, request: Request):
"in_process_course_actions": [],
"libraries": [],
"libraries_enabled": true,
"libraries_v1_enabled": true,
"libraries_v2_enabled": true,
"library_authoring_mfe_url": "//localhost:3001/course/course-v1:edX+P315+2T2023",
"optimization_enabled": true,
"request_course_creator_url": "/request_course_creator",
"rerun_creator_status": true,
Expand Down
24 changes: 18 additions & 6 deletions cms/djangoapps/contentstore/rest_api/v1/views/tests/test_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ class HomePageViewTest(CourseTestCase):
def setUp(self):
super().setUp()
self.url = reverse("cms.djangoapps.contentstore:v1:home")

def test_home_page_courses_response(self):
"""Check successful response content"""
response = self.client.get(self.url)

expected_response = {
self.expected_response = {
"allow_course_reruns": True,
"allow_to_create_new_org": False,
"allow_unicode_course_id": False,
Expand All @@ -51,6 +46,8 @@ def test_home_page_courses_response(self):
"in_process_course_actions": [],
"libraries": [],
"libraries_enabled": True,
"libraries_v1_enabled": True,
"libraries_v2_enabled": False,
"taxonomies_enabled": True,
"taxonomy_list_mfe_url": 'http://course-authoring-mfe/taxonomies',
"optimization_enabled": False,
Expand All @@ -66,6 +63,21 @@ def test_home_page_courses_response(self):
"user_is_active": True,
}

def test_home_page_studio_response(self):
"""Check successful response content"""
response = self.client.get(self.url)

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertDictEqual(self.expected_response, response.data)

@override_settings(MEILISEARCH_ENABLED=True)
def test_home_page_studio_with_meilisearch_enabled(self):
"""Check response content when Meilisearch is enabled"""
response = self.client.get(self.url)

expected_response = self.expected_response
expected_response["libraries_v2_enabled"] = True

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertDictEqual(expected_response, response.data)

Expand Down
48 changes: 48 additions & 0 deletions cms/djangoapps/contentstore/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
CMS feature toggles.
"""
from edx_toggles.toggles import SettingDictToggle, WaffleFlag
from openedx.core.djangoapps.content.search import api as search_api
from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag

# .. toggle_name: FEATURES['ENABLE_EXPORT_GIT']
Expand Down Expand Up @@ -593,3 +594,50 @@ def default_enable_flexible_peer_openassessments(course_key):
level to opt in/out of rolling forward this feature.
"""
return DEFAULT_ENABLE_FLEXIBLE_PEER_OPENASSESSMENTS.is_enabled(course_key)


# .. toggle_name: contentstore.new_studio_mfe.disable_legacy_libraries
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Hides legacy (v1) Libraries tab in Authoring MFE.
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2024-10-02
# .. toggle_target_removal_date: 2025-04-09
# .. toggle_tickets: https://github.com/openedx/frontend-app-authoring/issues/1334
# .. toggle_warning: Legacy libraries are deprecated in Sumac, cf https://github.com/openedx/edx-platform/issues/32457
DISABLE_LEGACY_LIBRARIES = WaffleFlag(
f'{CONTENTSTORE_NAMESPACE}.new_studio_mfe.disable_legacy_libraries',
__name__,
CONTENTSTORE_LOG_PREFIX,
)


def libraries_v1_enabled():
"""
Returns a boolean if Libraries V2 is enabled in the new Studio Home.
"""
return not DISABLE_LEGACY_LIBRARIES.is_enabled()


# .. toggle_name: contentstore.new_studio_mfe.disable_new_libraries
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Hides new Libraries v2 tab in Authoring MFE.
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2024-10-02
# .. toggle_target_removal_date: 2025-04-09
# .. toggle_tickets: https://github.com/openedx/frontend-app-authoring/issues/1334
# .. toggle_warning: Libraries v2 are in beta for Sumac, will be fully supported in Teak.
DISABLE_NEW_LIBRARIES = WaffleFlag(
f'{CONTENTSTORE_NAMESPACE}.new_studio_mfe.disable_new_libraries',
__name__,
CONTENTSTORE_LOG_PREFIX,
)


def libraries_v2_enabled():
"""
Returns a boolean if Libraries V2 is enabled in the new Studio Home.
"""
# We use Meilisearch to index Libraries V2 content for display on new Studio Home.
return search_api.is_meilisearch_enabled() and not DISABLE_NEW_LIBRARIES.is_enabled()
8 changes: 7 additions & 1 deletion cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
from pytz import UTC
from xblock.fields import Scope

from cms.djangoapps.contentstore.toggles import exam_setting_view_enabled
from cms.djangoapps.contentstore.toggles import (
exam_setting_view_enabled,
libraries_v1_enabled,
libraries_v2_enabled,
)
from common.djangoapps.course_action_state.models import CourseRerunUIStateManager, CourseRerunState
from common.djangoapps.course_action_state.managers import CourseActionStateItemNotFoundError
from common.djangoapps.course_modes.models import CourseMode
Expand Down Expand Up @@ -1696,6 +1700,8 @@ def get_home_context(request, no_course=False):
'archived_courses': archived_courses,
'in_process_course_actions': in_process_course_actions,
'libraries_enabled': LIBRARIES_ENABLED,
'libraries_v1_enabled': libraries_v1_enabled(),
'libraries_v2_enabled': libraries_v2_enabled(),
'taxonomies_enabled': not is_tagging_feature_disabled(),
'taxonomy_list_mfe_url': get_taxonomy_list_url(),
'libraries': libraries,
Expand Down

0 comments on commit 0fdbc72

Please sign in to comment.