Change Create member role in order to create both ri and community groups in both cases.
This commit is contained in:
parent
91511ee279
commit
61766a5f7b
|
@ -6,7 +6,6 @@ import com.google.gson.JsonObject;
|
|||
import com.google.gson.JsonParser;
|
||||
import eu.dnetlib.openaire.user.pojos.RoleVerification;
|
||||
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.JsonUtils;
|
||||
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.security.access.prepost.PreAuthorize;
|
||||
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 javax.mail.MessagingException;
|
||||
|
@ -106,36 +106,34 @@ public class RegistryService {
|
|||
@Path("/create/{type}/{id}")
|
||||
@POST
|
||||
@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) {
|
||||
JsonElement element = null;
|
||||
Response response = null;
|
||||
try {
|
||||
JsonElement response = calls.createMemberRole(type, id);
|
||||
return Response.status(HttpStatus.CREATED.value()).entity(response.toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
if(type.equals("ri") || type.equals("community")) {
|
||||
element = calls.createMemberRole("ri", id);
|
||||
} else {
|
||||
element = calls.createMemberRole(type, id);
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* Create a new role with the given name and description.
|
||||
**/
|
||||
@Path("/createRole")
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||
public Response createRole(@RequestBody Role role) {
|
||||
response = Response.status(e.getStatusCode().value()).entity(jsonUtils.createResponse(message).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
} finally {
|
||||
try {
|
||||
JsonElement response = calls.createRole(role.getName(), role.getDescription());
|
||||
return Response.status(HttpStatus.CREATED.value()).entity(response.toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
if(type.equals("ri") || type.equals("community")) {
|
||||
element = calls.createMemberRole("community", id);
|
||||
}
|
||||
if(element != null) {
|
||||
response = Response.status(HttpStatus.CREATED.value()).entity(element.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();
|
||||
response = Response.status(e.getStatusCode().value()).entity(jsonUtils.createResponse(message).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invite user with email to manage a type(Community, etc.) with id(ee, egi, etc.)
|
||||
|
|
Loading…
Reference in New Issue