Skip to content
Snippets Groups Projects

Add endpoint for checking whether a person is staff

Files

@@ -20,6 +20,8 @@ package nl.tudelft.labracore.controller;
import javax.transaction.Transactional;
import nl.tudelft.labracore.model.RoleType;
import nl.tudelft.labracore.repository.PersonRepository;
import nl.tudelft.labracore.repository.RoleRepository;
import nl.tudelft.labracore.security.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,6 +35,12 @@ public class AuthorizationController {
@Autowired
private AuthorizationService authService;
@Autowired
private PersonRepository pr;
@Autowired
private RoleRepository rr;
/**
* Checks whether a person already has a role in the edition.
*
@@ -41,7 +49,7 @@ public class AuthorizationController {
* @return true if the person already has a role in the edition
*/
@GetMapping("/{personId}/role/{editionId}/edition")
public Boolean hasRoleInEdition(@PathVariable Long personId, @PathVariable Long editionId) {
public boolean hasRoleInEdition(@PathVariable Long personId, @PathVariable Long editionId) {
return authService.hasRoleInEdition(personId, editionId);
}
@@ -54,7 +62,7 @@ public class AuthorizationController {
* @return true if the person already has a role in the edition
*/
@GetMapping("/{personId}/specific-role/{editionId}/edition")
public Boolean hasSpecificRoleInEdition(@PathVariable Long personId,
public boolean hasSpecificRoleInEdition(@PathVariable Long personId,
@PathVariable Long editionId,
@RequestParam RoleType type) {
return authService.hasSpecificRoleInEdition(personId, editionId, type);
@@ -68,10 +76,34 @@ public class AuthorizationController {
* @return true if the person is the manager of the course
*/
@GetMapping("/{personId}/course-manager/{courseId}")
public Boolean isCourseManager(@PathVariable Long personId, @PathVariable Long courseId) {
public boolean isCourseManager(@PathVariable Long personId, @PathVariable Long courseId) {
return authService.isCourseManager(personId, courseId);
}
/**
* Checks whether the given person has a staff role in the given course.
*
* @param personId The id of the person to lookup.
* @param courseId The id of the course to lookup.
* @return Whether the person has a staff role in the course.
*/
@GetMapping("/{personId}/staff-in-course/{courseId}")
public boolean isStaffInCourse(@PathVariable Long personId, @PathVariable Long courseId) {
return rr.existsStaffForPersonInCourse(personId, courseId);
}
/**
* Checks whether the given person has a staff role in the given edition.
*
* @param personId The id of the person to lookup.
* @param editionId The id of the edition to lookup.
* @return Whether the person has a staff role in the edition.
*/
@GetMapping("/{personId}/staff-in-edition/{editionId}")
public boolean isStaffInEdition(@PathVariable Long personId, @PathVariable Long editionId) {
return rr.existsStaffForPersonInEdition(personId, editionId);
}
/**
* Checks whether a person can read course information. They must either a the manager of the course or
* have the role of teacher(-RO) in any of the course editions.
@@ -81,8 +113,21 @@ public class AuthorizationController {
* @return true if the person can read the data of a course
*/
@GetMapping("/{personId}/course-read/{courseId}")
public Boolean canReadCourse(@PathVariable Long personId, @PathVariable Long courseId) {
public boolean canReadCourse(@PathVariable Long personId, @PathVariable Long courseId) {
return authService.canReadCourse(personId, courseId);
}
/**
* Checks whether the given person is a manager of any of the existing courses.
*
* @param personId The id of the person to lookup.
* @return Whether the given person has a manager role anywhere.
*/
@GetMapping("/{personId}/manager-anywhere")
public boolean isManagerForAnyCourse(@PathVariable Long personId) {
return pr.findById(personId)
.map(person -> !person.getManages().isEmpty())
.orElse(false);
}
}
Loading