From 88c71e735d5765e62a5d6ed06e7a4b15829f37e7 Mon Sep 17 00:00:00 2001 From: Aaron Shafovaloff Date: Tue, 24 Sep 2024 14:27:06 -0600 Subject: [PATCH] add mutations to SG2; remove over-fetching fragment Change-Id: I9af6c8accefa8805bd592896f9c81c1b3c021709 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/358355 Reviewed-by: Spencer Olson QA-Review: Aaron Shafovaloff Product-Review: Aaron Shafovaloff Tested-by: Service Cloud Jenkins --- .../mutations/deleteAttachmentMutation.ts | 33 ++++++++++ .../mutations/reassignAssignmentMutation.ts | 35 ++++++++++ .../mutations/saveRubricAssessmentMutation.ts | 64 +++++++++++++++++++ .../updateSubmissionGradeStatusMutation.ts | 8 +-- 4 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 ui/features/speed_grader/mutations/deleteAttachmentMutation.ts create mode 100644 ui/features/speed_grader/mutations/reassignAssignmentMutation.ts create mode 100644 ui/features/speed_grader/mutations/saveRubricAssessmentMutation.ts diff --git a/ui/features/speed_grader/mutations/deleteAttachmentMutation.ts b/ui/features/speed_grader/mutations/deleteAttachmentMutation.ts new file mode 100644 index 00000000000..c9e1fbf461f --- /dev/null +++ b/ui/features/speed_grader/mutations/deleteAttachmentMutation.ts @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 - present Instructure, Inc. + * + * This file is part of Canvas. + * + * Canvas is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License as published by the Free + * Software Foundation, version 3 of the License. + * + * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more + * details. + * + * You should have received a copy of the GNU Affero General Public License along + * with this program. If not, see . + */ +import {z} from 'zod' +import doFetchApi from '@canvas/do-fetch-api-effect' + +export const ZParams = z.object({ + attachmentId: z.string(), +}) + +type Params = z.infer + +export function deleteAttachment(params: Params): Promise { + ZParams.parse(params) + return doFetchApi({ + path: `/api/v1/files/${params.attachmentId}?replace=1`, + method: 'DELETE', + }) +} diff --git a/ui/features/speed_grader/mutations/reassignAssignmentMutation.ts b/ui/features/speed_grader/mutations/reassignAssignmentMutation.ts new file mode 100644 index 00000000000..17f2eff9a8f --- /dev/null +++ b/ui/features/speed_grader/mutations/reassignAssignmentMutation.ts @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024 - present Instructure, Inc. + * + * This file is part of Canvas. + * + * Canvas is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License as published by the Free + * Software Foundation, version 3 of the License. + * + * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more + * details. + * + * You should have received a copy of the GNU Affero General Public License along + * with this program. If not, see . + */ + +import {z} from 'zod' +import doFetchApi from '@canvas/do-fetch-api-effect' + +export const ZParams = z.object({ + courseId: z.string(), + assignmentId: z.string(), + userId: z.string(), +}) +type Params = z.infer + +export function reassignAssignmentMutation(params: Params): Promise { + ZParams.parse(params) + return doFetchApi({ + path: `/courses/${params.courseId}/assignments/${params.assignmentId}/submissions/${params.userId}/reassign`, + method: 'PUT', + }) +} diff --git a/ui/features/speed_grader/mutations/saveRubricAssessmentMutation.ts b/ui/features/speed_grader/mutations/saveRubricAssessmentMutation.ts new file mode 100644 index 00000000000..735844f55d5 --- /dev/null +++ b/ui/features/speed_grader/mutations/saveRubricAssessmentMutation.ts @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2024 - present Instructure, Inc. + * + * This file is part of Canvas. + * + * Canvas is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License as published by the Free + * Software Foundation, version 3 of the License. + * + * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more + * details. + * + * You should have received a copy of the GNU Affero General Public License along + * with this program. If not, see . + */ + +import doFetchApi from '@canvas/do-fetch-api-effect' +import {RubricAssessmentData} from '@canvas/rubrics/react/types/rubric' + +export default function saveRubricAssessementMutation( + assessments: RubricAssessmentData[], + userId: string +) { + // @ts-expect-error + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const {assessment_user_id, anonymous_id, assessment_type} = ENV.RUBRIC_ASSESSMENT ?? {} + + // TODO: anonymous grading stuff here, see convertSubmittedAssessmentin RubricAssessmentContainerWrapper + // if (assessment_user_id) { + // data['rubric_assessment[user_id]'] = assessment_user_id + // } else { + // data['rubric_assessment[anonymous_id]'] = anonymous_id + // } + const rubric_assessment: Record = {} + rubric_assessment.user_id = userId + rubric_assessment.assessment_type = assessment_type + + assessments.forEach(assessment => { + const pre = `criterion_${assessment.criterionId}` + rubric_assessment[pre] = {} + rubric_assessment[pre].points = assessment.points + rubric_assessment[pre].comments = assessment.comments + rubric_assessment[pre].save_comment = assessment.saveCommentsForLater ? '1' : '0' + rubric_assessment[pre].description = assessment.description + if (assessment.id) { + rubric_assessment[pre].rating_id = assessment.id + } + }) + const data: any = {rubric_assessment} + // TODO: moderated grading support here, see saveRubricAssessment in speed_grader.tsx + // TODO: anonymous grading support, see saveRubricAssessment in speed_grader.tsx + + data.graded_anonymously = false + // @ts-expect-error + const url = window.ENV.update_rubric_assessment_url! + const method = 'POST' + return doFetchApi({ + path: url, + method, + body: data, + }) +} diff --git a/ui/features/speed_grader/mutations/updateSubmissionGradeStatusMutation.ts b/ui/features/speed_grader/mutations/updateSubmissionGradeStatusMutation.ts index a1504c28b50..254a230a453 100644 --- a/ui/features/speed_grader/mutations/updateSubmissionGradeStatusMutation.ts +++ b/ui/features/speed_grader/mutations/updateSubmissionGradeStatusMutation.ts @@ -19,7 +19,6 @@ import {z} from 'zod' import {executeQuery} from '@canvas/query/graphql' import gql from 'graphql-tag' -import {SUBMISSION_FRAGMENT} from '../queries/submissionQuery' export const UPDATE_SUBMISSION_GRADE_STATUS = gql` mutation updateSubmissionGradeStatus( @@ -35,13 +34,8 @@ export const UPDATE_SUBMISSION_GRADE_STATUS = gql` latePolicyStatus: $latePolicyStatus customGradeStatusId: $customGradeStatusId } - ) { - submission { - ...SubmissionInterfaceFragment - } - } + ) } - ${SUBMISSION_FRAGMENT} ` export const ZUpdateSubmissionGradeStatusParams = z.object({