Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable taxonomy/tagging feature in MFE by default #34633

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from django.urls import reverse
from rest_framework import serializers

from cms.djangoapps.contentstore.toggles import use_tagging_taxonomy_list_page
from cms.djangoapps.contentstore.helpers import (
xblock_studio_url,
xblock_type_display_name,
)
from openedx.core.djangoapps.content_tagging.toggles import is_tagging_feature_disabled


class MessageValidation(serializers.Serializer):
Expand Down Expand Up @@ -122,7 +122,7 @@ def get_actions(self, obj): # pylint: disable=unused-argument
Method to get actions for each child xlock of the unit.
"""

can_manage_tags = use_tagging_taxonomy_list_page()
can_manage_tags = not is_tagging_feature_disabled()
xblock = obj["xblock"]
is_course = xblock.scope_ids.usage_id.context_key.is_course
xblock_url = xblock_studio_url(xblock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ def test_number_of_calls_to_db(self):
"""
Test to check number of queries made to mysql and mongo
"""
with self.assertNumQueries(29, table_ignorelist=WAFFLE_TABLES):
with self.assertNumQueries(31, table_ignorelist=WAFFLE_TABLES):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are from the tag count queries

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now +3: (1 for the course as a whole, 1 for all the blocks in the course, and 1 for getting the org-specific value of COURSE_AUTHORING_MICROFRONTEND_URL (within get_course_authoring_url within get_taxonomy_tags_widget_url within _get_course_index_context).

with check_mongo_calls(3):
self.client.get(self.url)
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
from django.urls import reverse
from edx_toggles.toggles.testutils import (
override_waffle_switch,
override_waffle_flag,
)
from rest_framework import status

from cms.djangoapps.contentstore.tests.utils import CourseTestCase
from cms.djangoapps.contentstore.tests.test_libraries import LibraryTestCase
from cms.djangoapps.contentstore.views.course import ENABLE_GLOBAL_STAFF_OPTIMIZATION
from cms.djangoapps.contentstore.toggles import ENABLE_TAGGING_TAXONOMY_LIST_PAGE
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
from xmodule.modulestore.tests.factories import CourseFactory

Expand Down Expand Up @@ -52,9 +50,9 @@ def test_home_page_courses_response(self):
"in_process_course_actions": [],
"libraries": [],
"libraries_enabled": True,
"taxonomies_enabled": False,
"taxonomies_enabled": True,
"library_authoring_mfe_url": settings.LIBRARY_AUTHORING_MICROFRONTEND_URL,
"taxonomy_list_mfe_url": None,
"taxonomy_list_mfe_url": 'http://course-authoring-mfe/taxonomies',
"optimization_enabled": False,
"redirect_to_library_authoring_mfe": False,
"request_course_creator_url": "/request_course_creator",
Expand All @@ -72,7 +70,6 @@ def test_home_page_courses_response(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertDictEqual(expected_response, response.data)

@override_waffle_flag(ENABLE_TAGGING_TAXONOMY_LIST_PAGE, True)
def test_taxonomy_list_link(self):
response = self.client.get(self.url)
self.assertTrue(response.data['taxonomies_enabled'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from xblock.validation import ValidationMessage

from cms.djangoapps.contentstore.tests.utils import CourseTestCase
from cms.djangoapps.contentstore.toggles import ENABLE_TAGGING_TAXONOMY_LIST_PAGE
from openedx.core.djangoapps.content_tagging.toggles import DISABLE_TAGGING_FEATURE
from xmodule.partitions.partitions import (
ENROLLMENT_TRACK_PARTITION_ID,
Group,
Expand Down Expand Up @@ -164,7 +164,6 @@ def test_xblock_is_published(self):
response = self.client.get(url)
self.assertTrue(response.data["is_published"])

@override_waffle_flag(ENABLE_TAGGING_TAXONOMY_LIST_PAGE, True)
def test_children_content(self):
"""
Check that returns valid response with children of vertical container.
Expand Down Expand Up @@ -238,7 +237,7 @@ def test_not_valid_usage_key_string(self):
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

@override_waffle_flag(ENABLE_TAGGING_TAXONOMY_LIST_PAGE, False)
@override_waffle_flag(DISABLE_TAGGING_FEATURE, True)
def test_actions_with_turned_off_taxonomy_flag(self):
"""
Check that action manage_tags for each child item has the same value as taxonomy flag.
Expand Down
18 changes: 0 additions & 18 deletions cms/djangoapps/contentstore/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,21 +597,3 @@ def default_enable_flexible_peer_openassessments(course_key):
level to opt in/out of rolling forward this feature.
"""
return DEFAULT_ENABLE_FLEXIBLE_PEER_OPENASSESSMENTS.is_enabled(course_key)


# .. toggle_name: new_studio_mfe.use_tagging_taxonomy_list_page
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: This flag enables the use of the taxonomy list page.
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2023-10-06
# .. toggle_target_removal_date: TBA
# .. toggle_warning:
ENABLE_TAGGING_TAXONOMY_LIST_PAGE = WaffleFlag('new_studio_mfe.use_tagging_taxonomy_list_page', __name__)


def use_tagging_taxonomy_list_page():
"""
Returns a boolean if taxonomy list page is enabled
"""
return ENABLE_TAGGING_TAXONOMY_LIST_PAGE.is_enabled()
42 changes: 24 additions & 18 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from common.djangoapps.xblock_django.api import deprecated_xblocks
from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService
from openedx.core import toggles as core_toggles
from openedx.core.djangoapps.content_tagging.toggles import is_tagging_feature_disabled
from openedx.core.djangoapps.credit.api import get_credit_requirements, is_credit_course
from openedx.core.djangoapps.discussions.config.waffle import ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration
Expand Down Expand Up @@ -90,7 +91,6 @@
use_new_video_editor,
use_new_video_uploads_page,
use_new_custom_pages,
use_tagging_taxonomy_list_page,
)
from cms.djangoapps.models.settings.course_grading import CourseGradingModel
from cms.djangoapps.models.settings.course_metadata import CourseMetadata
Expand Down Expand Up @@ -488,16 +488,19 @@ def get_custom_pages_url(course_locator) -> str:
return custom_pages_url


def get_taxonomy_list_url():
def get_taxonomy_list_url() -> str | None:
"""
Gets course authoring microfrontend URL for taxonomy list page view.
"""
taxonomy_list_url = None
if use_tagging_taxonomy_list_page():
mfe_base_url = settings.COURSE_AUTHORING_MICROFRONTEND_URL
if mfe_base_url:
taxonomy_list_url = f'{mfe_base_url}/taxonomies'
return taxonomy_list_url
if is_tagging_feature_disabled():
return None

mfe_base_url = settings.COURSE_AUTHORING_MICROFRONTEND_URL

if not mfe_base_url:
return None

return f'{mfe_base_url}/taxonomies'


def get_taxonomy_tags_widget_url(course_locator=None) -> str | None:
Expand All @@ -506,15 +509,18 @@ def get_taxonomy_tags_widget_url(course_locator=None) -> str | None:

The `content_id` needs to be appended to the end of the URL when using it.
"""
taxonomy_tags_widget_url = None
# Uses the same waffle flag as taxonomy list page
if use_tagging_taxonomy_list_page():
if is_tagging_feature_disabled():
return None

if course_locator:
mfe_base_url = get_course_authoring_url(course_locator)
else:
mfe_base_url = settings.COURSE_AUTHORING_MICROFRONTEND_URL
if course_locator:
mfe_base_url = get_course_authoring_url(course_locator)
if mfe_base_url:
taxonomy_tags_widget_url = f'{mfe_base_url}/tagging/components/widget/'
return taxonomy_tags_widget_url

if not mfe_base_url:
return None

return f'{mfe_base_url}/tagging/components/widget/'


def course_import_olx_validation_is_enabled():
Expand Down Expand Up @@ -1686,7 +1692,7 @@ def get_home_context(request, no_course=False):
'archived_courses': archived_courses,
'in_process_course_actions': in_process_course_actions,
'libraries_enabled': LIBRARIES_ENABLED,
'taxonomies_enabled': use_tagging_taxonomy_list_page(),
'taxonomies_enabled': not is_tagging_feature_disabled(),
'redirect_to_library_authoring_mfe': should_redirect_to_library_authoring_mfe(),
'library_authoring_mfe_url': LIBRARY_AUTHORING_MICROFRONTEND_URL,
'taxonomy_list_mfe_url': get_taxonomy_list_url(),
Expand Down Expand Up @@ -1982,7 +1988,7 @@ def get_container_handler_context(request, usage_key, course, xblock): # pylint
prev_url = quote_plus(prev_url) if prev_url else None
next_url = quote_plus(next_url) if next_url else None

show_unit_tags = use_tagging_taxonomy_list_page()
show_unit_tags = not is_tagging_feature_disabled()
unit_tags = None
if show_unit_tags and is_unit_page:
unit_tags = get_unit_tags(usage_key)
Expand Down
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/views/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from xmodule.modulestore.django import (
modulestore,
) # lint-amnesty, pylint: disable=wrong-import-order
from cms.djangoapps.contentstore.toggles import use_tagging_taxonomy_list_page
from openedx.core.djangoapps.content_tagging.toggles import is_tagging_feature_disabled

from xmodule.x_module import (
AUTHOR_VIEW,
Expand Down Expand Up @@ -242,7 +242,7 @@ def xblock_view_handler(request, usage_key_string, view_name):

# Fetch tags of children components
tags_count_map = {}
if use_tagging_taxonomy_list_page():
if not is_tagging_feature_disabled():
tags_count_map = get_children_tags_count(xblock)

# Set up the context to be passed to each XBlock's render method.
Expand Down
3 changes: 0 additions & 3 deletions cms/djangoapps/contentstore/views/tests/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from openedx_events.content_authoring.signals import XBLOCK_DUPLICATED
from openedx_events.tests.utils import OpenEdxEventsTestMixin
from edx_proctoring.exceptions import ProctoredExamNotFoundException
from edx_toggles.toggles.testutils import override_waffle_flag
from opaque_keys import InvalidKeyError
from opaque_keys.edx.asides import AsideUsageKeyV2
from opaque_keys.edx.keys import CourseKey, UsageKey
Expand Down Expand Up @@ -85,7 +84,6 @@
add_container_page_publishing_info,
create_xblock_info,
)
from cms.djangoapps.contentstore.toggles import ENABLE_TAGGING_TAXONOMY_LIST_PAGE


class AsideTest(XBlockAside):
Expand Down Expand Up @@ -272,7 +270,6 @@ def test_get_container_nested_container_fragment(self):
),
)

@override_waffle_flag(ENABLE_TAGGING_TAXONOMY_LIST_PAGE, True)
@patch("cms.djangoapps.contentstore.xblock_storage_handlers.xblock_helpers.get_object_tag_counts")
def test_tag_count_in_container_fragment(self, mock_get_object_tag_counts):
root_usage_key = self._create_vertical()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def test_number_of_calls_to_db(self):
"""
Test to check number of queries made to mysql and mongo
"""
with self.assertNumQueries(26, table_ignorelist=WAFFLE_TABLES):
with self.assertNumQueries(28, table_ignorelist=WAFFLE_TABLES):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are from the tag count queries

with check_mongo_calls(3):
self.client.get_html(reverse_course_url('course_handler', self.course.id))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from xblock.fields import Scope

from cms.djangoapps.contentstore.config.waffle import SHOW_REVIEW_RULES_FLAG
from cms.djangoapps.contentstore.toggles import ENABLE_COPY_PASTE_UNITS, use_tagging_taxonomy_list_page
from cms.djangoapps.contentstore.toggles import ENABLE_COPY_PASTE_UNITS
from cms.djangoapps.models.settings.course_grading import CourseGradingModel
from cms.lib.ai_aside_summary_config import AiAsideSummaryConfig
from common.djangoapps.static_replace import replace_static_urls
Expand All @@ -44,6 +44,7 @@
from common.djangoapps.util.date_utils import get_default_time_display
from common.djangoapps.util.json_request import JsonResponse, expect_json
from openedx.core.djangoapps.bookmarks import api as bookmarks_api
from openedx.core.djangoapps.content_tagging.toggles import is_tagging_feature_disabled
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration
from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE
from openedx.core.lib.gating import api as gating_api
Expand Down Expand Up @@ -1217,7 +1218,7 @@ def create_xblock_info( # lint-amnesty, pylint: disable=too-many-statements
xblock_info["ancestor_has_staff_lock"] = False
if tags is not None:
xblock_info["tags"] = tags
if use_tagging_taxonomy_list_page():
if not is_tagging_feature_disabled():
xblock_info["taxonomy_tags_widget_url"] = get_taxonomy_tags_widget_url()
xblock_info["course_authoring_url"] = settings.COURSE_AUTHORING_MICROFRONTEND_URL

Expand All @@ -1240,9 +1241,9 @@ def create_xblock_info( # lint-amnesty, pylint: disable=too-many-statements
else:
xblock_info["hide_from_toc_message"] = False

# If the ENABLE_TAGGING_TAXONOMY_LIST_PAGE feature flag is enabled, we show the "Manage Tags" options
if use_tagging_taxonomy_list_page():
xblock_info["use_tagging_taxonomy_list_page"] = True
# Don't show the "Manage Tags" option if the DISABLE_TAGGING_FEATURE waffle is true
xblock_info["is_tagging_feature_disabled"] = is_tagging_feature_disabled()
if not is_tagging_feature_disabled():
xblock_info["tag_counts_by_unit"] = _get_course_unit_tags(xblock.location.context_key)

xblock_info[
Expand Down
3 changes: 1 addition & 2 deletions cms/static/js/views/xblock_outline.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ function($, _, gettext, BaseView, ViewUtils, XBlockViewUtils, XBlockStringFieldE
hideFromTOCMessage: this.model.get('hide_from_toc_message'),
enableHideFromTOC: this.model.get('hide_from_toc'),
course: course,
enableCopyPasteUnits: this.model.get("enable_copy_paste_units"), // ENABLE_COPY_PASTE_UNITS waffle flag
useTaggingTaxonomyListPage: this.model.get("use_tagging_taxonomy_list_page"), // ENABLE_TAGGING_TAXONOMY_LIST_PAGE waffle flag
bradenmacdonald marked this conversation as resolved.
Show resolved Hide resolved
enableCopyPasteUnits: this.model.get('enable_copy_paste_units'), // ENABLE_COPY_PASTE_UNITS waffle flag
};
},

Expand Down
5 changes: 3 additions & 2 deletions cms/templates/studio_xblock_wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
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_video_gallery_flow, use_tagging_taxonomy_list_page
from cms.djangoapps.contentstore.toggles import use_new_text_editor, use_new_problem_editor, use_new_video_editor, use_video_gallery_flow
from openedx.core.djangoapps.content_tagging.toggles import is_tagging_feature_disabled
%>
<%
use_new_editor_text = use_new_text_editor()
use_new_editor_video = use_new_video_editor()
use_new_editor_problem = use_new_problem_editor()
use_new_video_gallery_flow = use_video_gallery_flow()
use_tagging = use_tagging_taxonomy_list_page()
use_tagging = not is_tagging_feature_disabled()
bradenmacdonald marked this conversation as resolved.
Show resolved Hide resolved
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"
Expand Down
24 changes: 22 additions & 2 deletions openedx/core/djangoapps/content_tagging/toggles.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

"""
Toggles for content tagging
"""

from edx_toggles.toggles import WaffleFlag

from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag


# .. toggle_name: content_tagging.auto
# .. toggle_implementation: WaffleSwitch
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: Setting this enables automatic tagging of content
# .. toggle_type: feature_flag
Expand All @@ -15,3 +17,21 @@
# .. toggle_creation_date: 2023-08-30
# .. toggle_tickets: https://github.com/openedx/modular-learning/issues/79
CONTENT_TAGGING_AUTO = CourseWaffleFlag('content_tagging.auto', __name__)


# .. toggle_name: content_tagging.disabled
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Setting this disables the tagging feature
# .. toggle_type: feature_flag
# .. toggle_category: admin
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2024-04-30
DISABLE_TAGGING_FEATURE = WaffleFlag('content_tagging.disabled', __name__)


def is_tagging_feature_disabled():
"""
Returns a boolean if tagging feature list page is disabled
"""
return DISABLE_TAGGING_FEATURE.is_enabled()
Loading