Package edu.ucsb.cs.scaffold.controller
Class CoursesController
java.lang.Object
edu.ucsb.cs.scaffold.controller.ApiController
edu.ucsb.cs.scaffold.controller.CoursesController
@RequestMapping("/api/courses")
@RestController
public class CoursesController
extends ApiController
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordDTO representing a course along with the ways in which the current user has access to it.static enumstatic enumstatic final recordProjection of Course entity with fields that are relevant for instructors and adminsstatic final recordstatic final record -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThis method returns a list of courses.This method returns a list of courses.deleteCourse(Long courseId) getCourseAccessInfo(Long courseId) This method returns the unified access info for a single course, if the current user has access to it.getCourseById(Long id) This method returns single course by its idgetCourseCanvasInfo(Long courseId) This method returns the Canvas course ID and partially obscured Canvas token for a course by its id.getCourseEmails(Long courseId, CoursesController.EmailTypes type, CoursesController.EmailFormats format) This method returns a list of courses that the current user is enrolled.This method returns a unified list of courses that the current user has access to, whether as a student, staff member, instructor, or admin.postCourse(String courseName, String term, School school, String canvasApiToken, String canvasCourseId) This method creates a new Course.student see what courses they appear as staff inupdateCourse(Long courseId, String courseName, String term, School school) This method updates an existing course.updateCourseWithCanvasToken(Long courseId, String canvasApiToken, String canvasCourseId) This method updates an existing course.updateGithubRepo(Long courseId, String repoName) Associates a GitHub repo (PlRepo) with a course, after verifying that the current user's stored GitHub PAT has read/write access to the repo.updateInstructorEmail(Long courseId, String instructorEmail) updatePLInstance(Long courseId, Long instanceId) Associates a PrairieLearn course instance (PlInstance) with a course.Methods inherited from class edu.ucsb.cs.scaffold.controller.ApiController
genericMessage, getCurrentUser, handleEntityNotFoundException, handleForbiddenException, handleIllegalArgument, handleUnsupportedOperation
-
Constructor Details
-
CoursesController
public CoursesController()
-
-
Method Details
-
postCourse
@PreAuthorize("hasRole(\'ROLE_ADMIN\') || hasRole(\'ROLE_INSTRUCTOR\')") @PostMapping("/post") public CoursesController.InstructorCourseView postCourse(@RequestParam String courseName, @RequestParam String term, @RequestParam School school, @RequestParam(required=false) String canvasApiToken, @RequestParam(required=false) String canvasCourseId) This method creates a new Course.- Parameters:
courseName- the name of the courseterm- the term of the courseschool- the school of the coursecanvasApiToken- the Canvas API token (optional)canvasCourseId- the Canvas course ID (optional)
-
allForInstructors
@PreAuthorize("hasRole(\'ROLE_INSTRUCTOR\')") @GetMapping("/list/instructors") public Iterable<CoursesController.InstructorCourseView> allForInstructors()This method returns a list of courses.- Returns:
- a list of all courses for an instructor.
-
allForAdmins
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @GetMapping("/list/admins") public Iterable<CoursesController.InstructorCourseView> allForAdmins()This method returns a list of courses.- Returns:
- a list of all courses for an admin.
-
getCourseById
@PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #id)") @GetMapping("/{id}") public CoursesController.InstructorCourseView getCourseById(@PathVariable Long id) This method returns single course by its id- Returns:
- a course
-
getCourseCanvasInfo
@PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @GetMapping("getCanvasInfo") public Map<String,String> getCourseCanvasInfo(@RequestParam Long courseId) This method returns the Canvas course ID and partially obscured Canvas token for a course by its id. If the token is less than or equal to 3 characters long, it is returned in full. Otherwise, all but the last three characters are replaced with asterisks. This is okay because such short tokens are not generated by Canvas.- Parameters:
courseId- the id of the course- Returns:
- a map with courseId, canvasCourseId, and obscured canvasApiToken
-
listCoursesForCurrentUser
@PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/list/students") public List<CoursesController.RosterStudentCoursesDTO> listCoursesForCurrentUser()This method returns a list of courses that the current user is enrolled.- Returns:
- a list of courses in the DTO form along with the student status in the organization.
-
staffCourses
@PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/list/staff") public List<CoursesController.StaffCoursesDTO> staffCourses()student see what courses they appear as staff in- Parameters:
studentId- the id of the student making request- Returns:
- a list of all courses student is staff in
-
listCoursesForCurrentUserUnified
@PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/list") public List<CoursesController.CourseListDTO> listCoursesForCurrentUserUnified()This method returns a unified list of courses that the current user has access to, whether as a student, staff member, instructor, or admin.- Returns:
- a list of courses along with the access flags for the current user.
-
getCourseAccessInfo
@PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/list/{courseId}") public CoursesController.CourseListDTO getCourseAccessInfo(@PathVariable Long courseId) This method returns the unified access info for a single course, if the current user has access to it. If the user does not have access, or the course does not exist, a 404 is returned.- Parameters:
courseId- the id of the course- Returns:
- the course along with the access flags for the current user.
-
updateInstructorEmail
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PutMapping("/updateInstructor") public CoursesController.InstructorCourseView updateInstructorEmail(@RequestParam Long courseId, @RequestParam String instructorEmail) -
getCourseEmails
@PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @GetMapping("/emails") public String getCourseEmails(@RequestParam Long courseId, @RequestParam(defaultValue="STUDENTS") CoursesController.EmailTypes type, @RequestParam(defaultValue="ONE_PER_LINE") CoursesController.EmailFormats format) -
deleteCourse
@PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @DeleteMapping("") @Transactional public Object deleteCourse(@RequestParam Long courseId) throws NoSuchAlgorithmException, InvalidKeySpecException -
updateCourse
@PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @PutMapping("") public CoursesController.InstructorCourseView updateCourse(@RequestParam Long courseId, @RequestParam String courseName, @RequestParam String term, @RequestParam School school) This method updates an existing course.- Parameters:
courseId- the id of the course to updatecourseName- the new name of the courseterm- the new term of the courseschool- the new school of the course- Returns:
- the updated course
-
updateCourseWithCanvasToken
@PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @PutMapping("/updateCourseCanvasToken") public CoursesController.InstructorCourseView updateCourseWithCanvasToken(@RequestParam Long courseId, @RequestParam(required=false) String canvasApiToken, @RequestParam(required=false) String canvasCourseId) This method updates an existing course.- Parameters:
courseId- the id of the course to updatecanvasApiToken- the new Canvas API token for the coursecanvasCourseId- the new Canvas course IDcourseName- the new name of the courseterm- the new term of the courseschool- the new school of the course- Returns:
- the updated course
-
updateGithubRepo
@PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @PutMapping("/updateGithubRepo") public CoursesController.InstructorCourseView updateGithubRepo(@RequestParam Long courseId, @RequestParam String repoName) Associates a GitHub repo (PlRepo) with a course, after verifying that the current user's stored GitHub PAT has read/write access to the repo. The check is a single GET /repos/{owner}/{repo} call: a successful response proves read access and its permissions block reports push (write) access, so nothing is written to the repo.- Parameters:
courseId- the id of the courserepoName- the repo in owner/repo form (i.e. the part after https://github.com/)- Returns:
- the updated course
-
updatePLInstance
@PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @PutMapping("/updatePLInstance") public CoursesController.InstructorCourseView updatePLInstance(@RequestParam Long courseId, @RequestParam Long instanceId) Associates a PrairieLearn course instance (PlInstance) with a course. The numeric instance id is verified in two steps: it is fetched from the PrairieLearn API using the caller's PrairieLearn PAT, and the course's GitHub repo must contain a matching courseInstances/{shortName}/infoCourseInstance.json whose longName agrees. Only the PrairieLearn API can supply the numeric id, and only the repo check proves the instance belongs to this course's repo.- Parameters:
courseId- the id of the courseinstanceId- PrairieLearn's numeric course instance id- Returns:
- the updated course
-