Merge pull request #29526 from edx/mikix/preserve-params-on-redirect

fix: when redirecting to the MFE, preserve query flags
This commit is contained in:
Dillon Dumesnil
2021-12-08 05:46:17 -08:00
committed by GitHub
7 changed files with 53 additions and 11 deletions

View File

@@ -18,6 +18,7 @@ from crum import set_current_request
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.http import Http404, HttpResponseBadRequest
from django.http.request import QueryDict
from django.test import RequestFactory, TestCase
from django.test.client import Client
from django.test.utils import override_settings
@@ -498,9 +499,9 @@ class BaseViewsTestCase(ModuleStoreTestCase): # lint-amnesty, pylint: disable=m
'course_id': str(self.course_key),
'chapter': str(self.chapter.location.block_id),
'section': str(self.section2.location.block_id),
}
)
mfe_url = '{}/course/{}/{}'.format(
},
) + '?foo=b$r'
mfe_url = '{}/course/{}/{}?foo=b%24r'.format(
settings.LEARNING_MICROFRONTEND_URL,
self.course_key,
self.section2.location
@@ -3395,10 +3396,12 @@ class AccessUtilsTestCase(ModuleStoreTestCase):
@ddt.ddt
@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=True)
class DatesTabTestCase(ModuleStoreTestCase):
"""
Ensure that the dates page renders with the correct data for both a verified and audit learner
"""
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
def setUp(self):
super().setUp()
@@ -3533,6 +3536,15 @@ class DatesTabTestCase(ModuleStoreTestCase):
response = self._get_response(self.course)
self.assertContains(response, 'div class="banner-cta-text"')
@override_waffle_flag(COURSE_HOME_USE_LEGACY_FRONTEND, active=False)
def test_legacy_redirect(self):
"""
Verify that the legacy dates page redirects to the MFE correctly.
"""
response = self.client.get(reverse('dates', args=[str(self.course.id)]) + '?foo=b$r')
assert response.status_code == 302
assert response.get('Location') == f'http://learning-mfe/course/{self.course.id}/dates?foo=b%24r'
class TestShowCoursewareMFE(TestCase):
"""
@@ -3628,6 +3640,11 @@ class TestShowCoursewareMFE(TestCase):
'https://learningmfe.openedx.org'
'/course/course-v1:OpenEdX+MFE+2020'
)
assert make_learning_mfe_courseware_url(course_key, params=QueryDict('foo=b$r')) == (
'https://learningmfe.openedx.org'
'/course/course-v1:OpenEdX+MFE+2020'
'?foo=b%24r'
)
assert make_learning_mfe_courseware_url(course_key, section_key, '') == (
'https://learningmfe.openedx.org'
'/course/course-v1:OpenEdX+MFE+2020'

View File

@@ -207,7 +207,8 @@ class CoursewareIndex(View):
url = make_learning_mfe_courseware_url(
self.course_key,
self.section.location if self.section else None,
unit_key
unit_key,
params=self.request.GET,
)
return url

View File

@@ -1060,8 +1060,9 @@ def dates(request, course_id):
course_key = CourseKey.from_string(course_id)
if not (course_home_legacy_is_active(course_key) or request.user.is_staff):
microfrontend_url = get_learning_mfe_home_url(course_key=course_key, view_name=COURSE_DATES_NAME)
raise Redirect(microfrontend_url)
raise Redirect(get_learning_mfe_home_url(
course_key=course_key, view_name=COURSE_DATES_NAME, params=request.GET,
))
# Enable NR tracing for this view based on course
monitoring_utils.set_custom_attribute('course_id', str(course_key))
@@ -1137,8 +1138,9 @@ def progress(request, course_id, student_id=None):
course_key = CourseKey.from_string(course_id)
if course_home_mfe_progress_tab_is_active(course_key) and not request.user.is_staff:
microfrontend_url = get_learning_mfe_home_url(course_key=course_key, view_name=COURSE_PROGRESS_NAME)
raise Redirect(microfrontend_url)
raise Redirect(get_learning_mfe_home_url(
course_key=course_key, view_name=COURSE_PROGRESS_NAME, params=request.GET,
))
with modulestore().bulk_operations(course_key):
return _progress(request, course_key, student_id)