From e303048f7ea2250c7d8ba11b58dc946595ccb1a4 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Wed, 17 Apr 2024 13:32:46 +0200 Subject: [PATCH] backend add ManageResearcherProfile --- .../Clyde/EndPoints/ApplicationsController.java | 11 +++++++++-- .../ScientificPublications/ResearcherController.java | 10 ++++++++++ .../java/ovh/herisson/Clyde/Tables/Applications.java | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java index f99fd60..5b49c66 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java @@ -1,5 +1,6 @@ package ovh.herisson.Clyde.EndPoints; +import lombok.AllArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.CrossOrigin; @@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RestController; import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService; import ovh.herisson.Clyde.Tables.Applications; import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.User; @@ -20,7 +22,10 @@ public class ApplicationsController { AuthenticatorService authServ; - public ApplicationsController(AuthenticatorService authServ){ + ResearchesService researchesServ; + + public ApplicationsController(AuthenticatorService authServ, ResearchesService researchesServ){ + this.researchesServ = researchesServ; this.authServ = authServ; } @@ -47,7 +52,6 @@ public class ApplicationsController { //if unAuthed authorizedApps.add(Applications.Login); - authorizedApps.add(Applications.ResearcherProfile); User user = authServ.getUserFromToken(token); if(user == null) @@ -71,6 +75,9 @@ public class ApplicationsController { if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)){ authorizedApps.add(Applications.UsersList);} + + if (researchesServ.getResearcherByUser(user) != null) + authorizedApps.add(Applications.ManageResearcherProfile); return authorizedApps; } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearcherController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearcherController.java index d052686..a0f3eeb 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearcherController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ScientificPublications/ResearcherController.java @@ -50,6 +50,16 @@ public class ResearcherController { return new ResponseEntity<>(toReturnResearchersDTO, HttpStatus.OK); } + @GetMapping("/researcher") + public ResponseEntity getSelf(@RequestHeader("Authorization") String token){ + + Researcher self = researchesServ.getResearcherByUser(authServ.getUserFromToken(token)); + + if (self ==null) return new UnauthorizedResponse<>(null); + + return new ResponseEntity<>(ResearcherDTO.construct(self), HttpStatus.OK); + } + @PostMapping("/researcher") public ResponseEntity postResearcher(@RequestHeader("Authorization") String token, @RequestBody Researcher researcher){ if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary}, token)){ diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java index 27c299e..a47997f 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Applications.java @@ -7,7 +7,6 @@ public enum Applications { // with any token Profile, - // Students and higher authorization Msg, Forum, @@ -21,5 +20,6 @@ public enum Applications { Requests, // profile of a researcher ResearcherProfile, + ManageResearcherProfile, StudentsList }