Skip to content

Commit a0ab489

Browse files
committed
fix: Handle a case that could cause infinite redirects.
If ENABLE_MKTG_SITE is True, MKTG_URLS['ROOT'] must be set. However if it is set to the same value as the LMS_ROOT_URL (which points to this view), you can end up in an infinite redirect loop. If the two URLs do match, don't redirect, just fall through to the content that this page would have responded with instead.
1 parent 82073d3 commit a0ab489

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

lms/djangoapps/branding/tests/test_views.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,20 @@ def test_index_does_not_redirect_without_site_override(self):
269269
response = self.client.get(reverse("root"))
270270
assert response.status_code == 200
271271

272+
@override_settings(ENABLE_MKTG_SITE=True)
273+
@override_settings(MKTG_URLS={'ROOT': 'https://foo.bar/'})
274+
@override_settings(LMS_ROOT_URL='https://foo.bar/')
275+
def test_index_wont_redirect_to_marketing_root_if_it_matches_lms_root(self):
276+
response = self.client.get(reverse("root"))
277+
assert response.status_code == 200
278+
279+
@override_settings(ENABLE_MKTG_SITE=True)
280+
@override_settings(MKTG_URLS={'ROOT': 'https://home.foo.bar/'})
281+
@override_settings(LMS_ROOT_URL='https://foo.bar/')
282+
def test_index_will_redirect_to_new_root_if_mktg_site_is_enabled(self):
283+
response = self.client.get(reverse("root"))
284+
assert response.status_code == 302
285+
272286
def test_index_redirects_to_marketing_site_with_site_override(self):
273287
""" Test index view redirects if MKTG_URLS['ROOT'] is set in SiteConfiguration """
274288
self.use_site(self.site_other)

lms/djangoapps/branding/views.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,25 @@ def index(request):
4242
# page to make it easier to browse for courses (and register)
4343
if configuration_helpers.get_value(
4444
'ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER',
45-
getattr(settings,'ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER', True)):
45+
getattr(settings, 'ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER', True)):
4646
return redirect('dashboard')
4747

4848
if use_catalog_mfe():
4949
return redirect(f'{settings.CATALOG_MICROFRONTEND_URL}/', permanent=True)
5050

5151
enable_mktg_site = configuration_helpers.get_value(
5252
'ENABLE_MKTG_SITE',
53-
getattr(settings,'ENABLE_MKTG_SITE', False)
53+
getattr(settings, 'ENABLE_MKTG_SITE', False)
5454
)
5555

5656
if enable_mktg_site:
5757
marketing_urls = configuration_helpers.get_value(
5858
'MKTG_URLS',
5959
settings.MKTG_URLS
6060
)
61-
return redirect(marketing_urls.get('ROOT'))
61+
root_url = marketing_urls.get("ROOT")
62+
if root_url != getattr(settings, "LMS_ROOT_URL", None):
63+
return redirect(root_url)
6264

6365
domain = request.headers.get('Host')
6466

0 commit comments

Comments
 (0)