Search in sources :

Example 1 with ProgrammingExercise

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);
}
Also used : ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ProgrammingExercise

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());
}
Also used : User(de.tum.in.www1.artemis.domain.User) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) Course(de.tum.in.www1.artemis.domain.Course) Timed(com.codahale.metrics.annotation.Timed) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with ProgrammingExercise

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));
}
Also used : User(de.tum.in.www1.artemis.domain.User) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) Course(de.tum.in.www1.artemis.domain.Course) Timed(com.codahale.metrics.annotation.Timed) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with 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);
}
Also used : User(de.tum.in.www1.artemis.domain.User) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) Course(de.tum.in.www1.artemis.domain.Course) Timed(com.codahale.metrics.annotation.Timed) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with ProgrammingExercise

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();
}
Also used : User(de.tum.in.www1.artemis.domain.User) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) Course(de.tum.in.www1.artemis.domain.Course) Timed(com.codahale.metrics.annotation.Timed) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)10 Timed (com.codahale.metrics.annotation.Timed)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Course (de.tum.in.www1.artemis.domain.Course)6 User (de.tum.in.www1.artemis.domain.User)6 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 ExerciseRepository (de.tum.in.www1.artemis.repository.ExerciseRepository)2 IOException (java.io.IOException)2 URI (java.net.URI)2 Path (java.nio.file.Path)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 Exercise (de.tum.in.www1.artemis.domain.Exercise)1 BambooException (de.tum.in.www1.artemis.exception.BambooException)1 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)1