use of de.tum.in.www1.artemis.domain.Course in project ArTEMiS by ls1intum.
the class ProgrammingExerciseResource method getProgrammingExercise.
/**
* GET /programming-exercises/:id : get the "id" programmingExercise.
*
* @param id the id of the programmingExercise to retrieve
* @return the ResponseEntity with status 200 (OK) and with body the programmingExercise, or with status 404 (Not Found)
*/
@GetMapping("/programming-exercises/{id}")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public ResponseEntity<ProgrammingExercise> getProgrammingExercise(@PathVariable Long id) {
log.debug("REST request to get ProgrammingExercise : {}", id);
ProgrammingExercise programmingExercise = programmingExerciseRepository.findOne(id);
Course course = programmingExercise.getCourse();
User user = userService.getUserWithGroupsAndAuthorities();
if (!authCheckService.isTeachingAssistantInCourse(course, user) && !authCheckService.isInstructorInCourse(course, user) && !authCheckService.isAdmin()) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
return ResponseUtil.wrapOrNotFound(Optional.ofNullable(programmingExercise));
}
use of de.tum.in.www1.artemis.domain.Course in project ArTEMiS by ls1intum.
the class ProgrammingExerciseResource method updateProgrammingExercise.
/**
* PUT /programming-exercises : Updates an existing programmingExercise.
*
* @param programmingExercise the programmingExercise to update
* @return the ResponseEntity with status 200 (OK) and with body the updated programmingExercise,
* or with status 400 (Bad Request) if the programmingExercise is not valid,
* or with status 500 (Internal Server Error) if the programmingExercise couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/programming-exercises")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public ResponseEntity<ProgrammingExercise> updateProgrammingExercise(@RequestBody ProgrammingExercise programmingExercise) throws URISyntaxException {
log.debug("REST request to update ProgrammingExercise : {}", programmingExercise);
if (programmingExercise.getId() == null) {
return createProgrammingExercise(programmingExercise);
}
// fetch course from database to make sure client didn't change groups
Course course = courseService.findOne(programmingExercise.getCourse().getId());
if (course == null) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "courseNotFound", "The course belonging to this programming exercise does not exist")).body(null);
}
User user = userService.getUserWithGroupsAndAuthorities();
if (!authCheckService.isTeachingAssistantInCourse(course, user) && !authCheckService.isInstructorInCourse(course, user) && !authCheckService.isAdmin()) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
ResponseEntity<ProgrammingExercise> errorResponse = checkProgrammingExerciseForError(programmingExercise);
if (errorResponse != null) {
return errorResponse;
}
ProgrammingExercise result = programmingExerciseRepository.save(programmingExercise);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, programmingExercise.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Course in project ArTEMiS by ls1intum.
the class ProgrammingExerciseResource method deleteProgrammingExercise.
/**
* DELETE /programming-exercises/:id : delete the "id" programmingExercise.
*
* @param id the id of the programmingExercise to delete
* @return the ResponseEntity with status 200 (OK)
*/
@DeleteMapping("/programming-exercises/{id}")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public ResponseEntity<Void> deleteProgrammingExercise(@PathVariable Long id) {
log.debug("REST request to delete ProgrammingExercise : {}", id);
ProgrammingExercise programmingExercise = programmingExerciseRepository.findOne(id);
Course course = programmingExercise.getCourse();
User user = userService.getUserWithGroupsAndAuthorities();
if (!authCheckService.isTeachingAssistantInCourse(course, user) && !authCheckService.isInstructorInCourse(course, user) && !authCheckService.isAdmin()) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
programmingExerciseRepository.delete(id);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build();
}
use of de.tum.in.www1.artemis.domain.Course in project ArTEMiS by ls1intum.
the class ParticipationResource method getParticipationRepositoryWebUrl.
@GetMapping(value = "/participations/{id}/repositoryWebUrl")
@PreAuthorize("hasAnyRole('USER', 'TA', 'INSTRUCTOR', 'ADMIN')")
public ResponseEntity<String> getParticipationRepositoryWebUrl(@PathVariable Long id, Authentication authentication) {
log.debug("REST request to get Participation : {}", id);
Participation participation = participationService.findOne(id);
Course course = participation.getExercise().getCourse();
if (!authCheckService.isOwnerOfParticipation(participation)) {
if (!courseService.userHasTAPermissions(course)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
}
URL url = versionControlService.get().getRepositoryWebUrl(participation);
return Optional.ofNullable(url).map(result -> new ResponseEntity<>(url.toString(), HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
use of de.tum.in.www1.artemis.domain.Course in project ArTEMiS by ls1intum.
the class ParticipationResource method getParticipationBuildPlanWebUrl.
@GetMapping(value = "/participations/{id}/buildPlanWebUrl")
@PreAuthorize("hasAnyRole('USER', 'TA', 'INSTRUCTOR', 'ADMIN')")
public ResponseEntity<String> getParticipationBuildPlanWebUrl(@PathVariable Long id) {
log.debug("REST request to get Participation : {}", id);
Participation participation = participationService.findOne(id);
Course course = participation.getExercise().getCourse();
if (!authCheckService.isOwnerOfParticipation(participation)) {
if (!courseService.userHasTAPermissions(course)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
}
URL url = continuousIntegrationService.get().getBuildPlanWebUrl(participation);
return Optional.ofNullable(url).map(result -> new ResponseEntity<>(url.toString(), HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
Aggregations