If the user does not have access to the course, then redirect to the course outline. (#13)

* If the user does not have access to the course, then redirect to the course outline.

In a subsequent PR, if this API call is made on the course outline page in the MFE, we’ll need to be able to prevent the redirect.  But that view of the MFE doesn’t exist yet.

* Moving course outline redirect logic into CourseContainer.

This way, depending on the page calling fetchCourseMetadata, we can make an intelligent choice about whether we want to redirect, show a message, etc.  By redirecting in the API call handler, then we took that choice away from ourselves.
This commit is contained in:
David Joy
2020-02-28 12:25:03 -05:00
committed by GitHub
parent ba6764de43
commit 2f90b78814

View File

@@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { history } from '@edx/frontend-platform';
import { history, getConfig } from '@edx/frontend-platform';
import { fetchCourseMetadata } from '../data/course-meta/thunks';
import { fetchCourseBlocks } from '../data/course-blocks/thunks';
@@ -41,6 +41,12 @@ function CourseContainer(props) {
}
}, [courseUsageKey, courseId, sequenceId]);
useEffect(() => {
if (metadataLoaded && !metadata.userHasAccess) {
global.location.assign(`${getConfig().LMS_BASE_URL}/courses/${courseUsageKey}/course/`);
}
}, [metadataLoaded]);
if (!courseId || !sequenceId) {
return (
<PageLoading
@@ -75,6 +81,7 @@ CourseContainer.propTypes = {
org: PropTypes.string,
number: PropTypes.string,
name: PropTypes.string,
userHasAccess: PropTypes.bool,
tabs: PropTypes.arrayOf(PropTypes.shape({
priority: PropTypes.number,
slug: PropTypes.string,