diff --git a/package-lock.json b/package-lock.json index 93e1504f..f5b7742b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@edx/brand": "npm:@edx/brand-openedx@1.2.0", "@edx/frontend-component-footer": "11.6.3", "@edx/frontend-component-header": "3.6.4", - "@edx/frontend-lib-special-exams": "2.10.0", + "@edx/frontend-lib-special-exams": "2.12.0", "@edx/frontend-platform": "3.4.1", "@edx/paragon": "20.28.4", "@fortawesome/fontawesome-svg-core": "1.3.0", @@ -3272,9 +3272,9 @@ } }, "node_modules/@edx/frontend-lib-special-exams": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/@edx/frontend-lib-special-exams/-/frontend-lib-special-exams-2.10.0.tgz", - "integrity": "sha512-YHTYlmHIVM6KRTklbM3ERHmu1adRoMIpYTWwn/KhEQ/a6YQfRM8SJt8uawj4ceSRftJ7E9QWMGy/21KfnIYOxg==", + "version": "2.12.0", + "resolved": "https://registry.npmjs.org/@edx/frontend-lib-special-exams/-/frontend-lib-special-exams-2.12.0.tgz", + "integrity": "sha512-VltUW9bZ+Ha9Gw4xplEJjfZi4zjUJJWsAFOVeX8n+ZJLko4qDU46tL7EOLAJyMaiAtjvHent8MNIfcGBbqgcFQ==", "dependencies": { "@fortawesome/fontawesome-svg-core": "1.2.34", "@fortawesome/free-brands-svg-icons": "5.11.2", @@ -28482,9 +28482,9 @@ } }, "@edx/frontend-lib-special-exams": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/@edx/frontend-lib-special-exams/-/frontend-lib-special-exams-2.10.0.tgz", - "integrity": "sha512-YHTYlmHIVM6KRTklbM3ERHmu1adRoMIpYTWwn/KhEQ/a6YQfRM8SJt8uawj4ceSRftJ7E9QWMGy/21KfnIYOxg==", + "version": "2.12.0", + "resolved": "https://registry.npmjs.org/@edx/frontend-lib-special-exams/-/frontend-lib-special-exams-2.12.0.tgz", + "integrity": "sha512-VltUW9bZ+Ha9Gw4xplEJjfZi4zjUJJWsAFOVeX8n+ZJLko4qDU46tL7EOLAJyMaiAtjvHent8MNIfcGBbqgcFQ==", "requires": { "@fortawesome/fontawesome-svg-core": "1.2.34", "@fortawesome/free-brands-svg-icons": "5.11.2", diff --git a/package.json b/package.json index d5d340e5..22809492 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "@edx/brand": "npm:@edx/brand-openedx@1.2.0", "@edx/frontend-component-footer": "11.6.3", "@edx/frontend-component-header": "3.6.4", - "@edx/frontend-lib-special-exams": "2.10.0", + "@edx/frontend-lib-special-exams": "2.12.0", "@edx/frontend-platform": "3.4.1", "@edx/paragon": "20.28.4", "@fortawesome/fontawesome-svg-core": "1.3.0", diff --git a/src/courseware/course/sequence/Unit.jsx b/src/courseware/course/sequence/Unit.jsx index 274bc681..57ca1899 100644 --- a/src/courseware/course/sequence/Unit.jsx +++ b/src/courseware/course/sequence/Unit.jsx @@ -1,6 +1,8 @@ import { getConfig } from '@edx/frontend-platform'; import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; +import { logError } from '@edx/frontend-platform/logging'; import { AppContext, ErrorPage } from '@edx/frontend-platform/react'; +import { getExamAccess, fetchExamAccess, isExam } from '@edx/frontend-lib-special-exams'; import { Modal } from '@edx/paragon'; import PropTypes from 'prop-types'; import React, { @@ -65,6 +67,16 @@ function useLoadBearingHook(id) { }, [id]); } +function addExamAccessToIframeUrl(accessToken, iframeUrl) { + let url = iframeUrl; + if (isExam()) { + if (accessToken) { + url += `&exam_access=${accessToken}`; + } + } + return url; +} + export function sendUrlHashToFrame(frame) { const { hash } = window.location; if (hash) { @@ -83,6 +95,7 @@ const Unit = ({ }) => { const { authenticatedUser } = useContext(AppContext); const view = authenticatedUser ? 'student_view' : 'public_view'; + let iframeUrl = `${getConfig().LMS_BASE_URL}/xblock/${id}?show_title=0&show_bookmark_button=0&recheck_access=1&view=${view}`; if (format) { iframeUrl += `&format=${format}`; @@ -93,6 +106,8 @@ const Unit = ({ const [showError, setShowError] = useState(false); const [modalOptions, setModalOptions] = useState({ open: false }); const [shouldDisplayHonorCode, setShouldDisplayHonorCode] = useState(false); + const [examAccessToken, setExamAccessToken] = useState(''); + const [blockExamAccess, setBlockExamAccess] = useState(isExam()); const unit = useModel('units', id); const course = useModel('coursewareMeta', courseId); @@ -140,6 +155,16 @@ const Unit = ({ sendUrlHashToFrame(document.getElementById('unit-iframe')); }, [id, setIframeHeight, hasLoaded, iframeHeight, setHasLoaded, onLoaded]); + useEffect(() => { + if (isExam()) { + fetchExamAccess().finally(() => { + const examAccess = getExamAccess(); + setExamAccessToken(examAccess); + setBlockExamAccess(false); + }).catch((error) => logError(error)); + } + }, [id]); + return (

{unit.title}

@@ -175,7 +200,7 @@ const Unit = ({ )} - {!shouldDisplayHonorCode && !hasLoaded && !showError && ( + {(!shouldDisplayHonorCode || blockExamAccess) && !hasLoaded && !showError && ( @@ -208,12 +233,12 @@ const Unit = ({ dialogClassName="modal-lti" /> )} - {!shouldDisplayHonorCode && ( + {!shouldDisplayHonorCode && !blockExamAccess && (