From 19014463b13849acc22f2e6db6a234206696f86d Mon Sep 17 00:00:00 2001 From: andrii-hantkovskyi <131773947+andrii-hantkovskyi@users.noreply.github.com> Date: Fri, 16 May 2025 15:37:41 +0300 Subject: [PATCH] feat: [AXM-2056] add catalog MFE enabled waffle flag (#2639) * feat: [AXM-2056] add catalog MFE enabled waffle flag * test: cover waffle with test * refactor: fix pylint error * refactor: redesign waffleflag & add new MFE toggle to FEATURES * test: update tests to new functionality * refactor: add toggle_use_cases to annotation * refactor: redesign again to use new approach * refactor: rename waffle flag variable & update description --------- Co-authored-by: Andrii --- lms/djangoapps/branding/test_toggles.py | 30 +++++++++++++++++++++ lms/djangoapps/branding/toggles.py | 36 +++++++++++++++++++++++++ lms/envs/common.py | 9 +++++++ lms/envs/mock.yml | 1 + 4 files changed, 76 insertions(+) create mode 100644 lms/djangoapps/branding/test_toggles.py create mode 100644 lms/djangoapps/branding/toggles.py diff --git a/lms/djangoapps/branding/test_toggles.py b/lms/djangoapps/branding/test_toggles.py new file mode 100644 index 0000000000..f4e10a5695 --- /dev/null +++ b/lms/djangoapps/branding/test_toggles.py @@ -0,0 +1,30 @@ +""" +Tests for toggles, where there is logic beyond enable/disable. +""" + +from unittest.mock import patch +import ddt +from django.test import TestCase + +from lms.djangoapps.branding.toggles import use_new_catalog_page + + +@ddt.ddt +class TestBrandingToggles(TestCase): + """ + Tests for toggles, where there is logic beyond enable/disable. + """ + + @ddt.data(True, False) + @patch("lms.djangoapps.branding.toggles.ENABLE_NEW_CATALOG_PAGE") + def test_use_new_catalog_page_enabled( + self, is_waffle_enabled, mock_enable_new_catalog_page + ): + # Given legacy catalog feature is / not enabled + mock_enable_new_catalog_page.is_enabled.return_value = is_waffle_enabled + + # When I check if the feature is enabled + should_use_new_catalog_page = use_new_catalog_page() + + # Then I respects waffle setting. + self.assertEqual(should_use_new_catalog_page, is_waffle_enabled) diff --git a/lms/djangoapps/branding/toggles.py b/lms/djangoapps/branding/toggles.py new file mode 100644 index 0000000000..d183b852ae --- /dev/null +++ b/lms/djangoapps/branding/toggles.py @@ -0,0 +1,36 @@ +""" +Configuration for features of Branding +""" +from django.conf import settings +from edx_toggles.toggles import WaffleFlag + +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers + +# Namespace for Waffle flags related to branding +WAFFLE_FLAG_NAMESPACE = "new_catalog_mfe" + + +def catalog_mfe_enabled(): + """ + Determine if Catalog MFE is enabled, replacing student_dashboard + """ + return configuration_helpers.get_value( + 'ENABLE_CATALOG_MICROFRONTEND', settings.FEATURES.get('ENABLE_CATALOG_MICROFRONTEND') + ) + + +# .. toggle_name: new_catalog_mfe.use_new_catalog_page +# .. toggle_implementation: WaffleFlag +# .. toggle_default: False +# .. toggle_description: Set to True to enable the new catalog page. +# .. toggle_creation_date: 2025-05-15 +# .. toggle_target_removal_date: None +# .. toggle_use_cases: open_edx +ENABLE_NEW_CATALOG_PAGE = WaffleFlag(f'{WAFFLE_FLAG_NAMESPACE}.use_new_catalog_page', __name__) + + +def use_new_catalog_page(): + """ + Returns a boolean if new catalog page should be used. + """ + return ENABLE_NEW_CATALOG_PAGE.is_enabled() diff --git a/lms/envs/common.py b/lms/envs/common.py index 41ea8ffe72..e6c147fbae 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -881,6 +881,15 @@ FEATURES = { # toggle does not have a target removal date. 'ENABLE_AUTHN_MICROFRONTEND': os.environ.get("EDXAPP_ENABLE_AUTHN_MFE", False), + # .. toggle_name: FEATURES['ENABLE_CATALOG_MICROFRONTEND'] + # .. toggle_implementation: DjangoSetting + # .. toggle_default: False + # .. toggle_description: Supports staged rollout of a new micro-frontend-based implementation of the catalog. + # .. toggle_use_cases: temporary, open_edx + # .. toggle_creation_date: 2025-05-15 + # .. toggle_target_removal_date: None + 'ENABLE_CATALOG_MICROFRONTEND': os.environ.get("EDXAPP_ENABLE_CATALOG_MFE", False), + ### ORA Feature Flags ### # .. toggle_name: FEATURES['ENABLE_ORA_ALL_FILE_URLS'] # .. toggle_implementation: DjangoSetting diff --git a/lms/envs/mock.yml b/lms/envs/mock.yml index 386388a887..0bcdf0e84b 100644 --- a/lms/envs/mock.yml +++ b/lms/envs/mock.yml @@ -552,6 +552,7 @@ FEATURES: ENABLE_API_DOCS: true ENABLE_ASYNC_ANSWER_DISTRIBUTION: true ENABLE_AUTHN_MICROFRONTEND: true + ENABLE_CATALOG_MICROFRONTEND: true ENABLE_AUTO_GENERATED_USERNAME: true ENABLE_BULK_USER_RETIREMENT: true ENABLE_CERTIFICATES_IDV_REQUIREMENT: true