diff --git a/src/course-home/data/__factories__/courseHomeMetadata.factory.js b/src/course-home/data/__factories__/courseHomeMetadata.factory.js index ffc06996..05007b79 100644 --- a/src/course-home/data/__factories__/courseHomeMetadata.factory.js +++ b/src/course-home/data/__factories__/courseHomeMetadata.factory.js @@ -9,7 +9,7 @@ Factory.define('courseHomeMetadata') title: 'Demonstration Course', is_self_paced: false, is_enrolled: false, - can_load_courseware: false, + can_load_courseware: true, celebrations: null, course_access: { additional_context_user_message: null, diff --git a/src/course-home/data/__snapshots__/redux.test.js.snap b/src/course-home/data/__snapshots__/redux.test.js.snap index e3173714..6ecca1d7 100644 --- a/src/course-home/data/__snapshots__/redux.test.js.snap +++ b/src/course-home/data/__snapshots__/redux.test.js.snap @@ -21,7 +21,7 @@ Object { "models": Object { "courseHomeMeta": Object { "course-v1:edX+DemoX+Demo_Course": Object { - "canLoadCourseware": false, + "canLoadCourseware": true, "celebrations": null, "courseAccess": Object { "additionalContextUserMessage": null, @@ -336,7 +336,7 @@ Object { "models": Object { "courseHomeMeta": Object { "course-v1:edX+DemoX+Demo_Course": Object { - "canLoadCourseware": false, + "canLoadCourseware": true, "celebrations": null, "courseAccess": Object { "additionalContextUserMessage": null, @@ -531,7 +531,7 @@ Object { "models": Object { "courseHomeMeta": Object { "course-v1:edX+DemoX+Demo_Course": Object { - "canLoadCourseware": false, + "canLoadCourseware": true, "celebrations": null, "courseAccess": Object { "additionalContextUserMessage": null, diff --git a/src/courseware/CoursewareContainer.test.jsx b/src/courseware/CoursewareContainer.test.jsx index 233fc5a9..3baa127f 100644 --- a/src/courseware/CoursewareContainer.test.jsx +++ b/src/courseware/CoursewareContainer.test.jsx @@ -471,13 +471,6 @@ describe('CoursewareContainer', () => { expect(global.location.href).toEqual(`http://localhost/redirect/survey/${courseMetadata.id}`); }); - it('should go to legacy courseware for a microfrontend_disabled error code', async () => { - const { courseMetadata, unitBlocks } = setUpWithDeniedStatus('microfrontend_disabled'); - await loadContainer(); - - expect(global.location.href).toEqual(`http://localhost/redirect/courseware/${courseMetadata.id}/unit/${unitBlocks[0].id}`); - }); - it('should go to course home for an authentication_required error code', async () => { const { courseMetadata } = setUpWithDeniedStatus('authentication_required'); await loadContainer(); @@ -507,4 +500,21 @@ describe('CoursewareContainer', () => { expect(global.location.href).toEqual(`http://localhost/redirect/dashboard?notlive=${startDate}`); }); }); + + describe('redirects when canLoadCourseware is false', () => { + it('should go to legacy courseware for disabled frontend', async () => { + const courseMetadata = Factory.build('courseMetadata'); + const courseHomeMetadata = Factory.build('courseHomeMetadata', { + can_load_courseware: false, + }); + const courseId = courseMetadata.id; + const { courseBlocks, sequenceBlocks, unitBlocks } = buildSimpleCourseBlocks(courseId, courseMetadata.name); + setUpMockRequests({ courseBlocks, courseMetadata, courseHomeMetadata }); + history.push(`/course/${courseId}/${sequenceBlocks[0].id}/${unitBlocks[0].id}`); + + await loadContainer(); + + expect(global.location.href).toEqual(`http://localhost/redirect/courseware/${courseMetadata.id}/unit/${unitBlocks[0].id}`); + }); + }); }); diff --git a/src/courseware/data/thunks.js b/src/courseware/data/thunks.js index c1ff21a3..af52f38f 100644 --- a/src/courseware/data/thunks.js +++ b/src/courseware/data/thunks.js @@ -93,7 +93,9 @@ export function fetchCourse(courseId) { logError(courseHomeMetadataResult.reason); } if (fetchedMetadata && fetchedCourseHomeMetadata) { - if (courseHomeMetadataResult.value.courseAccess.hasAccess && fetchedOutline) { + if (courseHomeMetadataResult.value.courseAccess.hasAccess + && courseHomeMetadataResult.value.canLoadCourseware + && fetchedOutline) { // User has access dispatch(fetchCourseSuccess({ courseId })); return; diff --git a/src/shared/access.js b/src/shared/access.js index 759475d0..3e98c2e1 100644 --- a/src/shared/access.js +++ b/src/shared/access.js @@ -4,7 +4,7 @@ import { getLocale } from '@edx/frontend-platform/i18n'; // This function inspects an access denied error and provides a redirect url (looks like a /redirect/... path), // which then renders a nice little message while the browser loads the next page. // This is basically a frontend version of check_course_access_with_redirect in the backend. -export function getAccessDeniedRedirectUrl(courseId, activeTabSlug, courseAccess, start, unitId) { +export function getAccessDeniedRedirectUrl(courseId, activeTabSlug, canLoadCourseware, courseAccess, start, unitId) { let url = null; switch (courseAccess.errorCode) { case 'audit_expired': @@ -21,19 +21,14 @@ export function getAccessDeniedRedirectUrl(courseId, activeTabSlug, courseAccess case 'unfulfilled_milestones': url = '/redirect/dashboard'; break; - case 'microfrontend_disabled': - // This code path is only used by the courseware right now. The course home tabs each have their own check for - // this in the tab-specific API calls. In those cases, the API will return an http status code if the MFE version - // of those tabs are disabled, rather than an access error like this. We could try to unify these approaches, but - // hopefully the legacy code isn't around long enough for that to be worth it. - if (unitId) { - url = `/redirect/courseware/${courseId}/unit/${unitId}`; - } - break; case 'authentication_required': case 'enrollment_required': default: - if (activeTabSlug !== 'outline') { + // if the learner has access to the course, but it is not enabled in the mfe, there is no + // error message, canLoadCourseware will be false. + if (activeTabSlug === 'courseware' && canLoadCourseware === false && unitId) { + url = `/redirect/courseware/${courseId}/unit/${unitId}`; + } else if (activeTabSlug !== 'outline') { url = `/redirect/course-home/${courseId}`; } } diff --git a/src/tab-page/TabPage.jsx b/src/tab-page/TabPage.jsx index 39e6c4ca..1fb59c1c 100644 --- a/src/tab-page/TabPage.jsx +++ b/src/tab-page/TabPage.jsx @@ -32,6 +32,7 @@ function TabPage({ intl, ...props }) { } = useSelector(state => state.courseHome); const dispatch = useDispatch(); const { + canLoadCourseware, courseAccess, number, org, @@ -52,7 +53,9 @@ function TabPage({ intl, ...props }) { } if (courseStatus === 'denied') { - const redirectUrl = getAccessDeniedRedirectUrl(courseId, activeTabSlug, courseAccess, start, unitId); + const redirectUrl = getAccessDeniedRedirectUrl( + courseId, activeTabSlug, canLoadCourseware, courseAccess, start, unitId, + ); if (redirectUrl) { return (); }