From af53843d1c657e357d612c885466dc13386f03c0 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 26 Feb 2021 10:14:16 +0000 Subject: [PATCH] [Admin Tools | Trunk]: Add again role Utils. Fix curator methods --- pom.xml | 4 +-- .../controllers/CommunityController.java | 5 ++-- .../controllers/CuratorController.java | 25 ++++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index f1313a6..86219d8 100644 --- a/pom.xml +++ b/pom.xml @@ -80,11 +80,11 @@ uoa-admin-tools-library 1.0.0-SNAPSHOT - + diff --git a/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java b/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java index d66450b..bbc2b7f 100644 --- a/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java +++ b/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java @@ -9,6 +9,7 @@ import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; import eu.dnetlib.uoaadmintoolslibrary.entities.fullEntities.PortalResponse; import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; import eu.dnetlib.uoaadmintoolslibrary.handlers.MismatchingContentException; +import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; import eu.dnetlib.uoaadmintoolslibrary.services.PortalService; import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService; import org.apache.log4j.Logger; @@ -25,7 +26,7 @@ public class CommunityController { private final Logger log = Logger.getLogger(this.getClass()); @Autowired - private AuthorizationService authorizationService; + private RolesUtils rolesUtils; @Autowired private LayoutService layoutService; @@ -95,7 +96,7 @@ public class CommunityController { @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") @RequestMapping(value = "/delete", method = RequestMethod.POST) public Boolean deleteCommunities(@RequestBody List portals) { - List roles = authorizationService.getRoles(); + List roles = rolesUtils.getRoles(); for (String id: portals) { Portal portal = portalService.getPortalById(id); diff --git a/src/main/java/eu/dnetlib/uoaadmintools/controllers/CuratorController.java b/src/main/java/eu/dnetlib/uoaadmintools/controllers/CuratorController.java index 98f2121..6a46990 100644 --- a/src/main/java/eu/dnetlib/uoaadmintools/controllers/CuratorController.java +++ b/src/main/java/eu/dnetlib/uoaadmintools/controllers/CuratorController.java @@ -3,7 +3,8 @@ package eu.dnetlib.uoaadmintools.controllers; import eu.dnetlib.uoaadmintools.entities.curator.Curator; import eu.dnetlib.uoaadmintools.entities.curator.CuratorResponse; import eu.dnetlib.uoaadmintools.services.CuratorService; -import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService; +import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; +import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; @@ -20,7 +21,7 @@ public class CuratorController { private CuratorService curatorService; @Autowired - private AuthorizationService authorizationService; + private RolesUtils rolesUtils; /** * Return a list with curator for a specific community @@ -34,15 +35,18 @@ public class CuratorController { } /** - * Return a Curator with the given id. + * Return Curator info of logged in user. * - * @param id * @return */ @PreAuthorize("isAuthenticated()") - @RequestMapping(value = "/curator/{id}", method = RequestMethod.GET) - public Curator getCuratorById(@PathVariable String id) { - return curatorService.findById(id); + @RequestMapping(value = "/curator", method = RequestMethod.GET) + public Curator getCuratorById() { + Curator curator = curatorService.findById(getId()); + if(curator != null) { + return curator; + } + throw new ContentNotFoundException("No curator found"); } /** @@ -54,8 +58,7 @@ public class CuratorController { @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/curator", method = RequestMethod.POST) public Curator insertCurator(@RequestBody Curator curator) { - String aaiId = authorizationService.getAaiId(); - curator.setId(aaiId.substring(0, aaiId.indexOf("@"))); + curator.setId(getId()); return curatorService.save(curator); } @@ -71,4 +74,8 @@ public class CuratorController { curatorService.deleteCurators(pid); } + private String getId() { + String aaiId = rolesUtils.getAaiId(); + return aaiId.substring(0, aaiId.indexOf("@")); + } }