feat: update course_about & catalog link generation

This commit is contained in:
Serhii Nanai
2025-05-30 17:34:49 +03:00
parent ed6aea3aa7
commit f018cfe70e
7 changed files with 78 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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,
}

View File

@@ -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: []

View File

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