From 24398fd90b531ab61f8151c144a5688e21500eb3 Mon Sep 17 00:00:00 2001 From: Ashar Fuadi Date: Mon, 8 Jul 2024 08:48:49 +0700 Subject: [PATCH] Disallow viewing other solution if we haven't solved a problem in course (#639) --- .../Programming/SubmissionDetails.jsx | 11 ++++++++++- .../ChapterProblemSubmissionPage.jsx | 5 +---- .../ChapterProblemSubmissionPage.test.jsx | 11 ----------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/judgels-client/src/components/SubmissionDetails/Programming/SubmissionDetails.jsx b/judgels-client/src/components/SubmissionDetails/Programming/SubmissionDetails.jsx index 898e63e33..f07020aa0 100644 --- a/judgels-client/src/components/SubmissionDetails/Programming/SubmissionDetails.jsx +++ b/judgels-client/src/components/SubmissionDetails/Programming/SubmissionDetails.jsx @@ -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'; @@ -30,6 +30,7 @@ export function SubmissionDetails({ problemUrl, containerName, onDownload, + hideSource, hideSourceFilename, showLoaderWhenPending, }) { @@ -301,6 +302,14 @@ export function SubmissionDetails({ } if (!source) { + if (hideSource) { + return ( + +  You cannot view other's solution before solving this problem in this course. + + ); + } + return ( <> {renderSourceFilesHeading()} diff --git a/judgels-client/src/routes/courses/courses/single/chapters/single/problems/single/Programming/submissions/single/ChapterProblemSubmissionPage/ChapterProblemSubmissionPage.jsx b/judgels-client/src/routes/courses/courses/single/chapters/single/problems/single/Programming/submissions/single/ChapterProblemSubmissionPage/ChapterProblemSubmissionPage.jsx index 06090a94a..c95a636ba 100644 --- a/judgels-client/src/routes/courses/courses/single/chapters/single/problems/single/Programming/submissions/single/ChapterProblemSubmissionPage/ChapterProblemSubmissionPage.jsx +++ b/judgels-client/src/routes/courses/courses/single/chapters/single/problems/single/Programming/submissions/single/ChapterProblemSubmissionPage/ChapterProblemSubmissionPage.jsx @@ -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, @@ -83,9 +81,9 @@ export class ChapterProblemSubmissionPage extends Component { @@ -101,7 +99,6 @@ const mapStateToProps = state => ({ const mapDispatchToProps = { onGetSubmissionWithSource: chapterProblemSubmissionActions.getSubmissionWithSource, - onGetSubmissionSourceImage: chapterProblemSubmissionActions.getSubmissionSourceImage, onPushBreadcrumb: breadcrumbsActions.pushBreadcrumb, onPopBreadcrumb: breadcrumbsActions.popBreadcrumb, }; diff --git a/judgels-client/src/routes/courses/courses/single/chapters/single/problems/single/Programming/submissions/single/ChapterProblemSubmissionPage/ChapterProblemSubmissionPage.test.jsx b/judgels-client/src/routes/courses/courses/single/chapters/single/problems/single/Programming/submissions/single/ChapterProblemSubmissionPage/ChapterProblemSubmissionPage.test.jsx index 2339a2d85..7463a1918 100644 --- a/judgels-client/src/routes/courses/courses/single/chapters/single/problems/single/Programming/submissions/single/ChapterProblemSubmissionPage/ChapterProblemSubmissionPage.test.jsx +++ b/judgels-client/src/routes/courses/courses/single/chapters/single/problems/single/Programming/submissions/single/ChapterProblemSubmissionPage/ChapterProblemSubmissionPage.test.jsx @@ -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'); - }); - }); });