Project

General

Profile

« Previous | Next » 

Revision 59502

[Dnet-Users | Trunk]: Add member invitation methods

View differences:

modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/AuthorizationService.java
34 34
    public String member(String type, String id) {
35 35
        return type.toUpperCase() + "_" + id.toUpperCase();
36 36
    }
37

  
38
    public boolean isCommunity(String type) {
39
        return type.equals("community");
40
    }
37 41
}
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/VerificationUtils.java
2 2

  
3 3
import com.google.gson.JsonArray;
4 4
import com.google.gson.JsonObject;
5
import eu.dnetlib.openaire.user.pojos.ManagerVerification;
5
import eu.dnetlib.openaire.user.pojos.RoleVerification;
6 6
import eu.dnetlib.openaire.user.utils.ManagerVerificationActions;
7 7
import org.apache.log4j.Logger;
8 8
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
9 9
import org.springframework.beans.factory.annotation.Autowired;
10 10
import org.springframework.security.core.context.SecurityContextHolder;
11
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
12
import org.springframework.security.crypto.password.PasswordEncoder;
13 11
import org.springframework.stereotype.Component;
14 12

  
15 13
import java.sql.Timestamp;
16
import java.util.*;
14
import java.util.Date;
15
import java.util.List;
16
import java.util.Random;
17 17

  
18 18

  
19 19
@Component("VerificationUtils")
......
25 25
    @Autowired
26 26
    private ManagerVerificationActions actions;
27 27

  
28
    public JsonObject createInvitation(String email, String type, String entity) {
28
    public JsonObject createManagerInvitation(String email, String type, String entity) {
29
        RoleVerification roleVerification = actions.getManagerVerification(email, type, entity);
30
        if(roleVerification == null) {
31
            String id;
32
            do {
33
                id = createId();
34
            } while (exists(id));
35
            roleVerification = actions.addManagerVerification(id, email, type, entity, createVerificationCode(), new Timestamp(new Date().getTime()));
36
        }
37
        JsonObject invitation = new JsonObject();
38
        invitation.addProperty("link", roleVerification.getId());
39
        invitation.addProperty("code", roleVerification.getVerificationCode());
40
        return invitation;
41
    }
42

  
43
    public JsonObject createMemberInvitation(String email, String type, String entity) {
29 44
        String id;
30 45
        do {
31 46
            id = createId();
32 47
        } while (exists(id));
33
        ManagerVerification managerVerification = actions.addVerificationEntry(id, email, type, entity, createVerificationCode(), new Timestamp(new Date().getTime()));
34
        JsonObject invitation = new JsonObject();
35
        invitation.addProperty("link", managerVerification.getId());
36
        invitation.addProperty("code", managerVerification.getVerificationCode());
48
        RoleVerification roleVerification = actions.getMemberVerification(email, type, entity);
49
        if(roleVerification == null) {
50
            roleVerification = actions.addMemberVerification(id, email, type, entity, createVerificationCode(), new Timestamp(new Date().getTime()));
51
        }        JsonObject invitation = new JsonObject();
52
        invitation.addProperty("link", roleVerification.getId());
53
        invitation.addProperty("code", roleVerification.getVerificationCode());
37 54
        return invitation;
38 55
    }
39 56

  
40
    public void deleteRelatedVerifications(ManagerVerification managerVerification) {
41
        List<ManagerVerification> related = actions.
42
                getUserVerificationsForAnEntity(managerVerification.getEmail(), managerVerification.getType(), managerVerification.getEntity());
43
        for (ManagerVerification verification : related) {
44
            deleteVerification(verification.getId());
57
    public void deleteManagerVerifications(String email, String type, String entity) {
58
        RoleVerification roleVerification = actions.getManagerVerification(email, type, entity);
59
        if (roleVerification != null) {
60
            deleteVerification(roleVerification.getId());
45 61
        }
46 62
    }
47 63

  
48
    public void deleteUserVerifications(String email, String type, String entity) {
49
        List<ManagerVerification> managerVerifications = actions.
50
                getUserVerificationsForAnEntity(email, type, entity);
51
        for (ManagerVerification verification : managerVerifications) {
52
            deleteVerification(verification.getId());
64
    public void deleteMemberVerifications(String email, String type, String entity) {
65
        RoleVerification roleVerification = actions.getMemberVerification(email, type, entity);
66
        if (roleVerification != null) {
67
            deleteVerification(roleVerification.getId());
53 68
        }
54 69
    }
55 70

  
56 71
    public void deleteVerification(String id) {
57
        actions.deleteVerificationEntry(id);
72
        actions.delete(id);
58 73
    }
59 74

  
60
    public JsonArray getInvitedUsers(String type, String id) {
61
        List<String> emails = actions.getVerificationsForAnEntity(type, id);
75
    public JsonArray getInvitedManagers(String type, String id) {
76
        List<String> emails = actions.getInvitedManagers(type, id);
62 77
        JsonArray users = new JsonArray();
63 78
        emails.forEach(users::add);
64 79
        return users;
65 80
    }
66 81

  
67
    public ManagerVerification getVerification(String id) {
68
        return actions.getManagerVerification(id);
82
    public JsonArray getInvitedMembers(String type, String id) {
83
        List<String> emails = actions.getInviteMembers(type, id);
84
        JsonArray users = new JsonArray();
85
        emails.forEach(users::add);
86
        return users;
69 87
    }
70 88

  
89
    public RoleVerification getVerification(String id) {
90
        return actions.get(id);
91
    }
92

  
71 93
    public boolean exists(String id) {
72
        return actions.verificationEntryExists(id);
94
        return actions.exists(id);
73 95
    }
74 96

  
75 97
    public boolean ownedVerification(String id) {
76 98
        try {
77
            ManagerVerification managerVerification = getVerification(id);
99
            RoleVerification managerVerification = getVerification(id);
78 100
            if (managerVerification != null) {
79 101
                OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
80 102
                String email = authentication.getUserInfo().getEmail().toLowerCase();
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/RegistryCalls.java
125 125
        JsonArray roles = getRoles(coPersonId);
126 126
        for (JsonElement role : roles) {
127 127
            JsonObject object = role.getAsJsonObject();
128
            if (object.get("CouId").getAsInt() == couId) {
128
            if (object.get("CouId").getAsInt() == couId && !object.get("Status").getAsString().equals("Deleted")) {
129 129
                return object.get("Id").getAsInt();
130 130
            }
131 131
        }
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/JsonUtils.java
3 3
import com.google.gson.JsonArray;
4 4
import com.google.gson.JsonElement;
5 5
import com.google.gson.JsonObject;
6
import eu.dnetlib.openaire.user.pojos.ManagerVerification;
6
import eu.dnetlib.openaire.user.pojos.RoleVerification;
7 7
import eu.dnetlib.openaire.usermanagement.dto.Role;
8 8
import org.springframework.beans.factory.annotation.Value;
9 9
import org.springframework.stereotype.Component;
10 10

  
11
import java.sql.Timestamp;
12
import java.util.Date;
13

  
14 11
@Component
15 12
public class JsonUtils {
16 13

  
......
79 76
        return cou;
80 77
    }
81 78

  
82
    public JsonObject createVerification(ManagerVerification managerVerification) {
79
    public JsonObject createVerification(RoleVerification roleVerification) {
83 80
        JsonObject verification = new JsonObject();
84
        verification.addProperty("id", managerVerification.getId());
85
        verification.addProperty("email", managerVerification.getEmail());
86
        verification.addProperty("type", managerVerification.getType());
87
        verification.addProperty("entity", managerVerification.getEntity());
88
        verification.addProperty("date", managerVerification.getDate().getTime());
81
        verification.addProperty("id", roleVerification.getId());
82
        verification.addProperty("email", roleVerification.getEmail());
83
        verification.addProperty("type", roleVerification.getType());
84
        verification.addProperty("entity", roleVerification.getEntity());
85
        verification.addProperty("verificationType", roleVerification.getVerificationType());
86
        verification.addProperty("date", roleVerification.getDate().getTime());
89 87
        return verification;
90 88
    }
91 89

  
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/api/RegistryService.java
3 3
import com.google.gson.JsonArray;
4 4
import com.google.gson.JsonObject;
5 5
import com.google.gson.JsonParser;
6
import eu.dnetlib.openaire.user.pojos.ManagerVerification;
6
import eu.dnetlib.openaire.user.pojos.RoleVerification;
7 7
import eu.dnetlib.openaire.user.utils.EmailSender;
8 8
import eu.dnetlib.openaire.usermanagement.dto.Role;
9 9
import eu.dnetlib.openaire.usermanagement.utils.JsonUtils;
......
46 46
    @Path("/subscribe/{type}/{id}")
47 47
    @POST
48 48
    @Produces(MediaType.APPLICATION_JSON)
49
    @PreAuthorize("isAuthenticated()")
49
    @PreAuthorize("isAuthenticated() and @AuthorizationService.isCommunity(#type)")
50 50
    public Response subscribe(@PathParam("type") String type, @PathParam("id") String id) {
51 51
        Integer coPersonId = calls.getCoPersonIdByIdentifier();
52 52
        Integer couId = calls.getCouId(type, id);
......
60 60
    }
61 61

  
62 62
    /**
63
     * Subscribe from type(Community, etc.) with id(ee, egi, etc.).
63
     * Unsubscribe from type(Community, etc.) with id(ee, egi, etc.).
64 64
     * If user has manager role for this entity, it will be removed too.
65 65
     */
66 66
    @Path("/unsubscribe/{type}/{id}")
67 67
    @POST
68 68
    @Produces(MediaType.APPLICATION_JSON)
69
    @PreAuthorize("isAuthenticated()")
69
    @PreAuthorize("isAuthenticated() and @AuthorizationService.isCommunity(#type)")
70 70
    public Response unsubscribe(@PathParam("type") String type, @PathParam("id") String id) {
71 71
        Integer coPersonId = calls.getCoPersonIdByIdentifier();
72 72
        Integer couId = calls.getCouId(type, id);
......
105 105
    @Produces(MediaType.APPLICATION_JSON)
106 106
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
107 107
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
108
    public Response inviteUser(@PathParam("type") String type, @PathParam("id") String id, @PathParam("email") String email, @RequestBody String body) {
108
    public Response inviteManager(@PathParam("type") String type, @PathParam("id") String id, @PathParam("email") String email, @RequestBody String body) {
109 109
        Integer couId = calls.getCouId(type, id);
110 110
        if (couId != null) {
111 111
            Integer coPersonId = calls.getCoPersonIdByEmail(email);
112
            if (calls.getUserAdminGroup(coPersonId, couId) == null) {
113
                JsonObject invitation = verificationUtils.createInvitation(email, type, id);
114
                String name = calls.getUserNames(coPersonId);
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 115
                JsonObject details = new JsonParser().parse(body).getAsJsonObject();
116
                String link = details.get("link").getAsString() + "/" + invitation.get("link").getAsString();
116
                String link = details.get("link").getAsString() + invitation.get("link").getAsString();
117 117
                String subject = "Invite to manage " + details.get("name").getAsString();
118
                String message = "<p>Hello " + name + ",</p>" +
118
                String message = "<p>Hello" + ((name != null)?(" " + name):"") + ",</p>" +
119 119
                        "<p> You have been invited to manage " + details.get("name").getAsString() + ". " +
120 120
                        "Use the verification code below to accept the invitation." +
121 121
                        "</p>" +
......
143 143
    }
144 144

  
145 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
    /**
146 192
     * Cancel invitation to user with email for managing a type(Community, etc.) with id(ee, egi, etc.)
147 193
     */
148 194
    @Path("/invite/{type}/{id}/manager/{email}")
......
150 196
    @Produces(MediaType.APPLICATION_JSON)
151 197
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
152 198
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
153
    public Response cancelUserInvitations(@PathParam("type") String type, @PathParam("id") String id, @PathParam("email") String email) {
199
    public Response cancelManagerInvitations(@PathParam("type") String type, @PathParam("id") String id, @PathParam("email") String email) {
154 200
        Integer couId = calls.getCouId(type, id);
155 201
        if (couId != null) {
156
            verificationUtils.deleteUserVerifications(email, type, id);
202
            verificationUtils.deleteManagerVerifications(email, type, id);
157 203
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Invitations have been deleted").toString()).type(MediaType.APPLICATION_JSON).build();
158 204
        } else {
159 205
            return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
......
161 207
    }
162 208

  
163 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
    /**
164 228
     * Get the invited managers for a type(Community, etc.) with id(ee, egi, etc.)
165 229
     */
166 230
    @Path("/invite/{type}/{id}/managers/")
......
169 233
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN, " +
170 234
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
171 235
    public Response getInvitedManagers(@PathParam("type") String type, @PathParam("id") String id) {
172
        JsonArray invited = verificationUtils.getInvitedUsers(type, id);
236
        JsonArray invited = verificationUtils.getInvitedManagers(type, id);
173 237
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(invited).toString()).type(MediaType.APPLICATION_JSON).build();
174 238
    }
175 239

  
176 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
    /**
177 254
     * Get the verification with a specific id only if it refers to the logged in user
178 255
     */
179 256
    @Path("verification/{id}")
......
181 258
    @Produces(MediaType.APPLICATION_JSON)
182 259
    @PreAuthorize("isAuthenticated()")
183 260
    public Response getVerification(@PathParam("id") String id) {
184
        ManagerVerification managerVerification = verificationUtils.getVerification(id);
185
        if (managerVerification != null) {
186
            if (calls.getCoPersonIdByEmail(managerVerification.getEmail()).equals(calls.getCoPersonIdByIdentifier())) {
187
                return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(jsonUtils.createVerification(managerVerification)).toString()).type(MediaType.APPLICATION_JSON).build();
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();
188 265
            } else {
189 266
                return Response.status(HttpStatus.FORBIDDEN.value()).entity(jsonUtils.createResponse("Forbidden verification").toString()).type(MediaType.APPLICATION_JSON).build();
190 267
            }
......
213 290
     * Verify the verification with the specific id, if the code is correct and it refers to the logged in user.
214 291
     * Manager role is assigned to this user, along with the member role.
215 292
     */
216
    @Path("verification/{id}")
293
    @Path("verification/manager/{id}")
217 294
    @POST
218 295
    @Produces(MediaType.APPLICATION_JSON)
219 296
    @PreAuthorize("isAuthenticated()")
220
    public Response verify(@PathParam("id") String id, @RequestBody String code) {
221
        ManagerVerification managerVerification = verificationUtils.getVerification(id);
222
        if (managerVerification != null) {
223
            Integer coPersonId = calls.getCoPersonIdByEmail(managerVerification.getEmail());
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());
224 301
            if (coPersonId != null) {
225 302
                if (coPersonId.equals(calls.getCoPersonIdByIdentifier())) {
226
                    if (managerVerification.getVerificationCode().equals(code)) {
227
                        verificationUtils.deleteRelatedVerifications(managerVerification);
228
                        Integer couId = calls.getCouId(managerVerification.getType(), managerVerification.getEntity());
303
                    if (verification.getVerificationCode().equals(code)) {
304
                        Integer couId = calls.getCouId(verification.getType(), verification.getEntity());
229 305
                        if (couId != null) {
230 306
                            Integer role = calls.getRoleId(coPersonId, couId);
231 307
                            calls.assignMemberRole(coPersonId, couId, role);
308
                            verificationUtils.deleteMemberVerifications(verification.getEmail(), verification.getType(), verification.getEntity());
232 309
                            if (calls.getUserAdminGroup(coPersonId, couId) == null) {
310
                                verificationUtils.deleteManagerVerifications(verification.getEmail(), verification.getType(), verification.getEntity());
233 311
                                calls.assignAdminRole(coPersonId, couId);
234 312
                                return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Admin role has been assigned").toString()).type(MediaType.APPLICATION_JSON).build();
235 313
                            } else {
......
253 331
    }
254 332

  
255 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
    /**
256 372
     * Remove the manager role from user with email for a type(Community, etc.) with id(ee, egi, etc.)
257 373
     */
258 374
    @Path("/{type}/{id}/manager/{email}")
......
278 394
    }
279 395

  
280 396
    /**
281
     * Get the names of the subscribers of a type(Community, etc.) with id(ee, egi, etc.)
397
     * Remove the member role from user with email for a type(Community, etc.) with id(ee, egi, etc.)
282 398
     */
283
    @Path("/{type}/{id}/subscribers")
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 = calls.getRoleId(coPersonId, couId);
411
            if (couId != null && role != null) {
412
                calls.removeAdminRole(coPersonId, couId);
413
                calls.removeMemberRole(coPersonId, couId, role);
414
                return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been removed").toString()).type(MediaType.APPLICATION_JSON).build();
415
            } else {
416
                return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
417
            }
418
        } else {
419
            return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("User has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
420
        }
421
    }
422

  
423
    /**
424
     * Get the names of the members of a type(Community, etc.) with id(ee, egi, etc.)
425
     */
426
    @Path("/{type}/{id}/members")
284 427
    @GET
285 428
    @Produces(MediaType.APPLICATION_JSON)
286 429
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN," +
287 430
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
288
    public Response getSubscribers(@PathParam("type") String type, @PathParam("id") String id) {
431
    public Response getMembers(@PathParam("type") String type, @PathParam("id") String id) {
289 432
        Integer couId = calls.getCouId(type, id);
290 433
        JsonArray subscribers = calls.getUserNamesByCouId(couId, false);
291 434
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(subscribers).toString()).type(MediaType.APPLICATION_JSON).build();
292 435
    }
293 436

  
294 437
    /**
295
     * Get the emails of the subscribers of a type(Community, etc.) with id(ee, egi, etc.)
438
     * Get the emails of the members of a type(Community, etc.) with id(ee, egi, etc.)
296 439
     */
297
    @Path("/{type}/{id}/subscribers/email")
440
    @Path("/{type}/{id}/members/email")
298 441
    @GET
299 442
    @Produces(MediaType.APPLICATION_JSON)
300 443
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN," +
301 444
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
302
    public Response getSubscribersEmail(@PathParam("type") String type, @PathParam("id") String id) {
445
    public Response getMembersEmail(@PathParam("type") String type, @PathParam("id") String id) {
303 446
        Integer couId = calls.getCouId(type, id);
304 447
        JsonArray subscribers = calls.getUserEmailByCouId(couId, false);
305 448
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(subscribers).toString()).type(MediaType.APPLICATION_JSON).build();
306 449
    }
307 450

  
308 451
    /**
309
     * Get the number of the subscribers of a type(Community, etc.) with id(ee, egi, etc.)
452
     * Get the number of the members of a type(Community, etc.) with id(ee, egi, etc.)
310 453
     */
311
    @Path("/{type}/{id}/subscribers/count")
454
    @Path("/{type}/{id}/members/count")
312 455
    @GET
313 456
    @Produces(MediaType.APPLICATION_JSON)
314
    public Response getSubscribersCount(@PathParam("type") String type, @PathParam("id") String id) {
457
    public Response getMembersCount(@PathParam("type") String type, @PathParam("id") String id) {
315 458
        Integer couId = calls.getCouId(type, id);
316 459
        int count = calls.getUserNamesByCouId(couId, false).size();
317 460
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(count).toString()).type(MediaType.APPLICATION_JSON).build();

Also available in: Unified diff