From 4d834b977fb0d852434cf2bef6b13c0794eb5f56 Mon Sep 17 00:00:00 2001 From: connorhaugh <49422820+connorhaugh@users.noreply.github.com> Date: Tue, 21 Dec 2021 10:55:23 -0500 Subject: [PATCH] feat: add flags to studio for editors work (#29536) Description In order to support ongoing editor work we need to open blocks in the course_authoring MFE from studio. We are gating that rollout behind a flag. This work does that for each of the new blocks, as well as provides urls to do so. Supporting information List of flags: new_core_editors.use_new_text_editor new_core_editors.use_new_video_editor new_core_editors.use_new_problem_editor Documentation of those flags: Planned Removal Work: https://openedx.atlassian.net/browse/TNL-9370 --- cms/djangoapps/contentstore/toggles.py | 59 ++++++++++++++++++- cms/djangoapps/contentstore/utils.py | 14 +++++ .../contentstore/views/tests/utils.py | 2 +- cms/static/js/views/pages/container.js | 13 ++++ cms/templates/studio_xblock_wrapper.html | 13 +++- 5 files changed, 97 insertions(+), 4 deletions(-) diff --git a/cms/djangoapps/contentstore/toggles.py b/cms/djangoapps/contentstore/toggles.py index a35f9be8c4..2cda1199d8 100644 --- a/cms/djangoapps/contentstore/toggles.py +++ b/cms/djangoapps/contentstore/toggles.py @@ -1,7 +1,7 @@ """ CMS feature toggles. """ -from edx_toggles.toggles import LegacyWaffleFlag, LegacyWaffleFlagNamespace, SettingDictToggle +from edx_toggles.toggles import LegacyWaffleFlag, LegacyWaffleFlagNamespace, SettingDictToggle, WaffleFlag # .. toggle_name: FEATURES['ENABLE_EXPORT_GIT'] # .. toggle_implementation: SettingDictToggle @@ -81,3 +81,60 @@ def exam_setting_view_enabled(): Returns a boolean if proctoring exam setting mfe view is enabled. """ return ENABLE_EXAM_SETTINGS_HTML_VIEW.is_enabled() + + +# .. toggle_name: new_core_editors.use_new_text_editor +# .. toggle_implementation: WaffleFlag +# .. toggle_default: False +# .. toggle_description: This flag enables the use of the new core text xblock editor +# .. toggle_use_cases: temporary +# .. toggle_creation_date: 2021-12-1 +# .. toggle_target_removal_date: 2022-1-30 +# .. toggle_tickets: TNL-9306 +# .. toggle_warnings: +ENABLE_NEW_TEXT_EDITOR_FLAG = WaffleFlag('new_core_editors.use_new_text_editor', __name__) + + +def use_new_text_editor(): + """ + Returns a boolean = true if new text editor is enabled + """ + return ENABLE_NEW_TEXT_EDITOR_FLAG.is_enabled() + + +# .. toggle_name: new_core_editors.use_new_video_editor +# .. toggle_implementation: WaffleFlag +# .. toggle_default: False +# .. toggle_description: This flag enables the use of the new core video xblock editor +# .. toggle_use_cases: temporary +# .. toggle_creation_date: 2021-12-1 +# .. toggle_target_removal_date: 2022-1-30 +# .. toggle_tickets: TNL-9306 +# .. toggle_warnings: +ENABLE_NEW_VIDEO_EDITOR_FLAG = WaffleFlag('new_core_editors.use_new_video_editor', __name__) + + +def use_new_video_editor(): + """ + Returns a boolean = true if new video editor is enabled + """ + return ENABLE_NEW_VIDEO_EDITOR_FLAG.is_enabled() + + +# .. toggle_name: new_core_editors.use_new_problem_editor +# .. toggle_implementation: WaffleFlag +# .. toggle_default: False +# .. toggle_description: This flag enables the use of the new core problem xblock editor +# .. toggle_use_cases: temporary +# .. toggle_creation_date: 2021-12-1 +# .. toggle_target_removal_date: 2022-1-30 +# .. toggle_tickets: TNL-9306 +# .. toggle_warnings: +ENABLE_NEW_PROBLEM_EDITOR_FLAG = WaffleFlag('new_core_editors.use_new_problem_editor', __name__) + + +def use_new_problem_editor(): + """ + Returns a boolean if new problem editor is enabled + """ + return ENABLE_NEW_PROBLEM_EDITOR_FLAG.is_enabled() diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 268a6a6fcd..6ac1a62ded 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -26,6 +26,7 @@ from openedx.core.djangoapps.site_configuration import helpers as configuration_ from openedx.core.djangoapps.site_configuration.models import SiteConfiguration from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.content_type_gating.partitions import CONTENT_TYPE_GATING_SCHEME +from cms.djangoapps.contentstore.toggles import use_new_text_editor from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order @@ -197,6 +198,19 @@ def get_proctored_exam_settings_url(course_locator) -> str: return proctored_exam_settings_url +def get_editor_page_base_url(course_locator) -> str: + """ + Gets course authoring microfrontend URL for links to the new base editors + """ + editor_url = None + if use_new_text_editor(): + mfe_base_url = get_course_authoring_url(course_locator) + course_mfe_url = f'{mfe_base_url}/course/{course_locator}/editor' + if mfe_base_url: + editor_url = course_mfe_url + return editor_url + + def course_import_olx_validation_is_enabled(): """ Check if course olx validation is enabled on course import. diff --git a/cms/djangoapps/contentstore/views/tests/utils.py b/cms/djangoapps/contentstore/views/tests/utils.py index 9567211f8d..6225e1b738 100644 --- a/cms/djangoapps/contentstore/views/tests/utils.py +++ b/cms/djangoapps/contentstore/views/tests/utils.py @@ -66,7 +66,7 @@ class StudioPageTestCase(CourseTestCase): ) self.validate_html_for_action_button( html, - 'button class="btn-default edit-button action-button">', + 'button class="btn-default edit-button action-button"', can_edit ) self.validate_html_for_action_button( diff --git a/cms/static/js/views/pages/container.js b/cms/static/js/views/pages/container.js index f86f3b2a37..9500f5c4a9 100644 --- a/cms/static/js/views/pages/container.js +++ b/cms/static/js/views/pages/container.js @@ -186,6 +186,19 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page modal = new EditXBlockModal(options); event.preventDefault(); + // check if we want to launch with the new editors (behind waffle flag) + var useNewTextEditor = this.$('.edit-button').attr("use-new-editor-text"), + useNewVideoEditor = this.$('.edit-button').attr("use-new-editor-video"), + useNewProblemEditor = this.$('.edit-button').attr("use-new-editor-problem"), + blockType = xblockElement.find('.xblock').attr("data-block-type"); + if( (useNewTextEditor === "True" && blockType === "html") || + (useNewVideoEditor === "True" && blockType === "video") || + (useNewProblemEditor === "True" && blockType === "problem") + ) { + var destinationUrl = this.$('.edit-button').attr("authoring_MFE_base_url") + '/' + blockType + '/' + this.$('.studio-xblock-wrapper').attr("data-locator"); + window.location.replace(destinationUrl); + return; + } modal.edit(xblockElement, this.model, { readOnlyView: !this.options.canEdit, refresh: function() { diff --git a/cms/templates/studio_xblock_wrapper.html b/cms/templates/studio_xblock_wrapper.html index 8159f1fa44..15a2d3a857 100644 --- a/cms/templates/studio_xblock_wrapper.html +++ b/cms/templates/studio_xblock_wrapper.html @@ -2,13 +2,17 @@ <%! from django.utils.translation import gettext as _ from cms.djangoapps.contentstore.views.helpers import xblock_studio_url -from cms.djangoapps.contentstore.utils import is_visible_to_specific_partition_groups +from cms.djangoapps.contentstore.utils import is_visible_to_specific_partition_groups, get_editor_page_base_url from lms.lib.utils import is_unit from openedx.core.djangolib.js_utils import ( dump_js_escaped_json, js_escaped_string ) +from cms.djangoapps.contentstore.toggles import use_new_text_editor, use_new_problem_editor, use_new_video_editor %> <% +use_new_editor_text = use_new_text_editor() +use_new_editor_video = use_new_video_editor() +use_new_editor_problem = use_new_problem_editor() xblock_url = xblock_studio_url(xblock) show_inline = xblock.has_children and not xblock_url section_class = "level-nesting" if show_inline else "level-element" @@ -76,7 +80,12 @@ block_is_unit = is_unit(xblock) % if can_edit: % if not show_inline:
  • -