From 475d61729bcb853e0d9e8b8fa73bb01578892226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Ch=C3=A1vez?= Date: Wed, 5 Mar 2025 12:45:43 -0500 Subject: [PATCH] feat: Enable library blocks using settings [FC-0076] (#36292) LIBRARY_ENABLED_BLOCKS added to verify enabled blocks in get_allowed_block_types --- cms/envs/common.py | 23 +++++++++++++++++++ .../core/djangoapps/content_libraries/api.py | 11 ++++++--- .../tests/test_content_libraries.py | 19 +++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 02464ab0e3..6f49a86236 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -2925,3 +2925,26 @@ MEILISEARCH_API_KEY = "devkey" # .. for now it wil impact country listing in auth flow and user profile. # .. eg ['US', 'CA'] DISABLED_COUNTRIES = [] + +# .. setting_name: LIBRARY_ENABLED_BLOCKS +# .. setting_default: ['problem', 'video', 'html', 'drag-and-drop-v2'] +# .. setting_description: List of block types that are ready/enabled to be created/used +# .. in libraries. Both basic blocks and advanced blocks can be included. +# .. In the future, we will support individual configuration per library - see +# .. openedx/core/djangoapps/content_libraries/api.py::get_allowed_block_types() +LIBRARY_ENABLED_BLOCKS = [ + 'problem', + 'video', + 'html', + 'drag-and-drop-v2', + 'conditional', + 'done', + 'freetextresponse', + 'google-calendar', + 'google-document', + 'invideoquiz', + 'pdf', + 'poll', + 'survey', + 'word_cloud', +] diff --git a/openedx/core/djangoapps/content_libraries/api.py b/openedx/core/djangoapps/content_libraries/api.py index c51c707fc4..15d628a74a 100644 --- a/openedx/core/djangoapps/content_libraries/api.py +++ b/openedx/core/djangoapps/content_libraries/api.py @@ -1317,12 +1317,17 @@ def get_allowed_block_types(library_key): # pylint: disable=unused-argument # use content libraries APIs directly but some tests may want to use them to # create libraries and then test library learning or course-library integration. from cms.djangoapps.contentstore import helpers as studio_helpers - # TODO: return support status and template options - # See cms/djangoapps/contentstore/views/component.py block_types = sorted(name for name, class_ in XBlock.load_classes()) + # Get enabled block types + # + # TODO: For now we are using `settings.LIBRARY_ENABLED_BLOCKS` without filtering + # to return the enabled block types for all libraries. In the future, filtering will be + # done based on a custom configuration per library. + enabled_block_types = [item for item in block_types if item in settings.LIBRARY_ENABLED_BLOCKS] + info = [] - for block_type in block_types: + for block_type in enabled_block_types: # TODO: unify the contentstore helper with the xblock.api version of # xblock_type_display_name display_name = studio_helpers.xblock_type_display_name(block_type, None) diff --git a/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py b/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py index f3a111cb05..7295e3bab0 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py @@ -1142,6 +1142,25 @@ class ContentLibrariesTestCase(ContentLibrariesRestApiTest, OpenEdxEventsTestMix "id": f"lb:CL-TEST:test_lib_paste_clipboard:problem:{pasted_block_id}", }) + @override_settings(LIBRARY_ENABLED_BLOCKS=['problem', 'video', 'html']) + def test_library_get_enabled_blocks(self): + expected = [ + {"block_type": "html", "display_name": "Text"}, + {"block_type": "problem", "display_name": "Problem"}, + {"block_type": "video", "display_name": "Video"}, + ] + + author = UserFactory.create(username="Author", email="author@example.com", is_staff=True) + with self.as_user(author): + lib = self._create_library( + slug="test_lib_enabled_blocks", + title="Get Enabled Blocks Test Library", + description="Testing get enabled blocks from library" + ) + lib_id = lib["id"] + block_types = self._get_library_block_types(lib_id) + assert [dict(item) for item in block_types] == expected + @ddt.ddt class ContentLibraryXBlockValidationTest(APITestCase):