Skip to content
Snippets Groups Projects

Add a redirect to the course enroll page for labs

2 files
+ 16
15
Compare changes
  • Side-by-side
  • Inline

Files

@@ -507,7 +507,7 @@ public class LabController {
/**
* Processes a GET request asking for the CSV file representing the list of requests from the current lab.
* This CSV file is created and sent to the requestor through a ResponseEntity.
*
* <p>
* Headers are added to the response entity to indicate that the attached resource should be downloaded
* and the user should not be redirected to a new page. Additionally, we indicate a name for the file.
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
@@ -546,12 +546,14 @@ public class LabController {
@ExceptionHandler(AccessDeniedException.class)
public String notInLab(@AuthenticatedUser User user, HttpServletRequest request,
Exception e) {
Pattern testPattern = Pattern.compile("/lab/([0-9]+)/*");
Pattern testPattern = Pattern.compile("/lab/([0-9]+)[/]?.*");
Matcher matcher = testPattern.matcher(request.getRequestURI());
if (matcher.matches() && matcher.groupCount() == 1) {
Course course = labRepository.findById(Long.parseLong(matcher.group(1))).orElseThrow()
.getCourse();
return "redirect:/course/" + course.getId() + "/enroll";
Long labId = Long.parseLong(matcher.group(1));
return labRepository.findById(labId)
.map(lab -> "redirect:/course/" + lab.getCourse().getId() + "/enroll")
.orElse("redirect:/error/404");
}
logger.error("Access Denied: (User: {}, page: {})", user.getDisplayName(), request.getRequestURI());
Loading