Revision 62360
Added by Konstantinos Triantafyllou almost 2 years ago
RegistryService.java | ||
---|---|---|
6 | 6 |
import com.google.gson.JsonParser; |
7 | 7 |
import eu.dnetlib.openaire.user.pojos.RoleVerification; |
8 | 8 |
import eu.dnetlib.openaire.user.utils.EmailSender; |
9 |
import eu.dnetlib.openaire.usermanagement.dto.Role; |
|
10 | 9 |
import eu.dnetlib.openaire.usermanagement.utils.AuthorizationService; |
11 | 10 |
import eu.dnetlib.openaire.usermanagement.utils.JsonUtils; |
12 | 11 |
import eu.dnetlib.openaire.usermanagement.utils.RoleManagement; |
... | ... | |
16 | 15 |
import org.springframework.http.HttpStatus; |
17 | 16 |
import org.springframework.security.access.prepost.PreAuthorize; |
18 | 17 |
import org.springframework.stereotype.Component; |
19 |
import org.springframework.web.bind.annotation.*; |
|
18 |
import org.springframework.web.bind.annotation.CrossOrigin; |
|
19 |
import org.springframework.web.bind.annotation.RequestBody; |
|
20 | 20 |
import org.springframework.web.client.HttpClientErrorException; |
21 | 21 |
|
22 | 22 |
import javax.mail.MessagingException; |
... | ... | |
106 | 106 |
@Path("/create/{type}/{id}") |
107 | 107 |
@POST |
108 | 108 |
@Produces(MediaType.APPLICATION_JSON) |
109 |
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") |
|
109 |
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN, @AuthorizationService.curator(#type))")
|
|
110 | 110 |
public Response createMemberRole(@PathParam("type") String type, @PathParam("id") String id) { |
111 |
JsonElement element = null; |
|
112 |
Response response = null; |
|
111 | 113 |
try { |
112 |
JsonElement response = calls.createMemberRole(type, id); |
|
113 |
return Response.status(HttpStatus.CREATED.value()).entity(response.toString()).type(MediaType.APPLICATION_JSON).build(); |
|
114 |
if(type.equals("ri") || type.equals("community")) { |
|
115 |
element = calls.createMemberRole("ri", id); |
|
116 |
} else { |
|
117 |
element = calls.createMemberRole(type, id); |
|
118 |
} |
|
114 | 119 |
} catch (HttpClientErrorException e) { |
115 | 120 |
String message = new JsonParser().parse(e.getResponseBodyAsString()).getAsJsonObject().get("message").getAsString(); |
116 |
return Response.status(e.getStatusCode().value()).entity(jsonUtils.createResponse(message).toString()).type(MediaType.APPLICATION_JSON).build(); |
|
121 |
response = Response.status(e.getStatusCode().value()).entity(jsonUtils.createResponse(message).toString()).type(MediaType.APPLICATION_JSON).build(); |
|
122 |
} finally { |
|
123 |
try { |
|
124 |
if(type.equals("ri") || type.equals("community")) { |
|
125 |
element = calls.createMemberRole("community", id); |
|
126 |
} |
|
127 |
if(element != null) { |
|
128 |
response = Response.status(HttpStatus.CREATED.value()).entity(element.toString()).type(MediaType.APPLICATION_JSON).build(); |
|
129 |
} |
|
130 |
} catch (HttpClientErrorException e) { |
|
131 |
String message = new JsonParser().parse(e.getResponseBodyAsString()).getAsJsonObject().get("message").getAsString(); |
|
132 |
response = Response.status(e.getStatusCode().value()).entity(jsonUtils.createResponse(message).toString()).type(MediaType.APPLICATION_JSON).build(); |
|
133 |
} |
|
117 | 134 |
} |
135 |
return response; |
|
118 | 136 |
} |
119 | 137 |
|
120 | 138 |
/** |
121 |
* @deprecated |
|
122 |
* |
|
123 |
* Create a new role with the given name and description. |
|
124 |
**/ |
|
125 |
@Path("/createRole") |
|
126 |
@POST |
|
127 |
@Produces(MediaType.APPLICATION_JSON) |
|
128 |
@Consumes(MediaType.APPLICATION_JSON) |
|
129 |
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") |
|
130 |
public Response createRole(@RequestBody Role role) { |
|
131 |
try { |
|
132 |
JsonElement response = calls.createRole(role.getName(), role.getDescription()); |
|
133 |
return Response.status(HttpStatus.CREATED.value()).entity(response.toString()).type(MediaType.APPLICATION_JSON).build(); |
|
134 |
} catch (HttpClientErrorException e) { |
|
135 |
String message = new JsonParser().parse(e.getResponseBodyAsString()).getAsJsonObject().get("message").getAsString(); |
|
136 |
return Response.status(e.getStatusCode().value()).entity(jsonUtils.createResponse(message).toString()).type(MediaType.APPLICATION_JSON).build(); |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 | 139 |
* Invite user with email to manage a type(Community, etc.) with id(ee, egi, etc.) |
142 | 140 |
* Auto generated link and code will be sent as response. |
143 | 141 |
*/ |
... | ... | |
470 | 468 |
return Response.status(e.getStatusCode().value()).entity(jsonUtils.createResponse(message).toString()).type(MediaType.APPLICATION_JSON).build(); |
471 | 469 |
} |
472 | 470 |
} |
473 |
} |
|
471 |
} |
Also available in: Unified diff
Update to version 2.0.1-BETA