Search in sources :

Example 26 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project Artemis by ls1intum.

the class ProgrammingExerciseTestService method resumeProgrammingExerciseByTriggeringInstructorBuild_correctInitializationState.

// TEST
public void resumeProgrammingExerciseByTriggeringInstructorBuild_correctInitializationState(ExerciseMode exerciseMode) throws Exception {
    var participation = createStudentParticipationWithSubmission(exerciseMode);
    var participant = participation.getParticipant();
    mockDelegate.mockTriggerInstructorBuildAll(participation);
    // We need to mock the call again because we are triggering the build twice in order to verify that the submission isn't re-created
    mockDelegate.mockTriggerInstructorBuildAll(participation);
    mockDelegate.mockDefaultBranch(participation.getProgrammingExercise());
    // These will be updated triggering a failed build
    participation.setInitializationState(InitializationState.INACTIVE);
    participation.setBuildPlanId(null);
    programmingExerciseStudentParticipationRepository.saveAndFlush(participation);
    var url = "/api/programming-exercises/" + exercise.getId() + "/trigger-instructor-build-all";
    request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
    Awaitility.setDefaultTimeout(Duration.ofSeconds(20));
    await().until(() -> programmingExerciseRepository.findWithTemplateAndSolutionParticipationTeamAssignmentConfigCategoriesById(exercise.getId()).isPresent());
    // Fetch updated participation and assert
    ProgrammingExerciseStudentParticipation updatedParticipation = (ProgrammingExerciseStudentParticipation) participationRepository.findByIdElseThrow(participation.getId());
    assertThat(updatedParticipation.getInitializationState()).as("Participation should be initialized").isEqualTo(InitializationState.INITIALIZED);
    assertThat(updatedParticipation.getBuildPlanId()).as("Build Plan Id should be set").isEqualTo(exercise.getProjectKey().toUpperCase() + "-" + participant.getParticipantIdentifier().toUpperCase());
    // Trigger the build again and make sure no new submission is created
    request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
    var submissions = submissionRepository.findAll();
    assertThat(submissions).hasSize(1);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)

Example 27 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project Artemis by ls1intum.

the class ComplaintResource method getNumberOfAllowedComplaintsInCourse.

/**
 * Get courses/{courseId}/allowed-complaints get the number of complaints that a student or team is still allowed to submit in the given course.
 * It is determined by the max. complaint limit and the current number of open or rejected complaints of the student or team in the course.
 * Students use their personal complaints for individual exercises and team complaints for team-based exercises, i.e. each student has
 * maxComplaints for personal complaints and additionally maxTeamComplaints for complaints by their team in the course.
 *
 * @param courseId the id of the course for which we want to get the number of allowed complaints
 * @param teamMode whether to return the number of allowed complaints per team (instead of per student)
 * @return the ResponseEntity with status 200 (OK) and the number of still allowed complaints
 */
@GetMapping("courses/{courseId}/allowed-complaints")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Long> getNumberOfAllowedComplaintsInCourse(@PathVariable Long courseId, @RequestParam(defaultValue = "false") Boolean teamMode) {
    log.debug("REST request to get the number of unaccepted Complaints associated to the current user in course : {}", courseId);
    User user = userRepository.getUser();
    Participant participant = user;
    Course course = courseRepository.findByIdElseThrow(courseId);
    if (!course.getComplaintsEnabled()) {
        throw new BadRequestAlertException("Complaints are disabled for this course", COMPLAINT_ENTITY_NAME, "complaintsDisabled");
    }
    if (teamMode) {
        Optional<Team> team = teamRepository.findAllByCourseIdAndUserIdOrderByIdDesc(course.getId(), user.getId()).stream().findFirst();
        participant = team.orElseThrow(() -> new BadRequestAlertException("You do not belong to a team in this course.", COMPLAINT_ENTITY_NAME, "noAssignedTeamInCourse"));
    }
    long unacceptedComplaints = complaintService.countUnacceptedComplaintsByParticipantAndCourseId(participant, courseId);
    return ResponseEntity.ok(Math.max(complaintService.getMaxComplaintsPerParticipant(course, participant) - unacceptedComplaints, 0));
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) Participant(de.tum.in.www1.artemis.domain.participation.Participant) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 28 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project Artemis by ls1intum.

the class ComplaintResponseResource method handleComplaintResponse.

private ResponseEntity<ComplaintResponse> handleComplaintResponse(long complaintId, Principal principal, Optional<ComplaintResponse> optionalComplaintResponse) {
    if (optionalComplaintResponse.isEmpty()) {
        throw new EntityNotFoundException("ComplaintResponse with " + complaintId + " was not found!");
    }
    var user = userRepository.getUserWithGroupsAndAuthorities();
    var complaintResponse = optionalComplaintResponse.get();
    // All tutors and higher can see this, and also the students who first open the complaint
    Participant originalAuthor = complaintResponse.getComplaint().getParticipant();
    StudentParticipation studentParticipation = (StudentParticipation) complaintResponse.getComplaint().getResult().getParticipation();
    Exercise exercise = studentParticipation.getExercise();
    var atLeastTA = authorizationCheckService.isAtLeastTeachingAssistantForExercise(exercise, user);
    if (!atLeastTA && !isOriginalAuthor(principal, originalAuthor)) {
        throw new AccessForbiddenException("Insufficient permission for this complaint response");
    }
    if (!authorizationCheckService.isAtLeastInstructorForExercise(exercise, user)) {
        complaintResponse.getComplaint().setParticipant(null);
    }
    if (!atLeastTA) {
        complaintResponse.setReviewer(null);
    }
    if (isOriginalAuthor(principal, originalAuthor)) {
        // hide complaint completely if the user is the student who created the complaint
        complaintResponse.setComplaint(null);
    } else {
        // hide unnecessary information
        complaintResponse.getComplaint().getResult().setParticipation(null);
        complaintResponse.getComplaint().getResult().setSubmission(null);
    }
    return ResponseUtil.wrapOrNotFound(optionalComplaintResponse);
}
Also used : Participant(de.tum.in.www1.artemis.domain.participation.Participant) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)

Example 29 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project Artemis by ls1intum.

the class ParticipantScoreResource method getParticipantScoresOfExam.

/**
 * GET /exams/:examId/participant-scores  gets the participant scores of the exam
 *
 * @param examId     the id of the exam for which to get the participant score
 * @param pageable   pageable object
 * @param getUnpaged if set all participant scores of the exam will be loaded (paging deactivated)
 * @return the ResponseEntity with status 200 (OK) and with the participant scores in the body
 */
@GetMapping("/exams/{examId}/participant-scores")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreDTO>> getParticipantScoresOfExam(@PathVariable Long examId, Pageable pageable, @RequestParam(value = "getUnpaged", required = false, defaultValue = "false") boolean getUnpaged) {
    long start = System.currentTimeMillis();
    log.debug("REST request to get participant scores for exam : {}", examId);
    Set<Exercise> exercisesOfExam = getExercisesOfExam(examId);
    Pageable page;
    if (getUnpaged) {
        page = Pageable.unpaged();
    } else {
        page = pageable;
    }
    List<ParticipantScoreDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreDTOs(page, exercisesOfExam);
    log.info("getParticipantScoresOfExam took {}ms", System.currentTimeMillis() - start);
    return ResponseEntity.ok().body(resultsOfAllExercises);
}
Also used : Exercise(de.tum.in.www1.artemis.domain.Exercise) Pageable(org.springframework.data.domain.Pageable) ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 30 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project Artemis by ls1intum.

the class ParticipantScoreResource method getParticipantScoresOfCourse.

/**
 * GET /courses/:courseId/participant-scores  gets the participant scores of the course
 *
 * @param courseId   the id of the course for which to get the participant score
 * @param pageable   pageable object
 * @param getUnpaged if set all participant scores of the course will be loaded (paging deactivated)
 * @return the ResponseEntity with status 200 (OK) and with the participant scores in the body
 */
@GetMapping("/courses/{courseId}/participant-scores")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreDTO>> getParticipantScoresOfCourse(@PathVariable Long courseId, Pageable pageable, @RequestParam(value = "getUnpaged", required = false, defaultValue = "false") boolean getUnpaged) {
    long start = System.currentTimeMillis();
    log.debug("REST request to get participant scores for course : {}", courseId);
    Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    Set<Exercise> exercisesOfCourse = course.getExercises().stream().filter(Exercise::isCourseExercise).collect(toSet());
    List<ParticipantScoreDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreDTOs(getUnpaged ? Pageable.unpaged() : pageable, exercisesOfCourse);
    log.info("getParticipantScoresOfCourse took {}ms", System.currentTimeMillis() - start);
    return ResponseEntity.ok().body(resultsOfAllExercises);
}
Also used : Exercise(de.tum.in.www1.artemis.domain.Exercise) Course(de.tum.in.www1.artemis.domain.Course) ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)21 Participant (de.tum.in.www1.artemis.domain.participation.Participant)15 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)14 ParticipantScore (de.tum.in.www1.artemis.domain.scores.ParticipantScore)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 ParticipantScoreDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO)12 StudentScore (de.tum.in.www1.artemis.domain.scores.StudentScore)10 TeamScore (de.tum.in.www1.artemis.domain.scores.TeamScore)10 Test (org.junit.jupiter.api.Test)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)10 Exercise (de.tum.in.www1.artemis.domain.Exercise)8 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)8 ParticipantScoreAverageDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO)8 java.util (java.util)8 Collectors (java.util.stream.Collectors)8 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)7 QuizSubmission (de.tum.in.www1.artemis.domain.quiz.QuizSubmission)7 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)6 Course (de.tum.in.www1.artemis.domain.Course)6 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)6