feat: Enable library blocks using settings [FC-0076] (#36292)

LIBRARY_ENABLED_BLOCKS added to verify enabled blocks in get_allowed_block_types
This commit is contained in:
Chris Chávez
2025-03-05 12:45:43 -05:00
committed by GitHub
parent af1f424910
commit 475d61729b
3 changed files with 50 additions and 3 deletions

View File

@@ -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',
]

View File

@@ -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)

View File

@@ -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):