Add create group in member controller. Change curator create role to create a curator role only.
This commit is contained in:
parent
726300d2f3
commit
c5331d5934
|
@ -4,8 +4,8 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.JsonArray;
|
||||
import eu.dnetlib.dnetrolemanagement.entities.Response;
|
||||
import eu.dnetlib.dnetrolemanagement.entities.User;
|
||||
import eu.dnetlib.dnetrolemanagement.exception.UnprocessableException;
|
||||
import eu.dnetlib.dnetrolemanagement.exception.ResourceNotFoundException;
|
||||
import eu.dnetlib.dnetrolemanagement.exception.UnprocessableException;
|
||||
import eu.dnetlib.dnetrolemanagement.services.RegistryService;
|
||||
import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUpdater;
|
||||
import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUtils;
|
||||
|
|
|
@ -3,7 +3,6 @@ package eu.dnetlib.dnetrolemanagement.controllers;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import eu.dnetlib.dnetrolemanagement.entities.Response;
|
||||
import eu.dnetlib.dnetrolemanagement.entities.Role;
|
||||
import eu.dnetlib.dnetrolemanagement.entities.User;
|
||||
import eu.dnetlib.dnetrolemanagement.exception.ConflictException;
|
||||
import eu.dnetlib.dnetrolemanagement.exception.ResourceNotFoundException;
|
||||
|
@ -37,12 +36,12 @@ public class CuratorController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a new role (only for admins)
|
||||
* Create a new Curator role (only for admins)
|
||||
*/
|
||||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||
public ResponseEntity<Response> createRole(@RequestBody Role role) {
|
||||
if (registryService.getCouId(role.getName()) == null) {
|
||||
if (registryService.createRole(role.getName(), role.getDescription()) != null) {
|
||||
@RequestMapping(value = "/{type}/create", method = RequestMethod.POST)
|
||||
public ResponseEntity<Response> createRole(@PathVariable("type") String type, @RequestParam("description") String description) {
|
||||
if (registryService.getCouId(AuthoritiesUtils.curatorRole(type).toLowerCase()) == null) {
|
||||
if (registryService.createRole(AuthoritiesUtils.curatorRole(type), description != null ? description : "") != null) {
|
||||
return ResponseEntity.ok(new Response("Role has been created successfully"));
|
||||
} else {
|
||||
throw new UnprocessableException("Role creation failed. Try again later");
|
||||
|
@ -57,7 +56,7 @@ public class CuratorController {
|
|||
*/
|
||||
@RequestMapping(value = "/{type}", method = RequestMethod.GET)
|
||||
public ResponseEntity<User[]> getAll(@PathVariable("type") String type) {
|
||||
Integer couId = registryService.getCouId(AuthoritiesUtils.curatorRole(type));
|
||||
Integer couId = registryService.getCouId(AuthoritiesUtils.curatorRole(type).toLowerCase());
|
||||
if (couId != null) {
|
||||
JsonArray users = registryService.getUserIdByCouId(couId, false);
|
||||
JsonArray emails = registryService.getUserEmailByCouId(couId, false);
|
||||
|
|
|
@ -3,7 +3,6 @@ package eu.dnetlib.dnetrolemanagement.controllers;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import eu.dnetlib.dnetrolemanagement.entities.Response;
|
||||
import eu.dnetlib.dnetrolemanagement.entities.Role;
|
||||
import eu.dnetlib.dnetrolemanagement.entities.User;
|
||||
import eu.dnetlib.dnetrolemanagement.exception.ConflictException;
|
||||
import eu.dnetlib.dnetrolemanagement.exception.ResourceNotFoundException;
|
||||
|
@ -13,7 +12,6 @@ import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUpdater;
|
|||
import eu.dnetlib.dnetrolemanagement.utils.AuthoritiesUtils;
|
||||
import eu.dnetlib.dnetrolemanagement.utils.JsonUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -21,7 +19,6 @@ import org.springframework.web.bind.annotation.*;
|
|||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/member")
|
||||
|
@ -38,7 +35,22 @@ public class MemberController {
|
|||
this.gson = new Gson();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Group for an entity (only for admins)
|
||||
*/
|
||||
@RequestMapping(value = "/{type}/{id}/create", method = RequestMethod.POST)
|
||||
public ResponseEntity<Response> createGroup(@PathVariable("type") String type, @PathVariable("id") String id,
|
||||
@RequestParam("description") String description) {
|
||||
if (registryService.getCouId(AuthoritiesUtils.memberRole(type, id)) == null) {
|
||||
if (registryService.createRole(AuthoritiesUtils.memberRole(type, id), description != null ? description : "") != null) {
|
||||
return ResponseEntity.ok(new Response("Role has been created successfully"));
|
||||
} else {
|
||||
throw new UnprocessableException("Role creation failed. Try again later");
|
||||
}
|
||||
} else {
|
||||
throw new ConflictException("This role already exists");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user info of the members of a type(Community, etc.) with id(ee, egi, etc.)
|
||||
|
@ -65,7 +77,7 @@ public class MemberController {
|
|||
if (coPersonIds.size() > 0) {
|
||||
Integer temp = registryService.getCouId(AuthoritiesUtils.memberRole(type, id));
|
||||
if (temp != null || force) {
|
||||
Integer couId = (temp != null)?temp:registryService.createRole(AuthoritiesUtils.memberRole(type, id), "");
|
||||
Integer couId = (temp != null) ? temp : registryService.createRole(AuthoritiesUtils.memberRole(type, id), "");
|
||||
coPersonIds.forEach(coPersonId -> {
|
||||
String identifier = registryService.getIdentifierByCoPersonId(coPersonId);
|
||||
Integer role = registryService.getRoleId(coPersonId, couId);
|
||||
|
@ -98,13 +110,13 @@ public class MemberController {
|
|||
coPersonIds.forEach(coPersonId -> {
|
||||
String identifier = registryService.getIdentifierByCoPersonId(coPersonId);
|
||||
Integer role = registryService.getRoleId(coPersonId, couId);
|
||||
if(force) {
|
||||
if (force) {
|
||||
registryService.removeAdminRole(coPersonId, couId);
|
||||
}
|
||||
registryService.removeMemberRole(coPersonId, couId, role);
|
||||
authoritiesUpdater.update(identifier, old -> {
|
||||
HashSet<SimpleGrantedAuthority> authorities = new HashSet<>((Collection<? extends SimpleGrantedAuthority>) old);
|
||||
if(force) {
|
||||
if (force) {
|
||||
authorities.remove(new SimpleGrantedAuthority(AuthoritiesUtils.manager(type, id)));
|
||||
}
|
||||
authorities.remove(new SimpleGrantedAuthority(AuthoritiesUtils.member(type, id)));
|
||||
|
@ -121,7 +133,7 @@ public class MemberController {
|
|||
}
|
||||
|
||||
|
||||
/* *//**
|
||||
/* *//**
|
||||
* Get the names of the members of a type(Community, etc.) with id(ee, egi, etc.)
|
||||
*//*
|
||||
@RequestMapping(value = "/{type}/{id}/name", method = RequestMethod.GET)
|
||||
|
|
Loading…
Reference in New Issue