Skip to content

Commit b413a62

Browse files
committed
1) replaced joinProject API with updateProjectInvitation api. You can accept/decline the invitataion with this command
2) Added deleteProjectInviation command. Can be executed by project admin only
1 parent eb0fdc2 commit b413a62

23 files changed

Lines changed: 238 additions & 69 deletions

api/src/com/cloud/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,6 @@ public class ApiConstants {
268268
public static final String USER = "user";
269269
public static final String ACTIVE_ONLY = "activeonly";
270270
public static final String TOKEN = "token";
271+
public static final String ACCEPT = "accept";
271272

272273
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
package com.cloud.api.commands;
19+
20+
import org.apache.log4j.Logger;
21+
22+
import com.cloud.api.ApiConstants;
23+
import com.cloud.api.BaseAsyncCmd;
24+
import com.cloud.api.BaseCmd;
25+
import com.cloud.api.Implementation;
26+
import com.cloud.api.Parameter;
27+
import com.cloud.api.ServerApiException;
28+
import com.cloud.api.response.SuccessResponse;
29+
import com.cloud.event.EventTypes;
30+
import com.cloud.user.Account;
31+
import com.cloud.user.UserContext;
32+
33+
@Implementation(description="Accepts or declines project invitation", responseObject=SuccessResponse.class)
34+
public class DeleteProjectInvitationCmd extends BaseAsyncCmd {
35+
public static final Logger s_logger = Logger.getLogger(DeleteProjectInvitationCmd.class.getName());
36+
private static final String s_name = "deleteprojectinvitationresponse";
37+
38+
/////////////////////////////////////////////////////
39+
//////////////// API parameters /////////////////////
40+
/////////////////////////////////////////////////////
41+
@Parameter(name=ApiConstants.ID, required=true, type=CommandType.LONG, description="id of the invitation")
42+
private Long id;
43+
44+
/////////////////////////////////////////////////////
45+
/////////////////// Accessors ///////////////////////
46+
/////////////////////////////////////////////////////
47+
public Long getId() {
48+
return id;
49+
}
50+
51+
@Override
52+
public String getCommandName() {
53+
return s_name;
54+
}
55+
56+
/////////////////////////////////////////////////////
57+
/////////////// API Implementation///////////////////
58+
/////////////////////////////////////////////////////
59+
@Override
60+
public long getEntityOwnerId() {
61+
//TODO - return project entity ownerId
62+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
63+
}
64+
65+
66+
@Override
67+
public void execute(){
68+
UserContext.current().setEventDetails("Project invitation id " + id);
69+
boolean result = _projectService.deleteProjectInvitation(id);
70+
if (result) {
71+
SuccessResponse response = new SuccessResponse(getCommandName());
72+
this.setResponseObject(response);
73+
} else {
74+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete the project invitation");
75+
}
76+
}
77+
78+
@Override
79+
public String getEventType() {
80+
return EventTypes.EVENT_PROJECT_INVITATION_REMOVE;
81+
}
82+
83+
@Override
84+
public String getEventDescription() {
85+
return "Project invitatino id " + id + " is being removed";
86+
}
87+
}

api/src/com/cloud/api/commands/ListProjectInvitationsCmd.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public class ListProjectInvitationsCmd extends BaseListCmd {
5252

5353
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list invitations by state")
5454
private String state;
55+
56+
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list invitations by id")
57+
private Long id;
5558
/////////////////////////////////////////////////////
5659
/////////////////// Accessors ///////////////////////
5760
/////////////////////////////////////////////////////
@@ -75,6 +78,10 @@ public String getState() {
7578
return state;
7679
}
7780

81+
public Long getId() {
82+
return id;
83+
}
84+
7885
@Override
7986
public String getCommandName() {
8087
return s_name;
@@ -86,7 +93,7 @@ public String getCommandName() {
8693

8794
@Override
8895
public void execute(){
89-
List<? extends ProjectInvitation> invites = _projectService.listProjectInvitations(projectId, accountName, domainId, state, activeOnly, this.getStartIndex(), this.getPageSizeVal());
96+
List<? extends ProjectInvitation> invites = _projectService.listProjectInvitations(id, projectId, accountName, domainId, state, activeOnly, this.getStartIndex(), this.getPageSizeVal());
9097
ListResponse<ProjectInvitationResponse> response = new ListResponse<ProjectInvitationResponse>();
9198
List<ProjectInvitationResponse> projectInvitationResponses = new ArrayList<ProjectInvitationResponse>();
9299
for (ProjectInvitation invite : invites) {

api/src/com/cloud/api/commands/JoinProjectCmd.java renamed to api/src/com/cloud/api/commands/UpdateProjectInvitationCmd.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,26 @@
3030
import com.cloud.user.Account;
3131
import com.cloud.user.UserContext;
3232

33-
@Implementation(description="Makes account to join the project", responseObject=SuccessResponse.class)
34-
public class JoinProjectCmd extends BaseAsyncCmd {
35-
public static final Logger s_logger = Logger.getLogger(JoinProjectCmd.class.getName());
36-
private static final String s_name = "joinprojectresponse";
33+
@Implementation(description="Accepts or declines project invitation", responseObject=SuccessResponse.class)
34+
public class UpdateProjectInvitationCmd extends BaseAsyncCmd {
35+
public static final Logger s_logger = Logger.getLogger(UpdateProjectInvitationCmd.class.getName());
36+
private static final String s_name = "updateprojectinvitationresponse";
37+
3738

3839
/////////////////////////////////////////////////////
3940
//////////////// API parameters /////////////////////
4041
/////////////////////////////////////////////////////
4142
@Parameter(name=ApiConstants.PROJECT_ID, required=true, type=CommandType.LONG, description="id of the project to join")
4243
private Long projectId;
4344

44-
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true, description="account that is joining the project")
45+
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account that is joining the project")
4546
private String accountName;
4647

4748
@Parameter(name=ApiConstants.TOKEN, type=CommandType.STRING, description="list invitations for specified account; this parameter has to be specified with domainId")
4849
private String token;
50+
51+
@Parameter(name=ApiConstants.ACCEPT, type=CommandType.BOOLEAN, description="if true, accept the invitation, decline if false. True by default")
52+
private Boolean accept;
4953

5054
/////////////////////////////////////////////////////
5155
/////////////////// Accessors ///////////////////////
@@ -67,10 +71,17 @@ public String getToken() {
6771
return token;
6872
}
6973

74+
public Boolean getAccept() {
75+
if (accept == null) {
76+
return true;
77+
}
78+
return accept;
79+
}
80+
81+
7082
/////////////////////////////////////////////////////
7183
/////////////// API Implementation///////////////////
7284
/////////////////////////////////////////////////////
73-
7485
@Override
7586
public long getEntityOwnerId() {
7687
//TODO - return project entity ownerId
@@ -80,8 +91,8 @@ public long getEntityOwnerId() {
8091

8192
@Override
8293
public void execute(){
83-
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName);
84-
boolean result = _projectService.joinProject(projectId, accountName, token);
94+
UserContext.current().setEventDetails("Project id: "+ projectId + "; accountName " + accountName + "; accept " + getAccept());
95+
boolean result = _projectService.updateInvitation(projectId, accountName, token, getAccept());
8596
if (result) {
8697
SuccessResponse response = new SuccessResponse(getCommandName());
8798
this.setResponseObject(response);
@@ -92,11 +103,11 @@ public void execute(){
92103

93104
@Override
94105
public String getEventType() {
95-
return EventTypes.EVENT_PROJECT_JOIN;
106+
return EventTypes.EVENT_PROJECT_INVITATION_UPDATE;
96107
}
97108

98109
@Override
99110
public String getEventDescription() {
100-
return "Account " + accountName + " joining the project: " + projectId;
111+
return "Updating project invitation for projectId " + projectId;
101112
}
102113
}

api/src/com/cloud/api/response/ProjectInvitationResponse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
@SuppressWarnings("unused")
88
public class ProjectInvitationResponse extends BaseResponse implements ControlledEntityResponse{
9+
@SerializedName(ApiConstants.ID) @Param(description="the id of the invitation")
10+
private Long id;
11+
912
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="the id of the project")
1013
private Long projectId;
1114

@@ -26,6 +29,10 @@ public class ProjectInvitationResponse extends BaseResponse implements Controlle
2629

2730
@SerializedName(ApiConstants.STATE) @Param(description="the invitation state")
2831
private String invitationState;
32+
33+
public void setId(Long id) {
34+
this.id = id;
35+
}
2936

3037
public void setProjectId(Long projectId) {
3138
this.projectId = projectId;

api/src/com/cloud/event/EventTypes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public class EventTypes {
212212
public static final String EVENT_PROJECT_ACTIVATE = "PROJECT.ACTIVATE";
213213
public static final String EVENT_PROJECT_SUSPEND = "PROJECT.SUSPEND";
214214
public static final String EVENT_PROJECT_ACCOUNT_ADD = "PROJECT.ACCOUNT.ADD";
215-
public static final String EVENT_PROJECT_JOIN = "PROJECT.JOIN";
215+
public static final String EVENT_PROJECT_INVITATION_UPDATE = "PROJECT.INVITATION.UPDATE";
216+
public static final String EVENT_PROJECT_INVITATION_REMOVE = "PROJECT.INVITATION.REMOVE";
216217
public static final String EVENT_PROJECT_ACCOUNT_REMOVE = "PROJECT.ACCOUNT.REMOVE";
217218
}

api/src/com/cloud/projects/ProjectInvitation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.Date;
44

55
public interface ProjectInvitation {
6-
public enum State {Pending, Completed, Expired}
6+
public enum State {Pending, Completed, Expired, Declined}
77

88
long getId();
99

api/src/com/cloud/projects/ProjectService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ public interface ProjectService {
5858

5959
List<? extends ProjectAccount> listProjectAccounts(long projectId, String accountName, String role, Long startIndex, Long pageSizeVal);
6060

61-
List<? extends ProjectInvitation> listProjectInvitations(Long projectId, String accountName, Long domainId, String state, boolean activeOnly, Long startIndex, Long pageSizeVal);
61+
List<? extends ProjectInvitation> listProjectInvitations(Long id, Long projectId, String accountName, Long domainId, String state, boolean activeOnly, Long startIndex, Long pageSizeVal);
6262

63-
boolean joinProject(long projectId, String accountName, String token);
63+
boolean updateInvitation(long projectId, String accountName, String token, boolean accept);
6464

6565
Project activateProject(long projectId);
6666

6767
Project suspendProject(long projectId) throws ConcurrentOperationException, ResourceUnavailableException;
6868

6969
Project enableProject(long projectId);
70+
71+
boolean deleteProjectInvitation(long invitationId);
7072
}

client/tomcatconf/commands.properties.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ addAccountToProject=com.cloud.api.commands.AddAccountToProjectCmd;15
278278
deleteAccountFromProject=com.cloud.api.commands.DeleteAccountFromProjectCmd;15
279279
listProjectAccounts=com.cloud.api.commands.ListProjectAccountsCmd;15
280280
listProjectInvitations=com.cloud.api.commands.ListProjectInvitationsCmd;15
281-
joinProject=com.cloud.api.commands.JoinProjectCmd;15
281+
updateProjectInvitation=com.cloud.api.commands.UpdateProjectInvitationCmd;15
282+
deleteProjectInvitation=com.cloud.api.commands.DeleteProjectInvitationCmd;15
282283

283284
####
284285
createFirewallRule=com.cloud.api.commands.CreateFirewallRuleCmd;15

server/src/com/cloud/api/ApiResponseHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,6 +2540,7 @@ public ProjectAccountResponse createProjectAccountResponse(ProjectAccount projec
25402540
@Override
25412541
public ProjectInvitationResponse createProjectInvitationResponse(ProjectInvitation invite) {
25422542
ProjectInvitationResponse response = new ProjectInvitationResponse();
2543+
response.setId(invite.getId());
25432544
response.setProjectId(invite.getProjectId());
25442545
response.setProjectName(ApiDBUtils.findProjectById(invite.getProjectId()).getName());
25452546
response.setInvitationState(invite.getState().toString());

0 commit comments

Comments
 (0)