From 17ab2412508fb7da0ca5e2a92d0682571b2797a8 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sat, 16 Mar 2024 16:57:52 +0100 Subject: [PATCH 1/3] show map by role --- .../EndPoints/ApplicationsController.java | 10 ++- frontend/src/App.vue | 62 ++++--------------- frontend/src/rest/apps.js | 55 +++++++++++++++- frontend/src/rest/restConsumer.js | 1 - 4 files changed, 75 insertions(+), 53 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 1629baa..77b2f3e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/ApplicationsController.java @@ -2,6 +2,7 @@ package ovh.herisson.Clyde.EndPoints; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; @@ -9,10 +10,12 @@ import org.springframework.web.bind.annotation.RestController; import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Tables.Applications; import ovh.herisson.Clyde.Tables.Role; +import ovh.herisson.Clyde.Tables.User; import java.util.ArrayList; @RestController +@CrossOrigin(originPatterns = "*", allowCredentials = "true") public class ApplicationsController { AuthenticatorService authServ; @@ -41,12 +44,17 @@ public class ApplicationsController { } public ArrayList getAuthorizedApplications(String token){ - Role posterRole = authServ.getUserFromToken(token).getRole(); ArrayList authorizedApps = new ArrayList<>(); authorizedApps.add(Applications.Login); authorizedApps.add(Applications.Profile); + User user = authServ.getUserFromToken(token); + if(user == null) + return authorizedApps; + + Role posterRole = user.getRole(); + if (posterRole == Role.Teacher || posterRole == Role.Student || posterRole == Role.Admin){ authorizedApps.add(Applications.Msg); authorizedApps.add(Applications.Forum); diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 1163b03..030c38d 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,32 +1,10 @@