Files
frontend-app-learning/src/courseware/course/sequence/honor-code/HonorCode.jsx
Simon Chen 436c05487a fix: Only dismiss the modal when masquerading as specific learner (#759)
if the user is masquerading as a specific learner, then dismiss the modal and do not post back and save the Honor Code signature

Co-authored-by: Simon Chen <schen@edX-C02FW0GUML85.local>
2021-12-02 10:08:49 -05:00

70 lines
2.5 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { useDispatch } from 'react-redux';
import { getConfig, history } from '@edx/frontend-platform';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { ActionRow, Alert, Button } from '@edx/paragon';
import { useModel } from '../../../../generic/model-store';
import { saveIntegritySignature } from '../../../data';
import messages from './messages';
function HonorCode({ intl, courseId }) {
const dispatch = useDispatch();
const coursewareMetaData = useModel('coursewareMeta', courseId);
const authUser = getAuthenticatedUser();
const siteName = getConfig().SITE_NAME;
const honorCodeUrl = `${getConfig().TERMS_OF_SERVICE_URL}#honor-code`;
const handleCancel = () => history.push(`/course/${courseId}/home`);
const handleAgree = () => dispatch(
// If the request is made by a staff user masquerading as a specific learner,
// don't actually create a signature for them on the backend.
// Only the modal dialog will be dismissed.
// Otherwise, even for staff users, we want to record the signature.
saveIntegritySignature(
courseId,
coursewareMetaData.isMasquerading && coursewareMetaData.username !== authUser.username,
),
);
return (
<Alert variant="light" aria-live="off">
<h4 aria-level="3">
{siteName}{' '}
{intl.formatMessage(messages['learn.honorCode.name'])}
</h4>
<p>
<FormattedMessage
id="learn.honorCode.content"
defaultMessage="Honesty and academic integrity are important to {siteName} and the institutions providing courses and programs on the {siteName} site. By clicking “I agree” below, I confirm that I have read, understand, and will abide by the {link} for the {siteName} Site."
values={{
siteName,
link: <a href={honorCodeUrl}>{intl.formatMessage(messages['learn.honorCode.name'])}</a>,
}}
/>
</p>
<ActionRow>
<ActionRow.Spacer />
<Button variant="tertiary" onClick={handleCancel}>
{intl.formatMessage(messages['learn.honorCode.cancel'])}
</Button>
<Button variant="primary" onClick={handleAgree}>
{intl.formatMessage(messages['learn.honorCode.agree'])}
</Button>
</ActionRow>
</Alert>
);
}
HonorCode.propTypes = {
intl: intlShape.isRequired,
courseId: PropTypes.string.isRequired,
};
export default injectIntl(HonorCode);