Skip to content

Commit

Permalink
Disallow viewing other solution if we haven't solved a problem in cou…
Browse files Browse the repository at this point in the history
…rse (#639)
  • Loading branch information
fushar authored Jul 8, 2024
1 parent e2fc3a0 commit 24398fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, HTMLTable, ProgressBar } from '@blueprintjs/core';
import { Download } from '@blueprintjs/icons';
import { Download, Lock } from '@blueprintjs/icons';
import { Link } from 'react-router-dom';

import { isInteractive, isOutputOnly } from '../../../modules/api/gabriel/engine';
Expand Down Expand Up @@ -30,6 +30,7 @@ export function SubmissionDetails({
problemUrl,
containerName,
onDownload,
hideSource,
hideSourceFilename,
showLoaderWhenPending,
}) {
Expand Down Expand Up @@ -301,6 +302,14 @@ export function SubmissionDetails({
}

if (!source) {
if (hideSource) {
return (
<ContentCard>
<Lock /> &nbsp;<small>You cannot view other's solution before solving this problem in this course.</small>
</ContentCard>
);
}

return (
<>
{renderSourceFilesHeading()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ export class ChapterProblemSubmissionPage extends Component {
+this.props.match.params.submissionId,
this.props.statementLanguage
);
const sourceImageUrl = data.source ? undefined : await this.props.onGetSubmissionSourceImage(data.submission.jid);
this.props.onPushBreadcrumb(this.props.match.url, '#' + data.submission.id);
this.setState({
submissionWithSource: data,
sourceImageUrl,
profile,
problemName,
containerName,
Expand All @@ -83,9 +81,9 @@ export class ChapterProblemSubmissionPage extends Component {
<SubmissionDetails
submission={submissionWithSource.submission}
source={submissionWithSource.source}
sourceImageUrl={sourceImageUrl}
profile={profile}
problemUrl={`/courses/${course.slug}/chapters/${chapter.alias}/problems/${problemAlias}`}
hideSource={!!!submissionWithSource.source}
hideSourceFilename
showLoaderWhenPending
/>
Expand All @@ -101,7 +99,6 @@ const mapStateToProps = state => ({

const mapDispatchToProps = {
onGetSubmissionWithSource: chapterProblemSubmissionActions.getSubmissionWithSource,
onGetSubmissionSourceImage: chapterProblemSubmissionActions.getSubmissionSourceImage,
onPushBreadcrumb: breadcrumbsActions.pushBreadcrumb,
onPopBreadcrumb: breadcrumbsActions.popBreadcrumb,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,4 @@ describe('ChapterProblemSubmissionPage', () => {
test('page', () => {
expect(wrapper.text()).toContain('Submission #10');
});

describe('when there is no source', () => {
beforeEach(async () => {
source = null;
await render();
});

test('get source image url', () => {
expect(chapterProblemSubmissionActions.getSubmissionSourceImage).toHaveBeenCalledWith('submissionJid');
});
});
});

0 comments on commit 24398fd

Please sign in to comment.