1
|
package eu.dnetlib.openaire.usermanagement.api;
|
2
|
|
3
|
import com.google.gson.JsonArray;
|
4
|
import com.google.gson.JsonObject;
|
5
|
import com.google.gson.JsonParser;
|
6
|
import eu.dnetlib.openaire.user.pojos.RoleVerification;
|
7
|
import eu.dnetlib.openaire.user.utils.EmailSender;
|
8
|
import eu.dnetlib.openaire.usermanagement.dto.Role;
|
9
|
import eu.dnetlib.openaire.usermanagement.utils.JsonUtils;
|
10
|
import eu.dnetlib.openaire.usermanagement.utils.RegistryCalls;
|
11
|
import eu.dnetlib.openaire.usermanagement.utils.VerificationUtils;
|
12
|
import org.apache.log4j.Logger;
|
13
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
import org.springframework.http.HttpStatus;
|
15
|
import org.springframework.security.access.prepost.PreAuthorize;
|
16
|
import org.springframework.stereotype.Component;
|
17
|
import org.springframework.web.bind.annotation.RequestBody;
|
18
|
|
19
|
import javax.mail.MessagingException;
|
20
|
import javax.ws.rs.*;
|
21
|
import javax.ws.rs.core.MediaType;
|
22
|
import javax.ws.rs.core.Response;
|
23
|
|
24
|
@Component(value = "RegistryService")
|
25
|
@Path("/registry")
|
26
|
public class RegistryService {
|
27
|
|
28
|
private static final Logger logger = Logger.getLogger(RegistryService.class);
|
29
|
|
30
|
@Autowired
|
31
|
private RegistryCalls calls;
|
32
|
|
33
|
@Autowired
|
34
|
private JsonUtils jsonUtils;
|
35
|
|
36
|
@Autowired
|
37
|
private EmailSender emailSender;
|
38
|
|
39
|
@Autowired
|
40
|
private VerificationUtils verificationUtils;
|
41
|
|
42
|
|
43
|
/**
|
44
|
* Subscribe to a type(Community, etc.) with id(ee, egi, etc.)
|
45
|
*/
|
46
|
@Path("/subscribe/{type}/{id}")
|
47
|
@POST
|
48
|
@Produces(MediaType.APPLICATION_JSON)
|
49
|
@PreAuthorize("isAuthenticated() and @AuthorizationService.isCommunity(#type)")
|
50
|
public Response subscribe(@PathParam("type") String type, @PathParam("id") String id) {
|
51
|
Integer coPersonId = calls.getCoPersonIdByIdentifier();
|
52
|
Integer couId = calls.getCouId(type, id);
|
53
|
if (couId != null) {
|
54
|
Integer role = calls.getRoleId(coPersonId, couId);
|
55
|
calls.assignMemberRole(coPersonId, couId, role);
|
56
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been assigned").toString()).type(MediaType.APPLICATION_JSON).build();
|
57
|
} else {
|
58
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
59
|
}
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Unsubscribe from type(Community, etc.) with id(ee, egi, etc.).
|
64
|
* If user has manager role for this entity, it will be removed too.
|
65
|
*/
|
66
|
@Path("/unsubscribe/{type}/{id}")
|
67
|
@POST
|
68
|
@Produces(MediaType.APPLICATION_JSON)
|
69
|
@PreAuthorize("isAuthenticated() and @AuthorizationService.isCommunity(#type)")
|
70
|
public Response unsubscribe(@PathParam("type") String type, @PathParam("id") String id) {
|
71
|
Integer coPersonId = calls.getCoPersonIdByIdentifier();
|
72
|
Integer couId = calls.getCouId(type, id);
|
73
|
if (couId != null) {
|
74
|
Integer role = calls.getRoleId(coPersonId, couId);
|
75
|
if (role != null) {
|
76
|
calls.removeAdminRole(coPersonId, couId);
|
77
|
calls.removeMemberRole(coPersonId, couId, role);
|
78
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been removed").toString()).type(MediaType.APPLICATION_JSON).build();
|
79
|
} else
|
80
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("User does not have this role").toString()).type(MediaType.APPLICATION_JSON).build();
|
81
|
} else {
|
82
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
83
|
}
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* Create a new role with the given name and description.
|
88
|
**/
|
89
|
@Path("/createRole")
|
90
|
@POST
|
91
|
@Produces(MediaType.APPLICATION_JSON)
|
92
|
@Consumes(MediaType.APPLICATION_JSON)
|
93
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
|
94
|
public Response createRole(@RequestBody Role role) {
|
95
|
calls.createRole(role);
|
96
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* Invite user with email to manage a type(Community, etc.) with id(ee, egi, etc.)
|
101
|
* Auto generated link and code will be sent as response.
|
102
|
*/
|
103
|
@Path("/invite/{type}/{id}/manager/{email}")
|
104
|
@POST
|
105
|
@Produces(MediaType.APPLICATION_JSON)
|
106
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
107
|
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
108
|
public Response inviteManager(@PathParam("type") String type, @PathParam("id") String id, @PathParam("email") String email, @RequestBody String body) {
|
109
|
Integer couId = calls.getCouId(type, id);
|
110
|
if (couId != null) {
|
111
|
Integer coPersonId = calls.getCoPersonIdByEmail(email);
|
112
|
if (coPersonId == null || calls.getUserAdminGroup(coPersonId, couId) == null) {
|
113
|
JsonObject invitation = verificationUtils.createManagerInvitation(email, type, id);
|
114
|
String name = (coPersonId != null)?calls.getUserNames(coPersonId):null;
|
115
|
JsonObject details = new JsonParser().parse(body).getAsJsonObject();
|
116
|
String link = details.get("link").getAsString() + invitation.get("link").getAsString();
|
117
|
String subject = "Invite to manage " + details.get("name").getAsString();
|
118
|
String message = "<p>Hello" + ((name != null)?(" " + name):"") + ",</p>" +
|
119
|
"<p> You have been invited to manage " + details.get("name").getAsString() + ". " +
|
120
|
"Use the verification code below to accept the invitation." +
|
121
|
"</p>" +
|
122
|
"<p>" +
|
123
|
"The verification code is " + invitation.get("code").getAsString() +
|
124
|
"</p>" +
|
125
|
"Click the URL below and proceed with the process." +
|
126
|
"<p><a href=" + link + ">" + link + "</a></p>" +
|
127
|
"<p>Thank you,</p>" +
|
128
|
"<p>OpenAIRE technical team</p>";
|
129
|
try {
|
130
|
emailSender.sendEmail(email, subject, message);
|
131
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(invitation).toString()).type(MediaType.APPLICATION_JSON).build();
|
132
|
} catch (MessagingException e) {
|
133
|
logger.error(e.getMessage());
|
134
|
verificationUtils.deleteVerification(invitation.get("link").getAsString());
|
135
|
return Response.status(HttpStatus.BAD_REQUEST.value()).entity(jsonUtils.createResponse("Email sent failed").toString()).type(MediaType.APPLICATION_JSON).build();
|
136
|
}
|
137
|
} else {
|
138
|
return Response.status(HttpStatus.CONFLICT.value()).entity(jsonUtils.createResponse("User has been already manager of this " + type).toString()).type(MediaType.APPLICATION_JSON).build();
|
139
|
}
|
140
|
} else {
|
141
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
142
|
}
|
143
|
}
|
144
|
|
145
|
/**
|
146
|
* Invite user with email to be a member of a type(Community, etc.) with id(ee, egi, etc.)
|
147
|
* Auto generated link and code will be sent as response.
|
148
|
*/
|
149
|
@Path("/invite/{type}/{id}/member/{email}")
|
150
|
@POST
|
151
|
@Produces(MediaType.APPLICATION_JSON)
|
152
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
153
|
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
154
|
public Response inviteMember(@PathParam("type") String type, @PathParam("id") String id, @PathParam("email") String email, @RequestBody String body) {
|
155
|
Integer couId = calls.getCouId(type, id);
|
156
|
if (couId != null) {
|
157
|
Integer coPersonId = calls.getCoPersonIdByEmail(email);
|
158
|
if (coPersonId == null || calls.getRoleId(coPersonId, couId) == null) {
|
159
|
JsonObject invitation = verificationUtils.createMemberInvitation(email, type, id);
|
160
|
String name = (coPersonId != null)?calls.getUserNames(coPersonId):null;
|
161
|
JsonObject details = new JsonParser().parse(body).getAsJsonObject();
|
162
|
String link = details.get("link").getAsString() + invitation.get("link").getAsString();
|
163
|
String subject = "Invite to be a member of " + details.get("name").getAsString();
|
164
|
String message = "<p>Hello" + ((name != null)?(" " + name):"") + ",</p>" +
|
165
|
"<p> You have been invited to be a member of " + details.get("name").getAsString() + ". " +
|
166
|
"Use the verification code below to accept the invitation." +
|
167
|
"</p>" +
|
168
|
"<p>" +
|
169
|
"The verification code is " + invitation.get("code").getAsString() +
|
170
|
"</p>" +
|
171
|
"Click the URL below and proceed with the process." +
|
172
|
"<p><a href=" + link + ">" + link + "</a></p>" +
|
173
|
"<p>Thank you,</p>" +
|
174
|
"<p>OpenAIRE technical team</p>";
|
175
|
try {
|
176
|
emailSender.sendEmail(email, subject, message);
|
177
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(invitation).toString()).type(MediaType.APPLICATION_JSON).build();
|
178
|
} catch (MessagingException e) {
|
179
|
logger.error(e.getMessage());
|
180
|
verificationUtils.deleteVerification(invitation.get("link").getAsString());
|
181
|
return Response.status(HttpStatus.BAD_REQUEST.value()).entity(jsonUtils.createResponse("Email sent failed").toString()).type(MediaType.APPLICATION_JSON).build();
|
182
|
}
|
183
|
} else {
|
184
|
return Response.status(HttpStatus.CONFLICT.value()).entity(jsonUtils.createResponse("User has been already member of this " + type).toString()).type(MediaType.APPLICATION_JSON).build();
|
185
|
}
|
186
|
} else {
|
187
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
188
|
}
|
189
|
}
|
190
|
|
191
|
/**
|
192
|
* Cancel invitation to user with email for managing a type(Community, etc.) with id(ee, egi, etc.)
|
193
|
*/
|
194
|
@Path("/invite/{type}/{id}/manager/{email}")
|
195
|
@DELETE
|
196
|
@Produces(MediaType.APPLICATION_JSON)
|
197
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
198
|
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
199
|
public Response cancelManagerInvitations(@PathParam("type") String type, @PathParam("id") String id, @PathParam("email") String email) {
|
200
|
Integer couId = calls.getCouId(type, id);
|
201
|
if (couId != null) {
|
202
|
verificationUtils.deleteManagerVerifications(email, type, id);
|
203
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Invitations have been deleted").toString()).type(MediaType.APPLICATION_JSON).build();
|
204
|
} else {
|
205
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
206
|
}
|
207
|
}
|
208
|
|
209
|
/**
|
210
|
* Cancel invitation to user with email for being member of a type(Community, etc.) with id(ee, egi, etc.)
|
211
|
*/
|
212
|
@Path("/invite/{type}/{id}/member/{email}")
|
213
|
@DELETE
|
214
|
@Produces(MediaType.APPLICATION_JSON)
|
215
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
216
|
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
217
|
public Response cancelMemberInvitations(@PathParam("type") String type, @PathParam("id") String id, @PathParam("email") String email) {
|
218
|
Integer couId = calls.getCouId(type, id);
|
219
|
if (couId != null) {
|
220
|
verificationUtils.deleteMemberVerifications(email, type, id);
|
221
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Invitations have been deleted").toString()).type(MediaType.APPLICATION_JSON).build();
|
222
|
} else {
|
223
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
224
|
}
|
225
|
}
|
226
|
|
227
|
/**
|
228
|
* Get the invited managers for a type(Community, etc.) with id(ee, egi, etc.)
|
229
|
*/
|
230
|
@Path("/invite/{type}/{id}/managers/")
|
231
|
@GET
|
232
|
@Produces(MediaType.APPLICATION_JSON)
|
233
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
234
|
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
235
|
public Response getInvitedManagers(@PathParam("type") String type, @PathParam("id") String id) {
|
236
|
JsonArray invited = verificationUtils.getInvitedManagers(type, id);
|
237
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(invited).toString()).type(MediaType.APPLICATION_JSON).build();
|
238
|
}
|
239
|
|
240
|
/**
|
241
|
* Get the invited members for a type(Community, etc.) with id(ee, egi, etc.)
|
242
|
*/
|
243
|
@Path("/invite/{type}/{id}/members/")
|
244
|
@GET
|
245
|
@Produces(MediaType.APPLICATION_JSON)
|
246
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
|
247
|
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
248
|
public Response getInviteMembers(@PathParam("type") String type, @PathParam("id") String id) {
|
249
|
JsonArray invited = verificationUtils.getInvitedMembers(type, id);
|
250
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(invited).toString()).type(MediaType.APPLICATION_JSON).build();
|
251
|
}
|
252
|
|
253
|
/**
|
254
|
* Get the verification with a specific id only if it refers to the logged in user
|
255
|
*/
|
256
|
@Path("verification/{id}")
|
257
|
@GET
|
258
|
@Produces(MediaType.APPLICATION_JSON)
|
259
|
@PreAuthorize("isAuthenticated()")
|
260
|
public Response getVerification(@PathParam("id") String id) {
|
261
|
RoleVerification verification = verificationUtils.getVerification(id);
|
262
|
if (verification != null) {
|
263
|
if (calls.getCoPersonIdByEmail(verification.getEmail()).equals(calls.getCoPersonIdByIdentifier())) {
|
264
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(jsonUtils.createVerification(verification)).toString()).type(MediaType.APPLICATION_JSON).build();
|
265
|
} else {
|
266
|
return Response.status(HttpStatus.FORBIDDEN.value()).entity(jsonUtils.createResponse("Forbidden verification").toString()).type(MediaType.APPLICATION_JSON).build();
|
267
|
}
|
268
|
} else {
|
269
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Verification has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
270
|
}
|
271
|
}
|
272
|
|
273
|
/**
|
274
|
* Delete the verification with a specific id.
|
275
|
*/
|
276
|
@Path("verification/{id}")
|
277
|
@DELETE
|
278
|
@Produces(MediaType.APPLICATION_JSON)
|
279
|
@PreAuthorize("isAuthenticated() && @VerificationUtils.ownedVerification(#id)")
|
280
|
public Response deleteVerification(@PathParam("id") String id) {
|
281
|
if (verificationUtils.getVerification(id) != null) {
|
282
|
verificationUtils.deleteVerification(id);
|
283
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(jsonUtils.createResponse("Verification deleted")).toString()).type(MediaType.APPLICATION_JSON).build();
|
284
|
} else {
|
285
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse(jsonUtils.createResponse("Verification has not been found")).toString()).type(MediaType.APPLICATION_JSON).build();
|
286
|
}
|
287
|
}
|
288
|
|
289
|
/**
|
290
|
* Verify the verification with the specific id, if the code is correct and it refers to the logged in user.
|
291
|
* Manager role is assigned to this user, along with the member role.
|
292
|
*/
|
293
|
@Path("verification/manager/{id}")
|
294
|
@POST
|
295
|
@Produces(MediaType.APPLICATION_JSON)
|
296
|
@PreAuthorize("isAuthenticated()")
|
297
|
public Response verifyManager(@PathParam("id") String id, @RequestBody String code) {
|
298
|
RoleVerification verification = verificationUtils.getVerification(id);
|
299
|
if (verification != null && verification.getVerificationType().equals("manager")) {
|
300
|
Integer coPersonId = calls.getCoPersonIdByEmail(verification.getEmail());
|
301
|
if (coPersonId != null) {
|
302
|
if (coPersonId.equals(calls.getCoPersonIdByIdentifier())) {
|
303
|
if (verification.getVerificationCode().equals(code)) {
|
304
|
Integer couId = calls.getCouId(verification.getType(), verification.getEntity());
|
305
|
if (couId != null) {
|
306
|
Integer role = calls.getRoleId(coPersonId, couId);
|
307
|
calls.assignMemberRole(coPersonId, couId, role);
|
308
|
verificationUtils.deleteMemberVerifications(verification.getEmail(), verification.getType(), verification.getEntity());
|
309
|
if (calls.getUserAdminGroup(coPersonId, couId) == null) {
|
310
|
verificationUtils.deleteManagerVerifications(verification.getEmail(), verification.getType(), verification.getEntity());
|
311
|
calls.assignAdminRole(coPersonId, couId);
|
312
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Admin role has been assigned").toString()).type(MediaType.APPLICATION_JSON).build();
|
313
|
} else {
|
314
|
return Response.status(HttpStatus.CONFLICT.value()).entity(jsonUtils.createResponse("User is already admin of this cou").toString()).type(MediaType.APPLICATION_JSON).build();
|
315
|
}
|
316
|
} else {
|
317
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
318
|
}
|
319
|
} else {
|
320
|
return Response.status(HttpStatus.FORBIDDEN.value()).entity(jsonUtils.createResponse("Verification code is wrong").toString()).type(MediaType.APPLICATION_JSON).build();
|
321
|
}
|
322
|
} else {
|
323
|
return Response.status(HttpStatus.FORBIDDEN.value()).entity(jsonUtils.createResponse("Forbidden verification").toString()).type(MediaType.APPLICATION_JSON).build();
|
324
|
}
|
325
|
} else {
|
326
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("User has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
327
|
}
|
328
|
} else {
|
329
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Verification has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
330
|
}
|
331
|
}
|
332
|
|
333
|
/**
|
334
|
* Verify the verification with the specific id, if the code is correct and it refers to the logged in user.
|
335
|
* Member role is assigned to this user, along with the member role.
|
336
|
*/
|
337
|
@Path("verification/member/{id}")
|
338
|
@POST
|
339
|
@Produces(MediaType.APPLICATION_JSON)
|
340
|
@PreAuthorize("isAuthenticated()")
|
341
|
public Response verifyMember(@PathParam("id") String id, @RequestBody String code) {
|
342
|
RoleVerification verification = verificationUtils.getVerification(id);
|
343
|
if (verification != null && verification.getVerificationType().equals("member")) {
|
344
|
Integer coPersonId = calls.getCoPersonIdByEmail(verification.getEmail());
|
345
|
if (coPersonId != null) {
|
346
|
if (coPersonId.equals(calls.getCoPersonIdByIdentifier())) {
|
347
|
if (verification.getVerificationCode().equals(code)) {
|
348
|
Integer couId = calls.getCouId(verification.getType(), verification.getEntity());
|
349
|
if (couId != null) {
|
350
|
Integer role = calls.getRoleId(coPersonId, couId);
|
351
|
calls.assignMemberRole(coPersonId, couId, role);
|
352
|
verificationUtils.deleteMemberVerifications(verification.getEmail(), verification.getType(), verification.getEntity());
|
353
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Member role has been assigned").toString()).type(MediaType.APPLICATION_JSON).build();
|
354
|
} else {
|
355
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
356
|
}
|
357
|
} else {
|
358
|
return Response.status(HttpStatus.FORBIDDEN.value()).entity(jsonUtils.createResponse("Verification code is wrong").toString()).type(MediaType.APPLICATION_JSON).build();
|
359
|
}
|
360
|
} else {
|
361
|
return Response.status(HttpStatus.FORBIDDEN.value()).entity(jsonUtils.createResponse("Forbidden verification").toString()).type(MediaType.APPLICATION_JSON).build();
|
362
|
}
|
363
|
} else {
|
364
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("User has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
365
|
}
|
366
|
} else {
|
367
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Verification has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
368
|
}
|
369
|
}
|
370
|
|
371
|
/**
|
372
|
* Remove the manager role from user with email for a type(Community, etc.) with id(ee, egi, etc.)
|
373
|
*/
|
374
|
@Path("/{type}/{id}/manager/{email}")
|
375
|
@DELETE
|
376
|
@Produces(MediaType.APPLICATION_JSON)
|
377
|
@Consumes(MediaType.APPLICATION_JSON)
|
378
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN," +
|
379
|
"@AuthorizationService.PORTAL_ADMIN, @AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
380
|
public Response removeManagerRole(@PathParam("type") String type, @PathParam("id") String
|
381
|
id, @PathParam("email") String email) {
|
382
|
Integer coPersonId = calls.getCoPersonIdByEmail(email);
|
383
|
if (coPersonId != null) {
|
384
|
Integer couId = calls.getCouId(type, id);
|
385
|
if (couId != null) {
|
386
|
calls.removeAdminRole(coPersonId, couId);
|
387
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been removed").toString()).type(MediaType.APPLICATION_JSON).build();
|
388
|
} else {
|
389
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
390
|
}
|
391
|
} else {
|
392
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("User has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
393
|
}
|
394
|
}
|
395
|
|
396
|
/**
|
397
|
* Remove the member role from user with email for a type(Community, etc.) with id(ee, egi, etc.)
|
398
|
*/
|
399
|
@Path("/{type}/{id}/member/{email}")
|
400
|
@DELETE
|
401
|
@Produces(MediaType.APPLICATION_JSON)
|
402
|
@Consumes(MediaType.APPLICATION_JSON)
|
403
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN," +
|
404
|
"@AuthorizationService.PORTAL_ADMIN, @AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
405
|
public Response removeMemberRole(@PathParam("type") String type, @PathParam("id") String
|
406
|
id, @PathParam("email") String email) {
|
407
|
Integer coPersonId = calls.getCoPersonIdByEmail(email);
|
408
|
if (coPersonId != null) {
|
409
|
Integer couId = calls.getCouId(type, id);
|
410
|
Integer role = null;
|
411
|
if(couId != null) {
|
412
|
role = calls.getRoleId(coPersonId, couId);
|
413
|
}
|
414
|
if (couId != null && role != null) {
|
415
|
calls.removeAdminRole(coPersonId, couId);
|
416
|
calls.removeMemberRole(coPersonId, couId, role);
|
417
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been removed").toString()).type(MediaType.APPLICATION_JSON).build();
|
418
|
} else {
|
419
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
420
|
}
|
421
|
} else {
|
422
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("User has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
423
|
}
|
424
|
}
|
425
|
|
426
|
/**
|
427
|
* Get the names of the members of a type(Community, etc.) with id(ee, egi, etc.)
|
428
|
*/
|
429
|
@Path("/{type}/{id}/members")
|
430
|
@GET
|
431
|
@Produces(MediaType.APPLICATION_JSON)
|
432
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN," +
|
433
|
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
434
|
public Response getMembers(@PathParam("type") String type, @PathParam("id") String id) {
|
435
|
Integer couId = calls.getCouId(type, id);
|
436
|
if(couId != null) {
|
437
|
JsonArray members = calls.getUserNamesByCouId(couId, false);
|
438
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
|
439
|
} else {
|
440
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
441
|
}
|
442
|
}
|
443
|
|
444
|
/**
|
445
|
* Get the emails of the members of a type(Community, etc.) with id(ee, egi, etc.)
|
446
|
*/
|
447
|
@Path("/{type}/{id}/members/email")
|
448
|
@GET
|
449
|
@Produces(MediaType.APPLICATION_JSON)
|
450
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN," +
|
451
|
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
452
|
public Response getMembersEmail(@PathParam("type") String type, @PathParam("id") String id) {
|
453
|
Integer couId = calls.getCouId(type, id);
|
454
|
if(couId != null) {
|
455
|
JsonArray members = calls.getUserEmailByCouId(couId, false);
|
456
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
|
457
|
} else {
|
458
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
459
|
}
|
460
|
}
|
461
|
|
462
|
/**
|
463
|
* Get the number of the members of a type(Community, etc.) with id(ee, egi, etc.)
|
464
|
*/
|
465
|
@Path("/{type}/{id}/members/count")
|
466
|
@GET
|
467
|
@Produces(MediaType.APPLICATION_JSON)
|
468
|
public Response getMembersCount(@PathParam("type") String type, @PathParam("id") String id) {
|
469
|
Integer couId = calls.getCouId(type, id);
|
470
|
int count = 0;
|
471
|
if(couId != null) {
|
472
|
count = calls.getUserNamesByCouId(couId, false).size();
|
473
|
}
|
474
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(count).toString()).type(MediaType.APPLICATION_JSON).build();
|
475
|
}
|
476
|
|
477
|
/**
|
478
|
* Get the names of the managers of a type(Community, etc.) with id(ee, egi, etc.)
|
479
|
*/
|
480
|
@Path("/{type}/{id}/managers")
|
481
|
@GET
|
482
|
@Produces(MediaType.APPLICATION_JSON)
|
483
|
public Response getManagers(@PathParam("type") String type, @PathParam("id") String id) {
|
484
|
Integer couId = calls.getCouId(type, id);
|
485
|
if(couId != null) {
|
486
|
JsonArray managers = calls.getUserNamesByCouId(couId, true);
|
487
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
|
488
|
} else {
|
489
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
490
|
}
|
491
|
}
|
492
|
|
493
|
/**
|
494
|
* Get the emails of the managers of a type(Community, etc.) with id(ee, egi, etc.)
|
495
|
*/
|
496
|
@Path("/{type}/{id}/managers/email")
|
497
|
@GET
|
498
|
@Produces(MediaType.APPLICATION_JSON)
|
499
|
public Response getManagersEmail(@PathParam("type") String type, @PathParam("id") String id) {
|
500
|
Integer couId = calls.getCouId(type, id);
|
501
|
if(couId != null) {
|
502
|
JsonArray managers = calls.getUserEmailByCouId(couId, true);
|
503
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
|
504
|
} else {
|
505
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
506
|
}
|
507
|
}
|
508
|
}
|