| 
						
					 | 
				
			
			 | 
			 | 
			
				@ -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<ArrayList<ExemptionsRequest>> 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<ExemptionsRequest> toReturn = new ArrayList<>();
 | 
			
		
		
	
	
		
			
				
					
					| 
						
					 | 
				
			
			 | 
			 | 
			
				@ -90,7 +93,7 @@ public class RequestsController {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    @GetMapping(value = "/exemptionsreq/{id}")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    public ResponseEntity<ExemptionsRequest> 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<String> 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<String> editScholReq(@RequestBody Map<String,Object> infos){
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    public ResponseEntity<String> editScholReq(@RequestHeader("Authorization") String token, @RequestBody Map<String,Object> 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<ScholarshipRequest> getScholReqbyId(@PathVariable long id){
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    public ResponseEntity<ScholarshipRequest> 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<ArrayList<UnregisterRequest>> getAllUnregReq(){
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    public ResponseEntity<ArrayList<UnregisterRequest>> getAllUnregReq(@RequestHeader("Authorization") String token){
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            return new UnauthorizedResponse<>(null);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        ArrayList<UnregisterRequest> toReturn = new ArrayList<>();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        unregisterRequestRepository.findAll().forEach(toReturn::add);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return new ResponseEntity<>(toReturn, HttpStatus.OK);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    @GetMapping(value = "/unregister/{id}")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    public ResponseEntity<UnregisterRequest> getUnregbyId(@PathVariable long id){
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    public ResponseEntity<UnregisterRequest> 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<String> pathUnregReq(@PathVariable long id, @PathVariable RequestState newstate){
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    public ResponseEntity<String> 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<UserCurriculum> 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<ArrayList <ChangeCurriculumRequest>> 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<ChangeCurriculumRequest> toReturn = new ArrayList<>();
 | 
			
		
		
	
	
		
			
				
					
					| 
						
					 | 
				
			
			 | 
			 | 
			
				@ -248,7 +280,7 @@ public class RequestsController {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    @GetMapping("/changecurriculumreq/{id}")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    public ResponseEntity<ChangeCurriculumRequest> 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<String> 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<String> 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);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
	
		
			
				
					
					| 
						
					 | 
				
			
			 | 
			 | 
			
				@ -311,8 +351,16 @@ public class RequestsController {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    @GetMapping("/exemptionreq/{userId}")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    public ResponseEntity<ArrayList<ExemptionsRequest>> getExReqByuser(@PathVariable long userId){
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    public ResponseEntity<ArrayList<ExemptionsRequest>> 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);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return new ResponseEntity<>(HttpStatus.OK);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        ArrayList<ExemptionsRequest> exList = err.findByUser(u);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return new ResponseEntity<>(exList, HttpStatus.OK);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
	
		
			
				
					
					| 
						 
							
							
							
						 
					 | 
				
			
			 | 
			 | 
			
				
 
 |