use of de.tum.in.www1.artemis.domain.ProgrammingExercise in project ArTEMiS by ls1intum.
the class ProgrammingExerciseResourceIntTest method updateProgrammingExercise.
@Test
@Transactional
public void updateProgrammingExercise() throws Exception {
// Initialize the database
programmingExerciseRepository.saveAndFlush(programmingExercise);
int databaseSizeBeforeUpdate = programmingExerciseRepository.findAll().size();
// Update the programmingExercise
ProgrammingExercise updatedProgrammingExercise = programmingExerciseRepository.findOne(programmingExercise.getId());
updatedProgrammingExercise.baseRepositoryUrl(UPDATED_BASE_REPOSITORY_URL).baseBuildPlanId(UPDATED_BASE_BUILD_PLAN_ID).publishBuildPlanUrl(UPDATED_PUBLISH_BUILD_PLAN_URL).allowOnlineEditor(UPDATED_ALLOW_ONLINE_EDITOR);
restProgrammingExerciseMockMvc.perform(put("/api/programming-exercises").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedProgrammingExercise))).andExpect(status().isOk());
// Validate the ProgrammingExercise in the database
List<ProgrammingExercise> programmingExerciseList = programmingExerciseRepository.findAll();
assertThat(programmingExerciseList).hasSize(databaseSizeBeforeUpdate);
ProgrammingExercise testProgrammingExercise = programmingExerciseList.get(programmingExerciseList.size() - 1);
assertThat(testProgrammingExercise.getBaseRepositoryUrl()).isEqualTo(UPDATED_BASE_REPOSITORY_URL);
assertThat(testProgrammingExercise.getBaseBuildPlanId()).isEqualTo(UPDATED_BASE_BUILD_PLAN_ID);
assertThat(testProgrammingExercise.isPublishBuildPlanUrl()).isEqualTo(UPDATED_PUBLISH_BUILD_PLAN_URL);
assertThat(testProgrammingExercise.isAllowOnlineEditor()).isEqualTo(UPDATED_ALLOW_ONLINE_EDITOR);
}
use of de.tum.in.www1.artemis.domain.ProgrammingExercise in project ArTEMiS by ls1intum.
the class ProgrammingExerciseResource method getAllProgrammingExercises.
/**
* GET /programming-exercises : get all the programmingExercises.
*
* @return the ResponseEntity with status 200 (OK) and the list of programmingExercises in body
*/
@GetMapping("/programming-exercises")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public List<ProgrammingExercise> getAllProgrammingExercises() {
log.debug("REST request to get all ProgrammingExercises");
List<ProgrammingExercise> exercises = programmingExerciseRepository.findAll();
Stream<ProgrammingExercise> authorizedExercises = exercises.stream().filter(exercise -> {
Course course = exercise.getCourse();
User user = userService.getUserWithGroupsAndAuthorities();
return authCheckService.isTeachingAssistantInCourse(course, user) || authCheckService.isInstructorInCourse(course, user) || authCheckService.isAdmin();
});
return authorizedExercises.collect(Collectors.toList());
}
use of de.tum.in.www1.artemis.domain.ProgrammingExercise 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.ProgrammingExercise 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.ProgrammingExercise 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();
}
Aggregations