Search in sources :

Example 6 with Course

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));
}
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 7 with Course

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);
}
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 8 with Course

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();
}
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 9 with Course

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));
}
Also used : de.tum.in.www1.artemis.service(de.tum.in.www1.artemis.service) Logger(org.slf4j.Logger) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) Timed(com.codahale.metrics.annotation.Timed) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) Principal(java.security.Principal) AbstractAuthenticationToken(org.springframework.security.authentication.AbstractAuthenticationToken) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) Authentication(org.springframework.security.core.Authentication) HeaderUtil(de.tum.in.www1.artemis.web.rest.util.HeaderUtil) ResponseEntity(org.springframework.http.ResponseEntity) URL(java.net.URL) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 10 with Course

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));
}
Also used : de.tum.in.www1.artemis.service(de.tum.in.www1.artemis.service) Logger(org.slf4j.Logger) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) Timed(com.codahale.metrics.annotation.Timed) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) Principal(java.security.Principal) AbstractAuthenticationToken(org.springframework.security.authentication.AbstractAuthenticationToken) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) Authentication(org.springframework.security.core.Authentication) HeaderUtil(de.tum.in.www1.artemis.web.rest.util.HeaderUtil) ResponseEntity(org.springframework.http.ResponseEntity) URL(java.net.URL) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 Course (de.tum.in.www1.artemis.domain.Course)9 URI (java.net.URI)7 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)6 User (de.tum.in.www1.artemis.domain.User)6 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)6 Transactional (org.springframework.transaction.annotation.Transactional)5 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)3 de.tum.in.www1.artemis.service (de.tum.in.www1.artemis.service)3 HeaderUtil (de.tum.in.www1.artemis.web.rest.util.HeaderUtil)3 URISyntaxException (java.net.URISyntaxException)3 Test (org.junit.Test)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 HttpStatus (org.springframework.http.HttpStatus)3 ResponseEntity (org.springframework.http.ResponseEntity)3 Authentication (org.springframework.security.core.Authentication)3 org.springframework.web.bind.annotation (org.springframework.web.bind.annotation)3