Search in sources :

Example 6 with PlagiarismComparison

use of de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison 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 7 with PlagiarismComparison

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

the class PlagiarismResource method updatePlagiarismComparisonStatus.

/**
 * Update the status of the plagiarism comparison with the given ID.
 * I.e. An editor or instructor sees a possible plagiarism case for the first time and decides if it should be further examined, or if it is not a plagiarism.
 *
 * @param comparisonId of the plagiarism comparison to update the status of
 * @param courseId the id of the course
 * @param statusDTO new status for the given comparison
 * @return the ResponseEntity with status 200 (Ok) or with status 400 (Bad Request) if the parameters are invalid
 */
@PutMapping("courses/{courseId}/plagiarism-comparisons/{comparisonId}/status")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Void> updatePlagiarismComparisonStatus(@PathVariable("courseId") long courseId, @PathVariable("comparisonId") long comparisonId, @RequestBody PlagiarismComparisonStatusDTO statusDTO) {
    log.info("REST request to update the status {} of the plagiarism comparison with id: {}", statusDTO.getStatus(), comparisonId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    authenticationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, course, null);
    // TODO: this check can take up to a few seconds in the worst case, we should do it directly in the database
    var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(comparisonId);
    if (!Objects.equals(comparison.getPlagiarismResult().getExercise().getCourseViaExerciseGroupOrCourseMember().getId(), courseId)) {
        throw new BadRequestAlertException("The courseId does not belong to the given comparisonId", "PlagiarismComparison", "idMismatch");
    }
    plagiarismComparisonRepository.updatePlagiarismComparisonStatus(comparisonId, statusDTO.getStatus());
    log.info("Finished updating the status {} of the plagiarism comparison with id: {}", statusDTO.getStatus(), comparisonId);
    return ResponseEntity.ok().body(null);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 8 with PlagiarismComparison

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

the class PlagiarismResource method updatePlagiarismComparisonInstructorStatement.

/**
 * Updates an instructor statement on a plagiarismComparison (for one side).
 * This process will send a notification to the respective student.
 * I.e. the instructor sets a personal message to one of the accused students.
 *
 * @param courseId the id of the course
 * @param comparisonId the id of the PlagiarismComparison
 * @param studentLogin of one of accused students
 * @param statement of the instructor directed to one of the accused students
 * @return the instructor statement (convention)
 */
@PutMapping("courses/{courseId}/plagiarism-comparisons/{comparisonId}/instructor-statement/{studentLogin}")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<PlagiarismStatementDTO> updatePlagiarismComparisonInstructorStatement(@PathVariable("courseId") long courseId, @PathVariable("comparisonId") long comparisonId, @PathVariable("studentLogin") String studentLogin, @RequestBody PlagiarismStatementDTO statement) {
    var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(comparisonId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    User affectedUser = userRepository.getUserByLoginElseThrow(studentLogin);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    String instructorStatement = statement.statement;
    if (!authenticationCheckService.isAtLeastInstructorInCourse(course, user)) {
        throw new AccessForbiddenException("Only instructors responsible for this course can access this plagiarism case.");
    }
    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.updatePlagiarismComparisonInstructorStatementA(comparison.getId(), instructorStatement);
        // needed for notifications
        comparison.setInstructorStatementA(instructorStatement);
    } else if (comparison.getSubmissionB().getStudentLogin().equals(studentLogin)) {
        plagiarismComparisonRepository.updatePlagiarismComparisonInstructorStatementB(comparison.getId(), instructorStatement);
        // needed for notifications
        comparison.setInstructorStatementB(instructorStatement);
    } else {
        throw new EntityNotFoundException("Student with id not found in plagiarism comparison");
    }
    singleUserNotificationService.notifyUserAboutNewPossiblePlagiarismCase(comparison, affectedUser);
    return ResponseEntity.ok(statement);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) User(de.tum.in.www1.artemis.domain.User) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) Course(de.tum.in.www1.artemis.domain.Course) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 9 with PlagiarismComparison

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

the class PlagiarismService method anonymizeComparisonForStudentView.

/**
 * Anonymizes the comparison for the student view.
 * A student should not have sensitive information (e.g. the userLogin of the other student)
 *
 * @param comparison that has to be anonymized.
 * @param userLogin of the student asking to see his plagiarism comparison.
 * @return the anoymized plagiarism comparison for the given student
 */
public PlagiarismComparison anonymizeComparisonForStudentView(PlagiarismComparison comparison, String userLogin) {
    if (comparison.getSubmissionA().getStudentLogin().equals(userLogin)) {
        comparison.getSubmissionA().setStudentLogin(YOUR_SUBMISSION);
        comparison.getSubmissionB().setStudentLogin(OTHER_SUBMISSION);
        comparison.setInstructorStatementB(null);
    } else if (comparison.getSubmissionB().getStudentLogin().equals(userLogin)) {
        comparison.getSubmissionA().setStudentLogin(OTHER_SUBMISSION);
        comparison.getSubmissionB().setStudentLogin(YOUR_SUBMISSION);
        comparison.setInstructorStatementA(null);
    } else {
        throw new AccessForbiddenException("This plagiarism comparison is not related to the requesting user.");
    }
    return comparison;
}
Also used : AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)

Example 10 with PlagiarismComparison

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

the class PlagiarismIntegrationTest method saveStudentStatementForStudentB.

/**
 * Checks the method updatePlagiarismComparisonStudentStatement for student B
 */
@Test
@WithMockUser(username = "student2", roles = "USER")
public void saveStudentStatementForStudentB() throws Exception {
    Course course = database.addCourseWithOneFinishedTextExercise();
    TextExercise textExercise = textExerciseRepository.findByCourseIdWithCategories(course.getId()).get(0);
    TextPlagiarismResult textPlagiarismResult = database.createTextPlagiarismResultForExercise(textExercise);
    PlagiarismComparison<TextSubmissionElement> plagiarismComparison = new PlagiarismComparison<>();
    plagiarismComparison.setPlagiarismResult(textPlagiarismResult);
    plagiarismComparison.setInstructorStatementB(INSTRUCTOR_STATEMENT_B);
    PlagiarismSubmission<TextSubmissionElement> submissionB = new PlagiarismSubmission<>();
    submissionB.setStudentLogin("student2");
    plagiarismComparison.setSubmissionB(submissionB);
    plagiarismComparisonRepository.save(plagiarismComparison);
    var statement = new PlagiarismResource.PlagiarismStatementDTO();
    statement.statement = "test statement";
    request.put("/api/courses/" + course.getId() + "/plagiarism-comparisons/" + plagiarismComparison.getId() + "/student-statement", statement, HttpStatus.OK);
    var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(plagiarismComparison.getId());
    assertThat(comparison.getStudentStatementB()).as("should update student statement").isEqualTo("test statement");
}
Also used : PlagiarismComparison(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) PlagiarismSubmission(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission) TextExercise(de.tum.in.www1.artemis.domain.TextExercise) Course(de.tum.in.www1.artemis.domain.Course) TextSubmissionElement(de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Aggregations

Course (de.tum.in.www1.artemis.domain.Course)37 PlagiarismComparison (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison)30 PlagiarismSubmission (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission)28 TextSubmissionElement (de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement)27 WithMockUser (org.springframework.security.test.context.support.WithMockUser)27 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)25 Test (org.junit.jupiter.api.Test)25 TextExercise (de.tum.in.www1.artemis.domain.TextExercise)21 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)17 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)16 User (de.tum.in.www1.artemis.domain.User)15 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)15 PlagiarismCase (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismCase)10 Post (de.tum.in.www1.artemis.domain.metis.Post)8 PlagiarismComparisonStatusDTO (de.tum.in.www1.artemis.web.rest.dto.PlagiarismComparisonStatusDTO)6 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)4 ModelingSubmissionElement (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingSubmissionElement)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 PlagiarismStatus (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismStatus)3 PlagiarismCaseDTO (de.tum.in.www1.artemis.web.rest.dto.PlagiarismCaseDTO)3