1 | package edu.ucsb.cs156.frontiers.controllers; | |
2 | ||
3 | ||
4 | import edu.ucsb.cs156.frontiers.entities.Course; | |
5 | import edu.ucsb.cs156.frontiers.entities.Job; | |
6 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
7 | import edu.ucsb.cs156.frontiers.errors.NoLinkedOrganizationException; | |
8 | import edu.ucsb.cs156.frontiers.jobs.CreateStudentRepositoriesJob; | |
9 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
10 | import edu.ucsb.cs156.frontiers.services.RepositoryService; | |
11 | import edu.ucsb.cs156.frontiers.services.jobs.JobService; | |
12 | import io.swagger.v3.oas.annotations.tags.Tag; | |
13 | import org.springframework.beans.factory.annotation.Autowired; | |
14 | import org.springframework.security.access.AccessDeniedException; | |
15 | import org.springframework.security.access.prepost.PreAuthorize; | |
16 | import org.springframework.web.bind.annotation.PostMapping; | |
17 | import org.springframework.web.bind.annotation.RequestMapping; | |
18 | import org.springframework.web.bind.annotation.RequestParam; | |
19 | import org.springframework.web.bind.annotation.RestController; | |
20 | ||
21 | import java.util.Optional; | |
22 | ||
23 | ||
24 | @Tag(name = "Repository Controller") | |
25 | @RestController | |
26 | @RequestMapping("/api/repos") | |
27 | public class RepositoryController extends ApiController { | |
28 | ||
29 | @Autowired | |
30 | RepositoryService repositoryService; | |
31 | ||
32 | @Autowired | |
33 | JobService jobService; | |
34 | ||
35 | @Autowired | |
36 | CourseRepository courseRepository; | |
37 | ||
38 | ||
39 | /** | |
40 | * Fires a job that creates a repo for every RosterStudent with a linked user with a GitHub account. | |
41 | * @param courseId ID of course to create repos for | |
42 | * @param repoPrefix each repo created will begin with this prefix, followed by a dash and the student's GitHub username | |
43 | * @param isPrivate determines whether the repository being created is private | |
44 | * | |
45 | * @return the {@link edu.ucsb.cs156.frontiers.entities.Job Job} started to create the repos. | |
46 | */ | |
47 | @PostMapping("/createRepos") | |
48 | @PreAuthorize("hasRole('ROLE_PROFESSOR')") | |
49 | public Job createRepos(@RequestParam Long courseId, @RequestParam String repoPrefix, @RequestParam Optional<Boolean> isPrivate) { | |
50 |
1
1. lambda$createRepos$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RepositoryController::lambda$createRepos$0 → KILLED |
Course course = courseRepository.findById(courseId).orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
51 |
1
1. createRepos : negated conditional → KILLED |
if (getCurrentUser().getUser().getId() == course.getCreator().getId()) { |
52 |
2
1. createRepos : negated conditional → KILLED 2. createRepos : negated conditional → KILLED |
if (course.getOrgName() == null || course.getInstallationId() == null) { |
53 | throw new NoLinkedOrganizationException(course.getCourseName()); | |
54 | } else { | |
55 | CreateStudentRepositoriesJob job = CreateStudentRepositoriesJob.builder() | |
56 | .repositoryPrefix(repoPrefix) | |
57 | .isPrivate(isPrivate.orElse(false)) | |
58 | .repositoryService(repositoryService) | |
59 | .course(course) | |
60 | .build(); | |
61 |
1
1. createRepos : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RepositoryController::createRepos → KILLED |
return jobService.runAsJob(job); |
62 | } | |
63 | } else { | |
64 | throw new AccessDeniedException("You do not have permission to create student repositories on this course"); | |
65 | } | |
66 | } | |
67 | } | |
Mutations | ||
50 |
1.1 |
|
51 |
1.1 |
|
52 |
1.1 2.2 |
|
61 |
1.1 |