From f018cfe70e5066eac64bf76476ddf5b156667cf1 Mon Sep 17 00:00:00 2001 From: Serhii Nanai Date: Fri, 30 May 2025 17:34:49 +0300 Subject: [PATCH] feat: update course_about & catalog link generation --- cms/envs/test.py | 2 ++ common/djangoapps/util/course.py | 5 ++- common/djangoapps/util/tests/test_course.py | 39 +++++++++++++++++++++ lms/djangoapps/learner_home/test_views.py | 21 +++++++++++ lms/djangoapps/learner_home/views.py | 7 +++- lms/envs/common.py | 4 +++ lms/envs/test.py | 2 ++ 7 files changed, 78 insertions(+), 2 deletions(-) diff --git a/cms/envs/test.py b/cms/envs/test.py index 9a294bf10b..5b6b4facbe 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -373,3 +373,5 @@ SINGLE_LEARNER_COURSE_REGRADE_ROUTING_KEY = "edx.lms.core.default" SOFTWARE_SECURE_VERIFICATION_ROUTING_KEY = "edx.lms.core.default" STATIC_ROOT_BASE = "/edx/var/edxapp/staticfiles" STATIC_URL_BASE = "/static/" + +CATALOG_MICROFRONTEND_URL = "http://catalog-mfe" diff --git a/common/djangoapps/util/course.py b/common/djangoapps/util/course.py index fa82f9c4aa..ebc5b58785 100644 --- a/common/djangoapps/util/course.py +++ b/common/djangoapps/util/course.py @@ -9,6 +9,7 @@ from urllib.parse import urlencode from django.conf import settings from opaque_keys.edx.keys import CourseKey, UsageKey +from lms.djangoapps.branding.toggles import catalog_mfe_enabled, use_new_course_about_page from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx_filters.learning.filters import CourseAboutPageURLRequested @@ -50,7 +51,9 @@ def get_link_for_about_page(course): 'SOCIAL_SHARING_SETTINGS', getattr(settings, 'SOCIAL_SHARING_SETTINGS', {}) ).get('CUSTOM_COURSE_URLS') - if is_social_sharing_enabled and course.social_sharing_url: + if catalog_mfe_enabled() and use_new_course_about_page(course.id): + course_about_url = f'{settings.CATALOG_MICROFRONTEND_URL}/courses/{course.id}/about' + elif is_social_sharing_enabled and course.social_sharing_url: course_about_url = course.social_sharing_url elif settings.FEATURES.get('ENABLE_MKTG_SITE') and getattr(course, 'marketing_url', None): course_about_url = course.marketing_url diff --git a/common/djangoapps/util/tests/test_course.py b/common/djangoapps/util/tests/test_course.py index 1c476b9756..75c700bbc4 100644 --- a/common/djangoapps/util/tests/test_course.py +++ b/common/djangoapps/util/tests/test_course.py @@ -5,7 +5,10 @@ from unittest import mock import ddt from django.conf import settings +from django.test import override_settings +from edx_toggles.toggles.testutils import override_waffle_flag +from lms.djangoapps.branding.toggles import ENABLE_NEW_COURSE_ABOUT_PAGE from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from common.djangoapps.util.course import get_link_for_about_page from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order @@ -126,3 +129,39 @@ class TestCourseSharingLinks(ModuleStoreTestCase): use_overview=False, ) assert actual_course_sharing_link == expected_course_sharing_link + + @ddt.data( + ( + True, + True, + f'{settings.CATALOG_MICROFRONTEND_URL}/courses/course-v1:test_org+test_number+test_run/about' + ), + ( + True, + False, + f'{settings.LMS_ROOT_URL}/courses/course-v1:test_org+test_number+test_run/about' + ), + ( + False, + True, + f'{settings.LMS_ROOT_URL}/courses/course-v1:test_org+test_number+test_run/about' + ), + ( + False, + False, + f'{settings.LMS_ROOT_URL}/courses/course-v1:test_org+test_number+test_run/about' + ) + ) + @ddt.unpack + def test_sharing_link_with_new_course_about_page( + self, catalog_mfe_enabled, use_new_course_about_page, expected_course_sharing_link + ): + """ + Verify the method gives correct course sharing url when new course about page is used. + """ + with override_waffle_flag(ENABLE_NEW_COURSE_ABOUT_PAGE, active=use_new_course_about_page): + features = settings.FEATURES.copy() + features['ENABLE_CATALOG_MICROFRONTEND'] = catalog_mfe_enabled + with override_settings(FEATURES=features): + actual_course_sharing_link = get_link_for_about_page(self.course_overview) + assert actual_course_sharing_link == expected_course_sharing_link diff --git a/lms/djangoapps/learner_home/test_views.py b/lms/djangoapps/learner_home/test_views.py index 5b09893971..427bc97d7d 100644 --- a/lms/djangoapps/learner_home/test_views.py +++ b/lms/djangoapps/learner_home/test_views.py @@ -13,6 +13,7 @@ from django.conf import settings from django.urls import reverse from django.utils import timezone from django.test import TestCase, override_settings +from edx_toggles.toggles.testutils import override_waffle_flag from opaque_keys.edx.keys import CourseKey from rest_framework.test import APITestCase @@ -23,6 +24,7 @@ from common.djangoapps.student.tests.factories import ( UserFactory, ) from common.djangoapps.util.course import get_encoded_course_sharing_utm_params +from lms.djangoapps.branding.toggles import ENABLE_NEW_CATALOG_PAGE from lms.djangoapps.bulk_email.models import Optout from lms.djangoapps.learner_home.test_utils import ( create_test_enrollment, @@ -61,6 +63,7 @@ from xmodule.modulestore.tests.factories import CourseFactory ENTERPRISE_ENABLED = "ENABLE_ENTERPRISE_INTEGRATION" +@ddt.ddt class TestGetPlatformSettings(TestCase): """Tests for get_platform_settings""" @@ -88,6 +91,24 @@ class TestGetPlatformSettings(TestCase): }, ) + @ddt.data( + (True, True, f'{settings.CATALOG_MICROFRONTEND_URL}/courses'), + (True, False, '/courses'), + (False, True, '/courses'), + (False, False, '/courses') + ) + @ddt.unpack + def test_link_with_new_catalog_page(self, catalog_mfe_enabled, use_new_catalog_page, expected_catalog_link): + """ + Test that the catalog link is constructed correctly based on the MFE flags. + """ + with override_waffle_flag(ENABLE_NEW_CATALOG_PAGE, active=use_new_catalog_page): + features = settings.FEATURES.copy() + features['ENABLE_CATALOG_MICROFRONTEND'] = catalog_mfe_enabled + with override_settings(FEATURES=features): + actual_course_sharing_link = get_platform_settings()["courseSearchUrl"] + assert actual_course_sharing_link == expected_catalog_link + @ddt.ddt class TestGetUserAccountConfirmationInfo(SharedModuleStoreTestCase): diff --git a/lms/djangoapps/learner_home/views.py b/lms/djangoapps/learner_home/views.py index b97f9a20f4..cfa66854c3 100644 --- a/lms/djangoapps/learner_home/views.py +++ b/lms/djangoapps/learner_home/views.py @@ -41,6 +41,7 @@ from common.djangoapps.util.course import ( from common.djangoapps.util.milestones_helpers import ( get_pre_requisite_courses_not_completed, ) +from lms.djangoapps.branding import toggles from lms.djangoapps.bulk_email.models import Optout from lms.djangoapps.bulk_email.models_api import is_bulk_email_feature_enabled from lms.djangoapps.commerce.utils import EcommerceService @@ -71,10 +72,14 @@ logger = logging.getLogger(__name__) def get_platform_settings(): """Get settings used for platform level connections: emails, url routes, etc.""" + course_search_url = marketing_link("COURSES") + if toggles.catalog_mfe_enabled() and toggles.use_new_catalog_page(): + course_search_url = f"{settings.CATALOG_MICROFRONTEND_URL}/courses" + return { "supportEmail": settings.DEFAULT_FEEDBACK_EMAIL, "billingEmail": settings.PAYMENT_SUPPORT_EMAIL, - "courseSearchUrl": marketing_link("COURSES"), + "courseSearchUrl": course_search_url, } diff --git a/lms/envs/common.py b/lms/envs/common.py index 046b7cfef3..3dde7156b9 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -3217,6 +3217,10 @@ ORA_MICROFRONTEND_URL = None # .. setting_default: None # .. setting_description: Base URL of the exams dashboard micro-frontend for instructors. EXAMS_DASHBOARD_MICROFRONTEND_URL = None +# .. setting_name: CATALOG_MICROFRONTEND_URL +# .. setting_default: None +# .. setting_description: Base URL of the micro-frontend-based course catalog page. +CATALOG_MICROFRONTEND_URL = None # .. setting_name: DISCUSSION_SPAM_URLS # .. setting_default: [] diff --git a/lms/envs/test.py b/lms/envs/test.py index 958a54be01..367714e041 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -747,3 +747,5 @@ STATIC_ROOT_BASE = "/edx/var/edxapp/staticfiles" STATIC_URL_BASE = "/static/" ZENDESK_API_KEY = "" ZENDESK_USER = "" + +CATALOG_MICROFRONTEND_URL = "http://catalog-mfe"