[Admin Tools | Trunk]: Add again role Utils. Fix curator methods

This commit is contained in:
Konstantinos Triantafyllou 2021-02-26 10:14:16 +00:00
parent 6484343d2f
commit af53843d1c
3 changed files with 21 additions and 13 deletions

View File

@ -80,11 +80,11 @@
<artifactId>uoa-admin-tools-library</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<!--<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-authorization-library</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependency>-->
</dependencies>
<build>

View File

@ -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<String> portals) {
List<String> roles = authorizationService.getRoles();
List<String> roles = rolesUtils.getRoles();
for (String id: portals) {
Portal portal = portalService.getPortalById(id);

View File

@ -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("@"));
}
}