diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/InscriptionController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/InscriptionController.java index 60f4585..eb283e8 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/InscriptionController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/InscriptionController.java @@ -29,7 +29,7 @@ public class InscriptionController { @GetMapping("/requests/register") public ResponseEntity>> getAllRequests(@RequestHeader("Authorization") String token){ - if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token)) + if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token)) return new UnauthorizedResponse<>(null); Iterable inscriptionRequests = inscriptionServ.getAll(); @@ -41,7 +41,7 @@ public class InscriptionController { @GetMapping("/request/register/{id}") public ResponseEntity> getById(@RequestHeader("Authorization") String token, @PathVariable long id){ - if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token)) + if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token)) return new UnauthorizedResponse<>(null); InscriptionRequest foundInscriptionRequest = inscriptionServ.getById(id); @@ -87,6 +87,12 @@ public class InscriptionController { return new UnauthorizedResponse<>(null); InscriptionRequest toEdit = inscriptionServ.getById(id); + + //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below) + if (toEdit.getEquivalenceState() == RequestState.Accepted){ + return new ResponseEntity<>(HttpStatus.OK); + } + toEdit.setEquivalenceState(newstate); inscriptionServ.save(toEdit); diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java index 74d1bf0..b21a6ca 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java @@ -13,6 +13,7 @@ import ovh.herisson.Clyde.Repositories.UserCurriculumRepository; import ovh.herisson.Clyde.Repositories.UserRepository; import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Services.TokenService; import ovh.herisson.Clyde.Services.UserService; import ovh.herisson.Clyde.Tables.*; import ovh.herisson.Clyde.Tables.Inscription.ExemptionsRequest; @@ -28,6 +29,7 @@ import java.util.Map; @CrossOrigin(originPatterns = "*", allowCredentials = "true") public class RequestsController { + public final TokenService tokenService; public final ExemptionsRequestRepository err; public final ScholarshipRequestRepository srr; public final UserRepository userRepository; @@ -40,7 +42,8 @@ public class RequestsController { public final ChangeCurriculumRequestRepository changeCurriculumRequestRepository; - public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UnregisterRequestRepository unregisterRequestRepository, CourseRepository courseRepository, UserService userService, UserCurriculumRepository userCurriculumRepository, CurriculumRepository curriculumRepository, ChangeCurriculumRequestRepository changeCurriculumRequestRepository) { + public RequestsController(TokenService tokenService, ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UnregisterRequestRepository unregisterRequestRepository, CourseRepository courseRepository, UserService userService, UserCurriculumRepository userCurriculumRepository, CurriculumRepository curriculumRepository, ChangeCurriculumRequestRepository changeCurriculumRequestRepository) { + this.tokenService = tokenService; this.err = err; this.srr = srr; this.userRepository = userRepository; @@ -78,7 +81,7 @@ public class RequestsController { //Get all the exemptions Request @GetMapping(value = "/exemptionsreq") public ResponseEntity> getAllExemptionsRequests(@RequestHeader("Authorization") String token){ - if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token)) return new UnauthorizedResponse<>(null); ArrayList toReturn = new ArrayList<>(); @@ -90,7 +93,7 @@ public class RequestsController { @GetMapping(value = "/exemptionsreq/{id}") public ResponseEntity getExemptionRequestbyId(@RequestHeader("Authorization") String token, @PathVariable long id){ - if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher,Role.InscriptionService},token)) return new UnauthorizedResponse<>(null); ExemptionsRequest exemptionsRequest = err.findById(id); @@ -100,10 +103,15 @@ public class RequestsController { @PatchMapping(value = "/exemptionsreq/{id}/{newstate}") public ResponseEntity changeExemptionReqState(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newstate){ - if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token)) return new UnauthorizedResponse<>(null); ExemptionsRequest exemptionsRequest = err.findById(id); + + if (exemptionsRequest.getState() == RequestState.Accepted){ + return new ResponseEntity<>(HttpStatus.OK); + } + exemptionsRequest.setState(newstate); err.save(exemptionsRequest); @@ -140,9 +148,17 @@ public class RequestsController { } @PatchMapping(value = "/scholarshipreq/") - public ResponseEntity editScholReq(@RequestBody Map infos){ + public ResponseEntity editScholReq(@RequestHeader("Authorization") String token, @RequestBody Map infos){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + ScholarshipRequest scholarshipRequest = srr.findById((Integer) infos.get("id")); + //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below) + if (scholarshipRequest.getState() == RequestState.Accepted){ + return new ResponseEntity<>(HttpStatus.OK); + } + if (infos.get("state").equals("Accepted")){ scholarshipRequest.setState(RequestState.Accepted); scholarshipRequest.setAmount((int) infos.get("amount")); @@ -155,30 +171,48 @@ public class RequestsController { } @GetMapping(value = "/scholarshipreq/{id}") - public ResponseEntity getScholReqbyId(@PathVariable long id){ + public ResponseEntity getScholReqbyId(@RequestHeader("Authorization") String token, @PathVariable long id){ + if (authServ.isNotIn(new Role[]{Role.Admin, Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + ScholarshipRequest toReturn = srr.findById(id); return new ResponseEntity<>(toReturn, HttpStatus.OK); } @GetMapping(value = "/unregister") - public ResponseEntity> getAllUnregReq(){ + public ResponseEntity> getAllUnregReq(@RequestHeader("Authorization") String token){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + ArrayList toReturn = new ArrayList<>(); unregisterRequestRepository.findAll().forEach(toReturn::add); return new ResponseEntity<>(toReturn, HttpStatus.OK); } @GetMapping(value = "/unregister/{id}") - public ResponseEntity getUnregbyId(@PathVariable long id){ + public ResponseEntity getUnregbyId(@RequestHeader("Authorization") String token, @PathVariable long id){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + UnregisterRequest unregisterRequest = unregisterRequestRepository.findById(id); return new ResponseEntity<>(unregisterRequest, HttpStatus.OK); } @PatchMapping(value = "/unregister/{id}/{newstate}") - public ResponseEntity pathUnregReq(@PathVariable long id, @PathVariable RequestState newstate){ + public ResponseEntity pathUnregReq(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newstate){ + if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + UnregisterRequest unregisterRequest = unregisterRequestRepository.findById(id); User u = userRepository.findById(unregisterRequest.getRegNo()); - unregisterRequest.setState(newstate); + //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below) + if (unregisterRequest.getState() == RequestState.Accepted){ + return new ResponseEntity<>(HttpStatus.OK); + } + + unregisterRequest.setState(newstate); + unregisterRequestRepository.save(unregisterRequest); if (newstate == RequestState.Accepted){ if (unregisterRequest.getCurriculum() == null){ ArrayList userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u); @@ -193,8 +227,6 @@ public class RequestsController { userCurriculumRepository.save(userCurriculum); } } - - unregisterRequestRepository.save(unregisterRequest); return new ResponseEntity<>(HttpStatus.OK); } @@ -236,7 +268,7 @@ public class RequestsController { @GetMapping("/changecurriculumreq") public ResponseEntity> getAllChangeCurrReq(@RequestHeader("Authorization") String token){ - if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token)) return new UnauthorizedResponse<>(null); ArrayList toReturn = new ArrayList<>(); @@ -248,7 +280,7 @@ public class RequestsController { @GetMapping("/changecurriculumreq/{id}") public ResponseEntity getCCrbyId(@RequestHeader("Authorization") String token, @PathVariable long id){ - if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher,Role.InscriptionService},token)) return new UnauthorizedResponse<>(null); ChangeCurriculumRequest toReturn = changeCurriculumRequestRepository.findById(id); @@ -257,37 +289,45 @@ public class RequestsController { @PatchMapping("/changecurriculumreq/{id}/{newState}") public ResponseEntity editCCReq(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newState){ - if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token)) return new UnauthorizedResponse<>(null); ChangeCurriculumRequest toEdit = changeCurriculumRequestRepository.findById(id); - toEdit.setState(newState); + //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below) + if (toEdit.getState() == RequestState.Accepted){ + return new ResponseEntity<>(HttpStatus.OK); + } + toEdit.setState(newState); + changeCurriculumRequestRepository.save(toEdit); if (newState == RequestState.Accepted && (toEdit.getTeacherApprovalState() == RequestState.Accepted || toEdit.getTeacherApprovalState() == RequestState.Unrequired)){ //If actual curriculum is not null then we need to set that the user doesn't follow it anymore acceptProcedure(toEdit); } - changeCurriculumRequestRepository.save(toEdit); return new ResponseEntity<>(HttpStatus.OK); } @PatchMapping("/changecurriculumreqteacher/{id}/{newteacherstate}") public ResponseEntity editCCReqTeacherState(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newteacherstate){ - if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token)) return new UnauthorizedResponse<>(null); ChangeCurriculumRequest toEdit = changeCurriculumRequestRepository.findById(id); + //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below) + if (toEdit.getTeacherApprovalState() == RequestState.Accepted){ + return new ResponseEntity<>(HttpStatus.OK); + } + toEdit.setState(newteacherstate); + changeCurriculumRequestRepository.save(toEdit); if (newteacherstate == RequestState.Accepted && toEdit.getState() == RequestState.Accepted){ //If actual curriculum is not null then we need to set that the user doesn't follow it anymore acceptProcedure(toEdit); } - - changeCurriculumRequestRepository.save(toEdit); return new ResponseEntity<>(HttpStatus.OK); } @@ -309,4 +349,18 @@ public class RequestsController { UserCurriculum userCurriculum = new UserCurriculum(u, toEdit.getDestinationCurriculum(), c.get(Calendar.YEAR), true); userCurriculumRepository.save(userCurriculum); } + + @GetMapping("/exemptionreq/{userId}") + public ResponseEntity> getExReqByuser(@RequestHeader("Authorization") String token, @PathVariable long userId){ + User currentUser = tokenService.getUserFromToken(token); + + //Only admin, teacher, secretary and the student himself can access a student's data here + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher, Role.Secretary},token) && currentUser.getRegNo() != userId) + return new UnauthorizedResponse<>(null); + + User u = userRepository.findById(userId); + + ArrayList exList = err.findByUser(u); + return new ResponseEntity<>(exList, HttpStatus.OK); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index d9320a9..ee215c9 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -109,7 +109,7 @@ public class MockController { ucr.save(new UserCurriculum(popo, infoBab2, 2023, true)); Course progra1 = new Course(5,"Programmation et algorithmique 1",joke); - Course chemistry1 = new Course(12, "Thermochimie",joke); + Course chemistry1 = new Course(12, "Thermochimie",jojo); Course psycho1 = new Course(21, "Neuroreaction of isolated brain cells",joke); Course commun = new Course(2, "cours commun",joke); @@ -126,7 +126,7 @@ public class MockController { CurriculumCourseService.save(new CurriculumCourse(infoBab1, psycho1)); CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,psycho1)); CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,commun)); - + CurriculumCourseService.save(new CurriculumCourse(chemistryBab1, chemistry1)); CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,commun)); CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,chemistry1)); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ExemptionsRequestRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ExemptionsRequestRepository.java index d644ef1..7682d11 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ExemptionsRequestRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ExemptionsRequestRepository.java @@ -2,7 +2,12 @@ package ovh.herisson.Clyde.Repositories.Inscription; import org.springframework.data.repository.CrudRepository; import ovh.herisson.Clyde.Tables.Inscription.ExemptionsRequest; +import ovh.herisson.Clyde.Tables.User; + +import java.util.ArrayList; public interface ExemptionsRequestRepository extends CrudRepository { ExemptionsRequest findById(long id); + + ArrayList findByUser(User user); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java index 208471d..534fb88 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java @@ -59,6 +59,11 @@ public class InscriptionService { if (inscrRequest == null) return false; + //If the request is already accepted we just return ok (otherwise we would duplicate the procedure below) + if (inscrRequest.getState() == RequestState.Accepted){ + return true; + } + inscrRequest.setState(requestState); save(inscrRequest); diff --git a/frontend/src/Apps/Inscription/AboutChangeCurriculum.vue b/frontend/src/Apps/Inscription/AboutChangeCurriculum.vue index 9a3f40d..98adc3d 100644 --- a/frontend/src/Apps/Inscription/AboutChangeCurriculum.vue +++ b/frontend/src/Apps/Inscription/AboutChangeCurriculum.vue @@ -66,12 +66,12 @@ async function editChangeCurrReqTeacherApproval(state){ -
+
- +
@@ -125,4 +125,12 @@ async function editChangeCurrReqTeacherApproval(state){ background-color:rgb(50,50,50); border-radius:20px; } + +button{ + border:none; + background-color:rgb(239, 60, 168); + border-radius:10px; + height:35px; + margin-top:10px; +} \ No newline at end of file diff --git a/frontend/src/Apps/Inscription/AboutExemption.vue b/frontend/src/Apps/Inscription/AboutExemption.vue index 366c32a..6fef834 100644 --- a/frontend/src/Apps/Inscription/AboutExemption.vue +++ b/frontend/src/Apps/Inscription/AboutExemption.vue @@ -56,10 +56,10 @@ async function editExemp(newstate){
- +
- +
@@ -113,4 +113,12 @@ async function editExemp(newstate){ background-color:rgb(50,50,50); border-radius:20px; } + +button{ + border:none; + background-color:rgb(239, 60, 168); + border-radius:10px; + height:35px; + margin-top:10px; +} \ No newline at end of file diff --git a/frontend/src/Apps/Inscription/AboutRequest.vue b/frontend/src/Apps/Inscription/AboutRequest.vue index c6d15df..efe401b 100644 --- a/frontend/src/Apps/Inscription/AboutRequest.vue +++ b/frontend/src/Apps/Inscription/AboutRequest.vue @@ -31,7 +31,7 @@ async function editEquivalence(id, newstate){