use of org.apache.cloudstack.acl.ProjectRolePermission in project cloudstack by apache.
the class CreateProjectRolePermissionCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
ProjectRole projectRole = projRoleService.findProjectRole(getProjectRoleId(), getProjectId());
if (projectRole == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid project role ID provided");
}
CallContext.current().setEventDetails("Project Role ID: " + projectRole.getId() + ", Rule:" + getRule() + ", Permission: " + getPermission() + ", Description: " + getDescription());
final ProjectRolePermission projectRolePermission = projRoleService.createProjectRolePermission(this);
if (projectRolePermission == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create project role permission");
}
setupResponse(projectRolePermission, projectRole);
}
use of org.apache.cloudstack.acl.ProjectRolePermission in project cloudstack by apache.
the class DeleteProjectRolePermissionCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
ProjectRolePermission rolePermission = projRoleService.findProjectRolePermission(getProjectRolePermissionId());
if (rolePermission == null || rolePermission.getProjectId() != getProjectId()) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role permission id provided for the project");
}
CallContext.current().setEventDetails("Deleting Project Role permission with id: " + rolePermission.getId());
boolean result = projRoleService.deleteProjectRolePermission(rolePermission);
SuccessResponse response = new SuccessResponse();
response.setSuccess(result);
setResponseObject(response);
}
use of org.apache.cloudstack.acl.ProjectRolePermission in project cloudstack by apache.
the class UpdateProjectRolePermissionCmd method updateProjectRolePermissionOrder.
private boolean updateProjectRolePermissionOrder(ProjectRole projectRole) {
final List<ProjectRolePermission> rolePermissionsOrder = new ArrayList<>();
for (Long rolePermissionId : getProjectRulePermissionOrder()) {
final ProjectRolePermission rolePermission = projRoleService.findProjectRolePermission(rolePermissionId);
if (rolePermission == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Provided project role permission(s) do not exist");
}
rolePermissionsOrder.add(rolePermission);
}
return projRoleService.updateProjectRolePermission(projectId, projectRole, rolePermissionsOrder);
}
use of org.apache.cloudstack.acl.ProjectRolePermission in project cloudstack by apache.
the class ListProjectRolePermissionsCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
List<ProjectRolePermission> projectRolePermissions = projRoleService.findAllProjectRolePermissions(getProjectId(), getProjectRoleId());
final ProjectRole projectRole = projRoleService.findProjectRole(getProjectRoleId(), getProjectId());
final ListResponse<ProjectRolePermissionResponse> response = new ListResponse<>();
final List<ProjectRolePermissionResponse> rolePermissionResponses = new ArrayList<>();
for (final ProjectRolePermission rolePermission : projectRolePermissions) {
ProjectRole role = projectRole;
if (role == null) {
role = projRoleService.findProjectRole(rolePermission.getProjectRoleId(), rolePermission.getProjectId());
}
rolePermissionResponses.add(setupResponse(role, rolePermission));
}
response.setResponses(rolePermissionResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.acl.ProjectRolePermission in project cloudstack by apache.
the class UpdateProjectRolePermissionCmd method execute.
// ///////////////////////////////////////////////////
// ///////////////// API Implementation //////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
ProjectRole projectRole = projRoleService.findProjectRole(getProjectRoleId(), getProjectId());
boolean result = false;
if (projectRole == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid role id provided");
}
if (getProjectRulePermissionOrder() != null) {
if (getProjectRuleId() != null || getProjectRolePermission() != null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Parameters permission and ruleid must be mutually exclusive with ruleorder");
}
CallContext.current().setEventDetails("Reordering permissions for role id: " + projectRole.getId());
result = updateProjectRolePermissionOrder(projectRole);
} else if (getProjectRuleId() != null || getProjectRolePermission() != null) {
if (getProjectRulePermissionOrder() != null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Parameters permission and ruleid must be mutually exclusive with ruleorder");
}
ProjectRolePermission rolePermission = getValidProjectRolePermission();
CallContext.current().setEventDetails("Updating project role permission for rule id: " + getProjectRuleId() + " to: " + getProjectRolePermission().toString());
result = projRoleService.updateProjectRolePermission(projectId, projectRole, rolePermission, getProjectRolePermission());
}
SuccessResponse response = new SuccessResponse(getCommandName());
response.setSuccess(result);
setResponseObject(response);
}
Aggregations