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
This commit is contained in:
connorhaugh
2021-12-21 10:55:23 -05:00
committed by GitHub
parent 66eae81add
commit 4d834b977f
5 changed files with 97 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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:
<li class="action-item action-edit">
<button class="btn-default edit-button action-button">
<button class="btn-default edit-button action-button"
use-new-editor-text = ${use_new_editor_text}
use-new-editor-video = ${use_new_editor_video}
use-new-editor-problem = ${use_new_editor_problem}
authoring_MFE_base_url = ${get_editor_page_base_url(xblock.location.course_key)}
>
<span class="icon fa fa-pencil" aria-hidden="true"></span>
<span class="action-button-text">${_("Edit")}</span>
</button>