Change Create member role in order to create both ri and community groups in both cases.

This commit is contained in:
Konstantinos Triantafyllou 2022-07-27 14:41:36 +00:00
parent 91511ee279
commit 61766a5f7b
1 changed files with 24 additions and 26 deletions

View File

@ -6,7 +6,6 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import eu.dnetlib.openaire.user.pojos.RoleVerification; import eu.dnetlib.openaire.user.pojos.RoleVerification;
import eu.dnetlib.openaire.user.utils.EmailSender; import eu.dnetlib.openaire.user.utils.EmailSender;
import eu.dnetlib.openaire.usermanagement.dto.Role;
import eu.dnetlib.openaire.usermanagement.utils.AuthorizationService; import eu.dnetlib.openaire.usermanagement.utils.AuthorizationService;
import eu.dnetlib.openaire.usermanagement.utils.JsonUtils; import eu.dnetlib.openaire.usermanagement.utils.JsonUtils;
import eu.dnetlib.openaire.usermanagement.utils.RoleManagement; import eu.dnetlib.openaire.usermanagement.utils.RoleManagement;
@ -16,7 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpClientErrorException;
import javax.mail.MessagingException; import javax.mail.MessagingException;
@ -106,35 +106,33 @@ public class RegistryService {
@Path("/create/{type}/{id}") @Path("/create/{type}/{id}")
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, @AuthorizationService.curator(#type))")
public Response createMemberRole(@PathParam("type") String type, @PathParam("id") String id) { public Response createMemberRole(@PathParam("type") String type, @PathParam("id") String id) {
JsonElement element = null;
Response response = null;
try { try {
JsonElement response = calls.createMemberRole(type, id); if(type.equals("ri") || type.equals("community")) {
return Response.status(HttpStatus.CREATED.value()).entity(response.toString()).type(MediaType.APPLICATION_JSON).build(); element = calls.createMemberRole("ri", id);
} else {
element = calls.createMemberRole(type, id);
}
} catch (HttpClientErrorException e) { } catch (HttpClientErrorException e) {
String message = new JsonParser().parse(e.getResponseBodyAsString()).getAsJsonObject().get("message").getAsString(); String message = new JsonParser().parse(e.getResponseBodyAsString()).getAsJsonObject().get("message").getAsString();
return Response.status(e.getStatusCode().value()).entity(jsonUtils.createResponse(message).toString()).type(MediaType.APPLICATION_JSON).build(); response = Response.status(e.getStatusCode().value()).entity(jsonUtils.createResponse(message).toString()).type(MediaType.APPLICATION_JSON).build();
} } finally {
} try {
if(type.equals("ri") || type.equals("community")) {
/** element = calls.createMemberRole("community", id);
* @deprecated }
* if(element != null) {
* Create a new role with the given name and description. response = Response.status(HttpStatus.CREATED.value()).entity(element.toString()).type(MediaType.APPLICATION_JSON).build();
**/ }
@Path("/createRole") } catch (HttpClientErrorException e) {
@POST String message = new JsonParser().parse(e.getResponseBodyAsString()).getAsJsonObject().get("message").getAsString();
@Produces(MediaType.APPLICATION_JSON) response = Response.status(e.getStatusCode().value()).entity(jsonUtils.createResponse(message).toString()).type(MediaType.APPLICATION_JSON).build();
@Consumes(MediaType.APPLICATION_JSON) }
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
public Response createRole(@RequestBody Role role) {
try {
JsonElement response = calls.createRole(role.getName(), role.getDescription());
return Response.status(HttpStatus.CREATED.value()).entity(response.toString()).type(MediaType.APPLICATION_JSON).build();
} catch (HttpClientErrorException e) {
String message = new JsonParser().parse(e.getResponseBodyAsString()).getAsJsonObject().get("message").getAsString();
return Response.status(e.getStatusCode().value()).entity(jsonUtils.createResponse(message).toString()).type(MediaType.APPLICATION_JSON).build();
} }
return response;
} }
/** /**