From 758a203376a5b50ed617b77811f212bf2b7ff157 Mon Sep 17 00:00:00 2001 From: Ivan Danilov Date: Wed, 16 Oct 2024 14:27:04 +0300 Subject: [PATCH] fix: Do not apply cross-check score more than max score of a task (#2540) * chore: Do not apply cross-check score more than max score of a task * Excplicit error message for score exceeding max score * Add check from front-end side for score exceeding max score * Update client/src/pages/course/student/cross-check-review.tsx Co-authored-by: Valery <57412523+valerydluski@users.noreply.github.com> * Update client/src/pages/course/student/cross-check-review.tsx Co-authored-by: Valery <57412523+valerydluski@users.noreply.github.com> --------- Co-authored-by: Valery <57412523+valerydluski@users.noreply.github.com> --- client/src/pages/course/student/cross-check-review.tsx | 4 ++++ server/src/routes/course/crossCheck/createResult.ts | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/client/src/pages/course/student/cross-check-review.tsx b/client/src/pages/course/student/cross-check-review.tsx index 4aa5c04800..f23acb337c 100644 --- a/client/src/pages/course/student/cross-check-review.tsx +++ b/client/src/pages/course/student/cross-check-review.tsx @@ -140,6 +140,10 @@ function Page() { const submitReview = withLoading(async values => { try { + if (values.maxScore != null && values.maxScore < score) { + message.error(`The score (${score}) exceeds the maximum score (${values.maxScore}) for the task.`); + return; + } await courseService.postTaskSolutionResult(values.githubId, values.courseTaskId, { score, comment: markdownLabel + values.comment, diff --git a/server/src/routes/course/crossCheck/createResult.ts b/server/src/routes/course/crossCheck/createResult.ts index 46d3178ce4..4196fca377 100644 --- a/server/src/routes/course/crossCheck/createResult.ts +++ b/server/src/routes/course/crossCheck/createResult.ts @@ -62,6 +62,11 @@ export const createResult = (_: ILogger) => async (ctx: Router.RouterContext) => review: Array.isArray(inputData.review) ? inputData.review : [], }; + if (data.score > courseTask.maxScore) { + setErrorResponse(ctx, BAD_REQUEST, 'score provided is greater than max score for the task'); + return; + } + if (isNaN(data.score) || data.score < 0) { setErrorResponse(ctx, BAD_REQUEST, 'no score provided'); return;