Search in sources :

Example 1 with PlagiarismCase

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

the class PlagiarismCaseService method createOrAddToPlagiarismCaseForStudent.

/**
 * Create or add to a plagiarism case for a student defined via the submission involved in a plagiarism comparison.
 * The following logic applies:
 *      * <ul>
 *      *     <li>Create a new plagiarism case if the student isn't already part of a plagiarism case in the exercise</li>
 *      *     <li>Add the submission of the student to existing plagiarism case otherwise</li>
 *      * </ul>
 *
 * @param plagiarismComparison  the plagiarism comparison for which to create the plagiarism case
 * @param plagiarismSubmission  the plagiarism submission of the student for which to create the plagiarism case
 */
public void createOrAddToPlagiarismCaseForStudent(PlagiarismComparison<?> plagiarismComparison, PlagiarismSubmission<?> plagiarismSubmission) {
    var plagiarismCase = plagiarismCaseRepository.findByStudentLoginAndExerciseIdWithPlagiarismSubmissions(plagiarismSubmission.getStudentLogin(), plagiarismComparison.getPlagiarismResult().getExercise().getId());
    if (plagiarismCase.isPresent()) {
        // add submission to existing PlagiarismCase for student
        plagiarismSubmission.setPlagiarismCase(plagiarismCase.get());
        plagiarismComparisonRepository.save(plagiarismComparison);
    } else {
        // create new PlagiarismCase for student
        var student = userRepository.getUserByLoginElseThrow(plagiarismSubmission.getStudentLogin());
        PlagiarismCase newPlagiarismCase = new PlagiarismCase();
        newPlagiarismCase.setExercise(plagiarismComparison.getPlagiarismResult().getExercise());
        newPlagiarismCase.setStudent(student);
        var savedPlagiarismCase = plagiarismCaseRepository.save(newPlagiarismCase);
        plagiarismSubmission.setPlagiarismCase(savedPlagiarismCase);
        plagiarismComparisonRepository.save(plagiarismComparison);
    }
}
Also used : PlagiarismCase(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismCase)

Example 2 with PlagiarismCase

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

the class ModelingSubmissionIntegrationTest method getModelSubmissionWithResult_involved_allowed.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void getModelSubmissionWithResult_involved_allowed() throws Exception {
    ModelingSubmission submission = ModelFactory.generateModelingSubmission(validModel, true);
    submission = database.addModelingSubmission(classExercise, submission, "student1");
    PlagiarismComparison<ModelingSubmissionElement> plagiarismComparison = new PlagiarismComparison<>();
    PlagiarismSubmission<ModelingSubmissionElement> submissionA = new PlagiarismSubmission<>();
    submissionA.setStudentLogin("student1");
    submissionA.setSubmissionId(submission.getId());
    plagiarismComparison.setSubmissionA(submissionA);
    PlagiarismCase plagiarismCase = new PlagiarismCase();
    plagiarismCase = plagiarismCaseRepository.save(plagiarismCase);
    Post post = new Post();
    post.setAuthor(userRepo.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 submissionResult = request.get("/api/modeling-submissions/" + submission.getId(), HttpStatus.OK, ModelingSubmission.class);
    assertThat(submissionResult.getParticipation()).as("Should anonymize participation").isNull();
    assertThat(submissionResult.getResults()).as("Should anonymize results").isEmpty();
    assertThat(submissionResult.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) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingSubmissionElement(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingSubmissionElement) PlagiarismSubmission(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission) Post(de.tum.in.www1.artemis.domain.metis.Post) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 3 with PlagiarismCase

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

the class SingleUserNotificationFactoryTest method setUp.

/**
 * sets up all needed mocks and their wanted behavior once for all test cases.
 */
@BeforeAll
public static void setUp() {
    course = new Course();
    course.setId(COURSE_ID);
    lecture = new Lecture();
    lecture.setId(LECTURE_ID);
    lecture.setCourse(course);
    exercise = new TextExercise();
    exercise.setId(EXERCISE_ID);
    exercise.setTitle(EXERCISE_TITLE);
    exercise.setCourse(course);
    exercise.setProblemStatement(PROBLEM_STATEMENT);
    post = new Post();
    post.setExercise(exercise);
    post.setLecture(lecture);
    answerPost = new AnswerPost();
    answerPost.setPost(post);
    cheatingUser = new User();
    cheatingUser.setLogin(USER_LOGIN);
    plagiarismResult = new TextPlagiarismResult();
    plagiarismResult.setExercise(exercise);
    plagiarismSubmission = new PlagiarismSubmission();
    plagiarismSubmission.setStudentLogin(USER_LOGIN);
    plagiarismSubmissionSet = new HashSet<>();
    plagiarismSubmissionSet.add(plagiarismSubmission);
    plagiarismComparison = new PlagiarismComparison();
    plagiarismComparison.setPlagiarismResult(plagiarismResult);
    plagiarismComparison.setSubmissionA(plagiarismSubmission);
    plagiarismCase = new PlagiarismCase();
    plagiarismCase.setExercise(exercise);
    plagiarismCase.setStudent(cheatingUser);
    plagiarismCase.setPlagiarismSubmissions(plagiarismSubmissionSet);
}
Also used : PlagiarismComparison(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison) PlagiarismCase(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismCase) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) Post(de.tum.in.www1.artemis.domain.metis.Post) PlagiarismSubmission(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission) AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with PlagiarismCase

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

the class PostService method getAllPlagiarismCasePosts.

/**
 * Checks course, user and post validity,
 * retrieves and filters posts for a plagiarism case by its id
 * and ensures that sensitive information is filtered out
 *
 * @param postContextFilter filter object
 * @return page of posts that belong to the plagiarism case
 */
public List<Post> getAllPlagiarismCasePosts(PostContextFilter postContextFilter) {
    final User user = userRepository.getUserWithGroupsAndAuthorities();
    final PlagiarismCase plagiarismCase = plagiarismCaseRepository.findByIdElseThrow(postContextFilter.getPlagiarismCaseId());
    // checks
    if (authorizationCheckService.isAtLeastInstructorInCourse(plagiarismCase.getExercise().getCourseViaExerciseGroupOrCourseMember(), user) || plagiarismCase.getStudent().getLogin().equals(user.getLogin())) {
        // retrieve posts
        List<Post> plagiarismCasePosts;
        plagiarismCasePosts = postRepository.findPostsByPlagiarismCaseId(postContextFilter.getPlagiarismCaseId());
        // protect sample solution, grading instructions, etc.
        plagiarismCasePosts.stream().map(Post::getExercise).filter(Objects::nonNull).forEach(Exercise::filterSensitiveInformation);
        return plagiarismCasePosts;
    } else {
        throw new ForbiddenException("Only instructors in the course or the students affected by the plagiarism case are allowed to view its post");
    }
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) User(de.tum.in.www1.artemis.domain.User) PlagiarismCase(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismCase) Exercise(de.tum.in.www1.artemis.domain.Exercise) Post(de.tum.in.www1.artemis.domain.metis.Post)

Example 5 with PlagiarismCase

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

the class PlagiarismCaseResource method getPlagiarismCaseForStudent.

/**
 * Retrieves the plagiarism case with the given ID for the student view.
 *
 * @param courseId the id of the course
 * @param plagiarismCaseId the id of the plagiarism case
 * @return all plagiarism cases of the course
 */
@GetMapping("courses/{courseId}/plagiarism-cases/{plagiarismCaseId}/for-student")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<PlagiarismCase> getPlagiarismCaseForStudent(@PathVariable long courseId, @PathVariable long plagiarismCaseId) {
    log.debug("REST request to get plagiarism case for student with id: {}", plagiarismCaseId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    if (!authenticationCheckService.isAtLeastStudentInCourse(course, user)) {
        throw new AccessForbiddenException("Only students of this course have access to its plagiarism cases.");
    }
    var plagiarismCase = plagiarismCaseRepository.findByIdWithPlagiarismSubmissionsElseThrow(plagiarismCaseId);
    if (!plagiarismCase.getStudent().getLogin().equals(user.getLogin())) {
        throw new AccessForbiddenException("Students only have access to plagiarism cases by which they are affected");
    }
    return getPlagiarismCaseResponseEntity(plagiarismCase);
}
Also used : 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)

Aggregations

PlagiarismCase (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismCase)16 Post (de.tum.in.www1.artemis.domain.metis.Post)12 Course (de.tum.in.www1.artemis.domain.Course)10 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 PlagiarismSubmission (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission)8 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 User (de.tum.in.www1.artemis.domain.User)6 PlagiarismComparison (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison)6 TextSubmissionElement (de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement)6 Test (org.junit.jupiter.api.Test)6 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Exercise (de.tum.in.www1.artemis.domain.Exercise)2 AnswerPost (de.tum.in.www1.artemis.domain.metis.AnswerPost)2 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)2 ModelingSubmissionElement (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingSubmissionElement)2 MimeMessage (javax.mail.internet.MimeMessage)2 ForbiddenException (javax.ws.rs.ForbiddenException)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2