Search in sources :

Example 1 with PlagiarismStatus

use of de.tum.in.www1.artemis.domain.plagiarism.PlagiarismStatus in project Artemis by ls1intum.

the class PlagiarismResource method updatePlagiarismComparisonFinalStatus.

/**
 * Updates the final status of a plagiarism comparison concerning one of both students.
 * This process will send a notification to the respective student.
 * I.e. an instructor sends his final verdict/decision
 *
 * @param courseId the id of the course
 * @param comparisonId of the comparison
 * @param studentLogin of the student
 * @param statusDTO is the final status of this plagiarism comparison concerning one of both students
 * @return the final (updated) status of this plagiarism comparison concerning one of both students
 */
@PutMapping("courses/{courseId}/plagiarism-comparisons/{comparisonId}/final-status/{studentLogin}")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<PlagiarismComparisonStatusDTO> updatePlagiarismComparisonFinalStatus(@PathVariable("courseId") long courseId, @PathVariable("comparisonId") long comparisonId, @PathVariable("studentLogin") String studentLogin, @RequestBody PlagiarismComparisonStatusDTO statusDTO) {
    var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(comparisonId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    User affectedUser = userRepository.getUserWithGroupsAndAuthorities(studentLogin);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    PlagiarismStatus finalStatus = statusDTO.getStatus();
    if (!authenticationCheckService.isAtLeastInstructorInCourse(course, user)) {
        throw new AccessForbiddenException("Only instructors responsible for this course can access this plagiarism comparison.");
    }
    if (!Objects.equals(comparison.getPlagiarismResult().getExercise().getCourseViaExerciseGroupOrCourseMember().getId(), courseId)) {
        throw new BadRequestAlertException("The courseId does not belong to the given comparisonId", "PlagiarismComparison", "idMismatch");
    }
    if (comparison.getSubmissionA().getStudentLogin().equals(studentLogin)) {
        plagiarismComparisonRepository.updatePlagiarismComparisonFinalStatusA(comparisonId, finalStatus);
        // needed for notifications
        comparison.setStatusA(finalStatus);
    } else if (comparison.getSubmissionB().getStudentLogin().equals(studentLogin)) {
        plagiarismComparisonRepository.updatePlagiarismComparisonFinalStatusB(comparisonId, finalStatus);
        // needed for notifications
        comparison.setStatusB(finalStatus);
    } else {
        return ResponseEntity.notFound().build();
    }
    singleUserNotificationService.notifyUserAboutFinalPlagiarismState(comparison, affectedUser);
    return ResponseEntity.ok(statusDTO);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) User(de.tum.in.www1.artemis.domain.User) Course(de.tum.in.www1.artemis.domain.Course) PlagiarismStatus(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismStatus) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with PlagiarismStatus

use of de.tum.in.www1.artemis.domain.plagiarism.PlagiarismStatus in project ArTEMiS by ls1intum.

the class PlagiarismResource method updatePlagiarismComparisonFinalStatus.

/**
 * Updates the final status of a plagiarism comparison concerning one of both students.
 * This process will send a notification to the respective student.
 * I.e. an instructor sends his final verdict/decision
 *
 * @param courseId the id of the course
 * @param comparisonId of the comparison
 * @param studentLogin of the student
 * @param statusDTO is the final status of this plagiarism comparison concerning one of both students
 * @return the final (updated) status of this plagiarism comparison concerning one of both students
 */
@PutMapping("courses/{courseId}/plagiarism-comparisons/{comparisonId}/final-status/{studentLogin}")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<PlagiarismComparisonStatusDTO> updatePlagiarismComparisonFinalStatus(@PathVariable("courseId") long courseId, @PathVariable("comparisonId") long comparisonId, @PathVariable("studentLogin") String studentLogin, @RequestBody PlagiarismComparisonStatusDTO statusDTO) {
    var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(comparisonId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    User affectedUser = userRepository.getUserWithGroupsAndAuthorities(studentLogin);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    PlagiarismStatus finalStatus = statusDTO.getStatus();
    if (!authenticationCheckService.isAtLeastInstructorInCourse(course, user)) {
        throw new AccessForbiddenException("Only instructors responsible for this course can access this plagiarism comparison.");
    }
    if (!Objects.equals(comparison.getPlagiarismResult().getExercise().getCourseViaExerciseGroupOrCourseMember().getId(), courseId)) {
        throw new BadRequestAlertException("The courseId does not belong to the given comparisonId", "PlagiarismComparison", "idMismatch");
    }
    if (comparison.getSubmissionA().getStudentLogin().equals(studentLogin)) {
        plagiarismComparisonRepository.updatePlagiarismComparisonFinalStatusA(comparisonId, finalStatus);
        // needed for notifications
        comparison.setStatusA(finalStatus);
    } else if (comparison.getSubmissionB().getStudentLogin().equals(studentLogin)) {
        plagiarismComparisonRepository.updatePlagiarismComparisonFinalStatusB(comparisonId, finalStatus);
        // needed for notifications
        comparison.setStatusB(finalStatus);
    } else {
        return ResponseEntity.notFound().build();
    }
    singleUserNotificationService.notifyUserAboutFinalPlagiarismState(comparison, affectedUser);
    return ResponseEntity.ok(statusDTO);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) User(de.tum.in.www1.artemis.domain.User) Course(de.tum.in.www1.artemis.domain.Course) PlagiarismStatus(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismStatus) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Course (de.tum.in.www1.artemis.domain.Course)2 User (de.tum.in.www1.artemis.domain.User)2 PlagiarismStatus (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismStatus)2 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)2 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2