diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py index 50aaaaded7..ded3b9d2f4 100644 --- a/cms/djangoapps/contentstore/views/component.py +++ b/cms/djangoapps/contentstore/views/component.py @@ -82,6 +82,16 @@ CONTAINER_TEMPLATES = [ "edit-title-button", "edit-upstream-alert", ] +DEFAULT_ADVANCED_MODULES = [ + 'google-calendar', + 'google-document', + 'lti_consumer', + 'poll', + 'split_test', + 'survey', + 'word_cloud', +] + def _advanced_component_types(show_unsupported): """ @@ -445,7 +455,7 @@ def get_component_templates(courselike, library=False): # lint-amnesty, pylint: # These modules should be specified as a list of strings, where the strings # are the names of the modules in ADVANCED_COMPONENT_TYPES that should be # enabled for the course. - course_advanced_keys = courselike.advanced_modules + course_advanced_keys = list(dict.fromkeys(courselike.advanced_modules + DEFAULT_ADVANCED_MODULES)) advanced_component_templates = { "type": "advanced", "templates": [], diff --git a/cms/djangoapps/contentstore/views/tests/test_block.py b/cms/djangoapps/contentstore/views/tests/test_block.py index ef85c446c8..019220246a 100644 --- a/cms/djangoapps/contentstore/views/tests/test_block.py +++ b/cms/djangoapps/contentstore/views/tests/test_block.py @@ -75,7 +75,7 @@ from lms.djangoapps.lms_xblock.mixin import NONSENSICAL_ACCESS_RESTRICTION from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration from openedx.core.djangoapps.content_tagging import api as tagging_api -from ..component import component_handler, get_component_templates +from ..component import component_handler, DEFAULT_ADVANCED_MODULES, get_component_templates from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import ( ALWAYS, VisibilityState, @@ -2900,6 +2900,16 @@ class TestComponentTemplates(CourseTestCase): self.templates = get_component_templates(self.course) + self.default_advanced_modules_titles = [ + "Google Calendar", + "Google Document", + "LTI Consumer", + "Poll", + "Content Experiment", + "Survey", + "Word cloud", + ] + def get_templates_of_type(self, template_type): """ Returns the templates for the specified type, or None if none is found. @@ -2953,7 +2963,11 @@ class TestComponentTemplates(CourseTestCase): self.assertGreater(len(self.get_templates_of_type("library")), 0) self.assertGreater(len(self.get_templates_of_type("html")), 0) self.assertGreater(len(self.get_templates_of_type("problem")), 0) - self.assertIsNone(self.get_templates_of_type("advanced")) + + # Check for default advanced modules + advanced_templates = self.get_templates_of_type("advanced") + advanced_module_keys = [t['category'] for t in advanced_templates] + self.assertCountEqual(advanced_module_keys, DEFAULT_ADVANCED_MODULES) # Now fully disable video through XBlockConfiguration XBlockConfiguration.objects.create(name="video", enabled=False) @@ -3001,29 +3015,38 @@ class TestComponentTemplates(CourseTestCase): """ Test the handling of advanced component templates. """ - self.course.advanced_modules.append("word_cloud") + self.course.advanced_modules.append("done") + EXPECTED_ADVANCED_MODULES_LENGTH = len(DEFAULT_ADVANCED_MODULES) + 1 self.templates = get_component_templates(self.course) advanced_templates = self.get_templates_of_type("advanced") - self.assertEqual(len(advanced_templates), 1) - world_cloud_template = advanced_templates[0] - self.assertEqual(world_cloud_template.get("category"), "word_cloud") - self.assertEqual(world_cloud_template.get("display_name"), "Word cloud") - self.assertIsNone(world_cloud_template.get("boilerplate_name", None)) + self.assertEqual(len(advanced_templates), EXPECTED_ADVANCED_MODULES_LENGTH) + done_template = advanced_templates[0] + self.assertEqual(done_template.get("category"), "done") + self.assertEqual(done_template.get("display_name"), "Completion") + self.assertIsNone(done_template.get("boilerplate_name", None)) - # Verify that non-advanced components are not added twice + # Verify that components are not added twice self.course.advanced_modules.append("video") self.course.advanced_modules.append("drag-and-drop-v2") + # Already defined advanced modules + self.course.advanced_modules.append("poll") + self.course.advanced_modules.append("google-document") + self.course.advanced_modules.append("survey") + self.templates = get_component_templates(self.course) advanced_templates = self.get_templates_of_type("advanced") - self.assertEqual(len(advanced_templates), 1) + self.assertEqual(len(advanced_templates), EXPECTED_ADVANCED_MODULES_LENGTH) only_template = advanced_templates[0] self.assertNotEqual(only_template.get("category"), "video") self.assertNotEqual(only_template.get("category"), "drag-and-drop-v2") + self.assertNotEqual(only_template.get("category"), "poll") + self.assertNotEqual(only_template.get("category"), "google-document") + self.assertNotEqual(only_template.get("category"), "survey") - # Now fully disable word_cloud through XBlockConfiguration - XBlockConfiguration.objects.create(name="word_cloud", enabled=False) + # Now fully disable done through XBlockConfiguration + XBlockConfiguration.objects.create(name="done", enabled=False) self.templates = get_component_templates(self.course) - self.assertIsNone(self.get_templates_of_type("advanced")) + self.assertTrue((not any(item.get("category") == "done" for item in self.get_templates_of_type("advanced")))) def test_advanced_problems(self): """ @@ -3084,8 +3107,9 @@ class TestComponentTemplates(CourseTestCase): XBlockConfiguration) if XBlockStudioConfigurationFlag is False. """ XBlockStudioConfigurationFlag.objects.create(enabled=False) - self.course.advanced_modules.extend(["annotatable", "survey"]) - self._verify_advanced_xblocks(["Annotation", "Survey"], [True, True]) + self.course.advanced_modules.extend(["annotatable", "done"]) + expected_xblocks = ["Annotation", "Completion"] + self.default_advanced_modules_titles + self._verify_advanced_xblocks(expected_xblocks, [True] * len(expected_xblocks)) def test_xblock_masquerading_as_problem(self): """