Skip to content
Snippets Groups Projects

Draft: Resolve "Implement Authorization"

11 files
+ 269
56
Compare changes
  • Side-by-side
  • Inline

Files

package server.controller;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import nl.tudelft.labracore.api.dto.CourseSummaryDTO;
import nl.tudelft.labracore.api.dto.*;
import nl.tudelft.labracore.lib.security.user.AuthenticatedPerson;
import nl.tudelft.labracore.lib.security.user.Person;
@@ -12,6 +14,8 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import server.dto.create.GitbullEditionCreateDTO;
import server.security.AuthorisationService;
import server.service.*;
@@ -36,14 +40,53 @@ public class DashboardController {
// this is the new course service that talks to core and has caches
@Autowired
private CourseService courseService;
@Autowired
private CohortService cohortService;
/** Copied and modified from submit -> we want something similar for our dashboard,
* but instead of editions we want courses, Submit had editions.
* Returns the list of all courses the user is part of.
*
* @param person The authenticated person
* @param model The model to fill out for template resolution.
* @return The page to be loaded
*/
@GetMapping
public String getEnrolledEditions(@AuthenticatedPerson Person person,
@RequestParam(required = false) String q,
Model model) {
List<RoleEditionDetailsDTO> roles = editionService
.getEnrolledEditionsForPerson(new PersonIdDTO().id(person.getId()));
List<EditionDetailsDTO> editions = editionService
.getEditions(roles.stream().map(e -> e.getEdition().getId()).collect(Collectors.toList()));
Map<Long, CourseSummaryDTO> courses = editions.stream()
.collect(Collectors.toMap(EditionDetailsDTO::getId, EditionDetailsDTO::getCourse));
if (q != null) {
String filter = q.toLowerCase();
roles = roles.stream()
.filter(r -> r.getEdition().getName().toLowerCase().contains(filter)
|| courses.get(r.getEdition().getId()).getName().toLowerCase().contains(filter)
|| courses.get(r.getEdition().getId()).getCode().toLowerCase().contains(filter))
.collect(Collectors.toList());
}
model.addAttribute("roles", roles);
model.addAttribute("courses", courses);
model.addAttribute("create",
GitbullEditionCreateDTO.builder().cohort(new CohortIdDTO()).course(new CourseIdDTO()).build());
model.addAttribute("manages", courseService.getManagingCourses(person.getId()));
model.addAttribute("cohorts", cohortService.getAllCohorts());
return "dashboard";
}
/**
* GET endpoint to get the dashboard with the list of courses a user has access to.
*
* @return the dashboard page
*/
@GetMapping()
@GetMapping("/courses")
public String getCourses(Model model, @AuthenticatedPerson Person person) {
//Fetching all accesses
// List<Access> userAccesses = accessService.fetchAllAccessesOfAccount(netId);
@@ -52,8 +95,9 @@ public class DashboardController {
// List<Long> courseIds = userAccesses.stream().map(x -> x.getCourseEditionID())
// .collect(Collectors.toList());
// List<CourseEdition> courses = courseService.fetchAllCoursesOfListOfIds(courseIds);
List<CourseSummaryDTO> courses = courseService.getAllCoursesTAorHigher(person.getId());
// List<CourseSummaryDTO> courses = courseService.getAllCoursesTAorHigher(person.getId());
List<CourseSummaryDTO> courses = courseService.getAllCoursesTAorHigher(person.getId());
//Fetching all groups for user
// List<Long> groupIds = userAccesses.stream().map(x -> x.getGroupID()).collect(Collectors.toList());
// List<StudentGroup> groups = groupService.fetchAllGroupsFromId(groupIds);
@@ -82,7 +126,7 @@ public class DashboardController {
// res.add(uci);
// }
// TODO this will not work, courses from core are different than the ones in gitbull
// -> UPDATE: NO? why would you have a course in gitbull and not in CORE?
// -> UPDATE: added the GitbullCourseDetailsDTO to combine them
// need to create courses in gibull that point to one in core and have the extra attributes
model.addAttribute("courses", courses);
return "dashboard";
Loading