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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations