Search in sources :

Example 26 with PlagiarismComparison

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

the class PlagiarismService method anonymizeComparisonForStudent.

/**
 * Anonymize the comparison for the student view.
 * A student should not have sensitive information (e.g. the userLogin of the other student)
 *
 * @param comparison to anonymize.
 * @param userLogin of the student asking to see his plagiarism comparison.
 * @return the anonymized plagiarism comparison for the given student
 */
public PlagiarismComparison anonymizeComparisonForStudent(PlagiarismComparison comparison, String userLogin) {
    if (comparison.getSubmissionA().getStudentLogin().equals(userLogin)) {
        comparison.getSubmissionA().setStudentLogin(YOUR_SUBMISSION);
        comparison.getSubmissionB().setStudentLogin(OTHER_SUBMISSION);
    } else if (comparison.getSubmissionB().getStudentLogin().equals(userLogin)) {
        comparison.getSubmissionA().setStudentLogin(OTHER_SUBMISSION);
        comparison.getSubmissionB().setStudentLogin(YOUR_SUBMISSION);
    } 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 27 with PlagiarismComparison

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

the class PlagiarismResource method getPlagiarismComparisonForSplitView.

/**
 * Retrieves the plagiarismComparison specified by its ID.
 * If a studentLogin is passed the comparison is anonymized
 *
 * @param courseId the id of the course
 * @param comparisonId the id of the PlagiarismComparison
 * @param studentLogin optional login of the student
 * @return the PlagiarismComparison
 * @throws AccessForbiddenException if the requesting user is not affected by the plagiarism case.
 */
@GetMapping("courses/{courseId}/plagiarism-comparisons/{comparisonId}/for-split-view")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<PlagiarismComparison<?>> getPlagiarismComparisonForSplitView(@PathVariable("courseId") long courseId, @PathVariable("comparisonId") Long comparisonId, @RequestParam(value = "studentLogin", required = false) String studentLogin) {
    var comparisonA = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsAndElementsAElseThrow(comparisonId);
    var comparisonB = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsAndElementsBElseThrow(comparisonId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    if (!authenticationCheckService.isAtLeastStudentInCourse(course, user)) {
        throw new AccessForbiddenException("Only students registered for this course can access this plagiarism comparison.");
    }
    if (!Objects.equals(comparisonA.getPlagiarismResult().getExercise().getCourseViaExerciseGroupOrCourseMember().getId(), courseId)) {
        throw new BadRequestAlertException("The courseId does not belong to the given comparisonId", "PlagiarismComparison", "idMismatch");
    }
    comparisonA.setSubmissionB(comparisonB.getSubmissionB());
    if (studentLogin != null) {
        comparisonA = this.plagiarismService.anonymizeComparisonForStudent(comparisonA, studentLogin);
    }
    comparisonA.getSubmissionA().setPlagiarismComparison(null);
    comparisonB.getSubmissionB().setPlagiarismComparison(null);
    return ResponseEntity.ok(comparisonA);
}
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) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 28 with PlagiarismComparison

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

the class TextSubmissionIntegrationTest method getTextSubmissionWithResult_involved_allowed.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void getTextSubmissionWithResult_involved_allowed() throws Exception {
    textSubmission = database.saveTextSubmission(finishedTextExercise, textSubmission, "student1");
    PlagiarismComparison<TextSubmissionElement> plagiarismComparison = new PlagiarismComparison<>();
    PlagiarismSubmission<TextSubmissionElement> submissionA = new PlagiarismSubmission<>();
    submissionA.setStudentLogin("student1");
    submissionA.setSubmissionId(this.textSubmission.getId());
    plagiarismComparison.setSubmissionA(submissionA);
    PlagiarismCase plagiarismCase = new PlagiarismCase();
    plagiarismCase = plagiarismCaseRepository.save(plagiarismCase);
    Post post = new Post();
    post.setAuthor(userRepository.getUserByLoginElseThrow("instructor1"));
    post.setTitle("Title Plagiarism Case Post");
    post.setContent("Content Plagiarism Case Post");
    post.setVisibleForStudents(true);
    post.setPlagiarismCase(plagiarismCase);
    postRepository.save(post);
    submissionA.setPlagiarismCase(plagiarismCase);
    plagiarismComparisonRepository.save(plagiarismComparison);
    var submission = request.get("/api/text-submissions/" + this.textSubmission.getId(), HttpStatus.OK, TextSubmission.class);
    assertThat(submission.getParticipation()).as("Should anonymize participation").isNull();
    assertThat(submission.getResults()).as("Should anonymize results").isEmpty();
    assertThat(submission.getSubmissionDate()).as("Should anonymize submission date").isNull();
}
Also used : PlagiarismComparison(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison) PlagiarismCase(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismCase) PlagiarismSubmission(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission) Post(de.tum.in.www1.artemis.domain.metis.Post) TextSubmissionElement(de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 29 with PlagiarismComparison

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

the class PlagiarismCaseIntegrationTest method initTestCase.

@BeforeEach
public void initTestCase() {
    database.addUsers(3, 1, 1, 1);
    course = database.addCourseWithOneFinishedTextExercise();
    textExercise = textExerciseRepository.findByCourseIdWithCategories(course.getId()).get(0);
    plagiarismCase1 = new PlagiarismCase();
    plagiarismCase1.setExercise(textExercise);
    User student1 = database.getUserByLogin("student1");
    plagiarismCase1.setStudent(student1);
    plagiarismCase1 = plagiarismCaseRepository.save(plagiarismCase1);
    PlagiarismResult<TextSubmissionElement> textPlagiarismResult = database.createTextPlagiarismResultForExercise(textExercise);
    PlagiarismComparison<TextSubmissionElement> plagiarismComparison = new PlagiarismComparison<>();
    plagiarismComparison.setPlagiarismResult(textPlagiarismResult);
    plagiarismComparison = plagiarismComparisonRepository.save(plagiarismComparison);
    PlagiarismSubmission<TextSubmissionElement> plagiarismSubmission1 = new PlagiarismSubmission<>();
    plagiarismSubmission1.setStudentLogin("student1");
    plagiarismSubmission1.setPlagiarismCase(plagiarismCase1);
    plagiarismSubmission1.setPlagiarismComparison(plagiarismComparison);
    PlagiarismSubmission<TextSubmissionElement> plagiarismSubmission2 = new PlagiarismSubmission<>();
    plagiarismSubmission2.setStudentLogin("student2");
    plagiarismSubmission2.setPlagiarismCase(plagiarismCase1);
    plagiarismSubmission2.setPlagiarismComparison(plagiarismComparison);
    plagiarismComparison.setSubmissionA(plagiarismSubmission1);
    plagiarismComparison.setSubmissionB(plagiarismSubmission2);
    plagiarismComparisonRepository.save(plagiarismComparison);
    plagiarismCase2 = new PlagiarismCase();
    plagiarismCase2.setExercise(textExercise);
    User student2 = database.getUserByLogin("student2");
    plagiarismCase2.setStudent(student2);
    plagiarismCase2 = plagiarismCaseRepository.save(plagiarismCase2);
    plagiarismCase3 = new PlagiarismCase();
    plagiarismCase3.setExercise(textExercise);
    User student3 = database.getUserByLogin("student3");
    plagiarismCase3.setStudent(student3);
    plagiarismCase3 = plagiarismCaseRepository.save(plagiarismCase3);
}
Also used : User(de.tum.in.www1.artemis.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) TextSubmissionElement(de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 30 with PlagiarismComparison

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

the class SingleUserNotificationServiceTest method setUp.

/**
 * Sets up all needed mocks and their wanted behavior
 */
@BeforeEach
public void setUp() {
    SecurityUtils.setAuthorizationObject();
    course = database.createCourse();
    List<User> users = database.addUsers(3, 0, 0, 0);
    user = users.get(0);
    exercise = new TextExercise();
    exercise.setCourse(course);
    exercise.setMaxPoints(10D);
    fileUploadExercise = new FileUploadExercise();
    fileUploadExercise.setCourse(course);
    Lecture lecture = new Lecture();
    lecture.setCourse(course);
    post = new Post();
    post.setExercise(exercise);
    post.setLecture(lecture);
    post.setAuthor(user);
    post.setCourse(course);
    PlagiarismSubmission<TextSubmissionElement> plagiarismSubmission = new PlagiarismSubmission<>();
    plagiarismSubmission.setStudentLogin(user.getLogin());
    TextPlagiarismResult plagiarismResult = new TextPlagiarismResult();
    plagiarismResult.setExercise(exercise);
    plagiarismComparison = new PlagiarismComparison<>();
    plagiarismComparison.setSubmissionA(plagiarismSubmission);
    plagiarismComparison.setPlagiarismResult(plagiarismResult);
    plagiarismCase = new PlagiarismCase();
    plagiarismCase.setExercise(exercise);
    result = new Result();
    result.setScore(1D);
    result.setCompletionDate(ZonedDateTime.now().minusMinutes(1));
    doNothing().when(javaMailSender).send(any(MimeMessage.class));
}
Also used : Post(de.tum.in.www1.artemis.domain.metis.Post) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) PlagiarismCase(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismCase) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) MimeMessage(javax.mail.internet.MimeMessage) PlagiarismSubmission(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission) TextSubmissionElement(de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement) BeforeEach(org.junit.jupiter.api.BeforeEach)

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