Skip to content

Commit d34a6b9

Browse files
authored
Merge pull request #37342 from raccoongang/nanai/axm-2166/update-link-generation
feat [FC-86]: update course_about & catalog link generation
2 parents 3f44585 + cb4dcb0 commit d34a6b9

11 files changed

Lines changed: 77 additions & 22 deletions

File tree

cms/djangoapps/contentstore/tests/test_course_settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ def test_disable_advanced_settings_feature(self, disable_advanced_settings):
180180
"""
181181
advanced_settings_link_html = f"<a href=\"{self.course_setting_url}\">Advanced Settings</a>".encode('utf-8')
182182

183-
with override_settings(FEATURES={'DISABLE_ADVANCED_SETTINGS': disable_advanced_settings}):
183+
with override_settings(FEATURES={
184+
'DISABLE_ADVANCED_SETTINGS': disable_advanced_settings,
185+
}):
184186
for handler in (
185187
'import_handler',
186188
'export_handler',

cms/envs/test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,5 @@
373373
SOFTWARE_SECURE_VERIFICATION_ROUTING_KEY = "edx.lms.core.default"
374374
STATIC_ROOT_BASE = "/edx/var/edxapp/staticfiles"
375375
STATIC_URL_BASE = "/static/"
376+
377+
CATALOG_MICROFRONTEND_URL = "http://catalog-mfe"

common/djangoapps/util/course.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.conf import settings
1010
from opaque_keys.edx.keys import CourseKey, UsageKey
1111

12+
from lms.djangoapps.branding.toggles import use_catalog_mfe
1213
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
1314
from openedx_filters.learning.filters import CourseAboutPageURLRequested
1415

@@ -50,22 +51,25 @@ def get_link_for_about_page(course):
5051
'SOCIAL_SHARING_SETTINGS',
5152
getattr(settings, 'SOCIAL_SHARING_SETTINGS', {})
5253
).get('CUSTOM_COURSE_URLS')
54+
55+
if use_catalog_mfe():
56+
about_base_url = settings.CATALOG_MICROFRONTEND_URL
57+
else:
58+
about_base_url = configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL)
59+
5360
if is_social_sharing_enabled and course.social_sharing_url:
5461
course_about_url = course.social_sharing_url
5562
elif settings.FEATURES.get('ENABLE_MKTG_SITE') and getattr(course, 'marketing_url', None):
5663
course_about_url = course.marketing_url
5764
else:
58-
course_about_url = '{about_base_url}/courses/{course_key}/about'.format(
59-
about_base_url=configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL),
60-
course_key=str(course.id),
61-
)
62-
63-
## .. filter_implemented_name: CourseAboutPageURLRequested
64-
## .. filter_type: org.openedx.learning.course_about.page.url.requested.v1
65-
course_about_url, _ = CourseAboutPageURLRequested.run_filter(
66-
url=course_about_url,
67-
org=course.id.org,
68-
)
65+
course_about_url = f'{about_base_url}/courses/{course.id}/about'
66+
67+
## .. filter_implemented_name: CourseAboutPageURLRequested
68+
## .. filter_type: org.openedx.learning.course_about.page.url.requested.v1
69+
course_about_url, _ = CourseAboutPageURLRequested.run_filter(
70+
url=course_about_url,
71+
org=course.id.org,
72+
)
6973

7074
return course_about_url
7175

common/djangoapps/util/tests/test_course.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import ddt
77
from django.conf import settings
8+
from django.test import override_settings
89

910
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
1011
from common.djangoapps.util.course import get_link_for_about_page
@@ -51,17 +52,18 @@ def get_course_sharing_link(self, enable_social_sharing, enable_mktg_site, use_o
5152
"""
5253
mock_settings = {
5354
'FEATURES': {
54-
'ENABLE_MKTG_SITE': enable_mktg_site
55+
'ENABLE_MKTG_SITE': enable_mktg_site,
5556
},
5657
'SOCIAL_SHARING_SETTINGS': {
5758
'CUSTOM_COURSE_URLS': enable_social_sharing
58-
},
59+
}
5960
}
6061

61-
with mock.patch.multiple('django.conf.settings', **mock_settings):
62-
course_sharing_link = get_link_for_about_page(
63-
self.course_overview if use_overview else self.course
64-
)
62+
with override_settings(ENABLE_CATALOG_MICROFRONTEND=False):
63+
with mock.patch.multiple('django.conf.settings', **mock_settings):
64+
course_sharing_link = get_link_for_about_page(
65+
self.course_overview if use_overview else self.course
66+
)
6567

6668
return course_sharing_link
6769

@@ -126,3 +128,24 @@ def test_sharing_link_with_course_block(self, enable_social_sharing, expected_co
126128
use_overview=False,
127129
)
128130
assert actual_course_sharing_link == expected_course_sharing_link
131+
132+
@ddt.data(
133+
(
134+
True,
135+
f'{settings.CATALOG_MICROFRONTEND_URL}/courses/course-v1:test_org+test_number+test_run/about'
136+
),
137+
(
138+
False,
139+
f'{settings.LMS_ROOT_URL}/courses/course-v1:test_org+test_number+test_run/about'
140+
)
141+
)
142+
@ddt.unpack
143+
def test_sharing_link_with_new_course_about_page(
144+
self, catalog_mfe_enabled, expected_course_sharing_link
145+
):
146+
"""
147+
Verify the method gives correct course sharing url when new course about page is used.
148+
"""
149+
with override_settings(ENABLE_CATALOG_MICROFRONTEND=catalog_mfe_enabled):
150+
actual_course_sharing_link = get_link_for_about_page(self.course_overview)
151+
assert actual_course_sharing_link == expected_course_sharing_link

lms/djangoapps/branding/test_toggles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ def test_use_catalog_mfe(self, enabled):
1919
"""
2020
Test the use_catalog_mfe toggle.
2121
"""
22-
with override_settings(FEATURES={'ENABLE_CATALOG_MICROFRONTEND': enabled}):
22+
with override_settings(ENABLE_CATALOG_MICROFRONTEND=enabled):
2323
assert use_catalog_mfe() == enabled

lms/djangoapps/branding/toggles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
def use_catalog_mfe():
1010
"""
11-
Determine if Catalog MFE is enabled, replacing student_dashboard
11+
Returns a boolean = true if the Catalog MFE is enabled.
1212
"""
1313
return configuration_helpers.get_value(
14-
'ENABLE_CATALOG_MICROFRONTEND', settings.FEATURES['ENABLE_CATALOG_MICROFRONTEND']
14+
'ENABLE_CATALOG_MICROFRONTEND', getattr(settings, 'ENABLE_CATALOG_MICROFRONTEND', False)
1515
)

lms/djangoapps/learner_home/test_views.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
ENTERPRISE_ENABLED = "ENABLE_ENTERPRISE_INTEGRATION"
6262

6363

64+
@ddt.ddt
6465
class TestGetPlatformSettings(TestCase):
6566
"""Tests for get_platform_settings"""
6667

@@ -88,6 +89,18 @@ def test_happy_path(self, mock_marketing_link):
8889
},
8990
)
9091

92+
@ddt.data(
93+
(True, f'{settings.CATALOG_MICROFRONTEND_URL}/courses'),
94+
(False, '/courses'),
95+
)
96+
@ddt.unpack
97+
def test_link_with_new_catalog_page(self, catalog_mfe_enabled, expected_catalog_link):
98+
"""
99+
Test that the catalog link is constructed correctly based on the MFE flags.
100+
"""
101+
with override_settings(ENABLE_CATALOG_MICROFRONTEND=catalog_mfe_enabled):
102+
assert get_platform_settings()["courseSearchUrl"] == expected_catalog_link
103+
91104

92105
@ddt.ddt
93106
class TestGetUserAccountConfirmationInfo(SharedModuleStoreTestCase):

lms/djangoapps/learner_home/views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from common.djangoapps.util.milestones_helpers import (
4242
get_pre_requisite_courses_not_completed,
4343
)
44+
from lms.djangoapps.branding import toggles
4445
from lms.djangoapps.bulk_email.models import Optout
4546
from lms.djangoapps.bulk_email.models_api import is_bulk_email_feature_enabled
4647
from lms.djangoapps.commerce.utils import EcommerceService
@@ -71,10 +72,14 @@
7172
def get_platform_settings():
7273
"""Get settings used for platform level connections: emails, url routes, etc."""
7374

75+
course_search_url = marketing_link("COURSES")
76+
if toggles.use_catalog_mfe():
77+
course_search_url = f"{settings.CATALOG_MICROFRONTEND_URL}/courses"
78+
7479
return {
7580
"supportEmail": settings.DEFAULT_FEEDBACK_EMAIL,
7681
"billingEmail": settings.PAYMENT_SUPPORT_EMAIL,
77-
"courseSearchUrl": marketing_link("COURSES"),
82+
"courseSearchUrl": course_search_url,
7883
}
7984

8085

lms/envs/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,6 +3217,10 @@
32173217
# .. setting_default: None
32183218
# .. setting_description: Base URL of the exams dashboard micro-frontend for instructors.
32193219
EXAMS_DASHBOARD_MICROFRONTEND_URL = None
3220+
# .. setting_name: CATALOG_MICROFRONTEND_URL
3221+
# .. setting_default: None
3222+
# .. setting_description: Base URL of the micro-frontend-based course catalog page.
3223+
CATALOG_MICROFRONTEND_URL = None
32203224

32213225
# .. setting_name: DISCUSSION_SPAM_URLS
32223226
# .. setting_default: []

lms/envs/devstack.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
396396
AUTHN_MICROFRONTEND_URL = 'http://localhost:1999'
397397
AUTHN_MICROFRONTEND_DOMAIN = 'localhost:1999'
398398
EXAMS_DASHBOARD_MICROFRONTEND_URL = 'http://localhost:2020'
399+
CATALOG_MICROFRONTEND_URL = 'http://localhost:1998/catalog'
399400

400401
################### FRONTEND APPLICATION DISCUSSIONS ###################
401402
DISCUSSIONS_MICROFRONTEND_URL = 'http://localhost:2002'

0 commit comments

Comments
 (0)