[Users | Trunk]: Fix get managers and members calls
This commit is contained in:
parent
e947a9c7c3
commit
b7a94f6aa2
|
@ -90,7 +90,7 @@ public class RegistryService {
|
|||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN)")
|
||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
|
||||
public Response createRole(@RequestBody Role role) {
|
||||
calls.createRole(role);
|
||||
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
|
@ -407,7 +407,10 @@ public class RegistryService {
|
|||
Integer coPersonId = calls.getCoPersonIdByEmail(email);
|
||||
if (coPersonId != null) {
|
||||
Integer couId = calls.getCouId(type, id);
|
||||
Integer role = calls.getRoleId(coPersonId, couId);
|
||||
Integer role = null;
|
||||
if(couId != null) {
|
||||
role = calls.getRoleId(coPersonId, couId);
|
||||
}
|
||||
if (couId != null && role != null) {
|
||||
calls.removeAdminRole(coPersonId, couId);
|
||||
calls.removeMemberRole(coPersonId, couId, role);
|
||||
|
@ -430,8 +433,12 @@ public class RegistryService {
|
|||
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
||||
public Response getMembers(@PathParam("type") String type, @PathParam("id") String id) {
|
||||
Integer couId = calls.getCouId(type, id);
|
||||
JsonArray subscribers = calls.getUserNamesByCouId(couId, false);
|
||||
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(subscribers).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
if(couId != null) {
|
||||
JsonArray members = calls.getUserNamesByCouId(couId, true);
|
||||
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
} else {
|
||||
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -444,8 +451,12 @@ public class RegistryService {
|
|||
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
||||
public Response getMembersEmail(@PathParam("type") String type, @PathParam("id") String id) {
|
||||
Integer couId = calls.getCouId(type, id);
|
||||
JsonArray subscribers = calls.getUserEmailByCouId(couId, false);
|
||||
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(subscribers).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
if(couId != null) {
|
||||
JsonArray members = calls.getUserEmailByCouId(couId, true);
|
||||
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
} else {
|
||||
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -456,7 +467,10 @@ public class RegistryService {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getMembersCount(@PathParam("type") String type, @PathParam("id") String id) {
|
||||
Integer couId = calls.getCouId(type, id);
|
||||
int count = calls.getUserNamesByCouId(couId, false).size();
|
||||
int count = 0;
|
||||
if(couId != null) {
|
||||
count = calls.getUserNamesByCouId(couId, false).size();
|
||||
}
|
||||
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(count).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
|
@ -468,8 +482,12 @@ public class RegistryService {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getManagers(@PathParam("type") String type, @PathParam("id") String id) {
|
||||
Integer couId = calls.getCouId(type, id);
|
||||
JsonArray managers = calls.getUserNamesByCouId(couId, true);
|
||||
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
if(couId != null) {
|
||||
JsonArray managers = calls.getUserNamesByCouId(couId, true);
|
||||
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
} else {
|
||||
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -480,7 +498,11 @@ public class RegistryService {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getManagersEmail(@PathParam("type") String type, @PathParam("id") String id) {
|
||||
Integer couId = calls.getCouId(type, id);
|
||||
JsonArray managers = calls.getUserEmailByCouId(couId, true);
|
||||
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
if(couId != null) {
|
||||
JsonArray managers = calls.getUserEmailByCouId(couId, true);
|
||||
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
} else {
|
||||
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,12 +9,22 @@ public class AuthorizationService {
|
|||
public final String PORTAL_ADMIN = "PORTAL_ADMINISTRATOR";
|
||||
public final String USER_ADMIN = "USER_MANAGER";
|
||||
|
||||
private String mapType(String type) {
|
||||
if(type.equals("organization")) {
|
||||
type = "institution";
|
||||
}
|
||||
if(type.equals("ri")) {
|
||||
type = "community";
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
|
||||
*
|
||||
* */
|
||||
public String curator(String type) {
|
||||
return type.toUpperCase() + "_CURATOR";
|
||||
return mapType(type).toUpperCase() + "_CURATOR";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,7 +33,7 @@ public class AuthorizationService {
|
|||
* Id = EE, EGI, etc
|
||||
* */
|
||||
public String manager(String type, String id) {
|
||||
return type.toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
|
||||
return mapType(type).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,10 +42,10 @@ public class AuthorizationService {
|
|||
* Id = EE, EGI, etc
|
||||
* */
|
||||
public String member(String type, String id) {
|
||||
return type.toUpperCase() + "_" + id.toUpperCase();
|
||||
return mapType(type).toUpperCase() + "_" + id.toUpperCase();
|
||||
}
|
||||
|
||||
public boolean isCommunity(String type) {
|
||||
return type.equals("community");
|
||||
return mapType(type).equals("community");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,17 @@ public class RegistryCalls {
|
|||
@Autowired
|
||||
public JsonUtils jsonUtils;
|
||||
|
||||
|
||||
private String mapType(String type) {
|
||||
if(type.equals("organization")) {
|
||||
type = "institution";
|
||||
}
|
||||
if(type.equals("ri")) {
|
||||
type = "community";
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Get CoPersonId by Email
|
||||
*/
|
||||
|
@ -101,7 +112,7 @@ public class RegistryCalls {
|
|||
JsonArray cous = getCous();
|
||||
Integer couId = null;
|
||||
for (JsonElement cou : cous) {
|
||||
if (cou.getAsJsonObject().get("Name").getAsString().equals(type + "." + id)) {
|
||||
if (cou.getAsJsonObject().get("Name").getAsString().equals(mapType(type) + "." + id)) {
|
||||
couId = cou.getAsJsonObject().get("Id").getAsInt();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue