Skip to content

Commit d3b292a

Browse files
authored
server: Fixes API permissions, global settings and template UX (#3534)
Fixes: - This allows getUploadParamsForIso for all user role types, also fixes authorised field for getUploadParamsForTemplate API. - Fix global setting description to say what is used when value is empty/blank. - For VM running/allocated usage description, use parenthesis to return the instance name and ID. - Display template download progress when template is added to a project Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent b2db897 commit d3b292a

5 files changed

Lines changed: 20 additions & 12 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.iso;
1818

19-
import com.cloud.exception.ConcurrentOperationException;
20-
import com.cloud.exception.InsufficientCapacityException;
21-
import com.cloud.exception.NetworkRuleConflictException;
22-
import com.cloud.exception.ResourceAllocationException;
23-
import com.cloud.exception.ResourceUnavailableException;
19+
import java.net.MalformedURLException;
20+
21+
import org.apache.cloudstack.acl.RoleType;
2422
import org.apache.cloudstack.api.APICommand;
2523
import org.apache.cloudstack.api.AbstractGetUploadParamsCmd;
2624
import org.apache.cloudstack.api.ApiConstants;
@@ -33,11 +31,16 @@
3331
import org.apache.cloudstack.api.response.ZoneResponse;
3432
import org.apache.cloudstack.context.CallContext;
3533

36-
import java.net.MalformedURLException;
34+
import com.cloud.exception.ConcurrentOperationException;
35+
import com.cloud.exception.InsufficientCapacityException;
36+
import com.cloud.exception.NetworkRuleConflictException;
37+
import com.cloud.exception.ResourceAllocationException;
38+
import com.cloud.exception.ResourceUnavailableException;
3739

3840
@APICommand(name = GetUploadParamsForIsoCmd.APINAME,
3941
description = "upload an existing ISO into the CloudStack cloud.",
4042
responseObject = GetUploadParamsResponse.class, since = "4.13",
43+
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User},
4144
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
4245
public class GetUploadParamsForIsoCmd extends AbstractGetUploadParamsCmd {
4346

api/src/main/java/org/apache/cloudstack/api/command/user/template/GetUploadParamsForTemplateCmd.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Collection;
2323
import java.util.Map;
2424

25+
import org.apache.cloudstack.acl.RoleType;
2526
import org.apache.cloudstack.api.APICommand;
2627
import org.apache.cloudstack.api.AbstractGetUploadParamsCmd;
2728
import org.apache.cloudstack.api.ApiConstants;
@@ -35,8 +36,10 @@
3536

3637
import com.cloud.exception.ResourceAllocationException;
3738

38-
@APICommand(name = "getUploadParamsForTemplate", description = "upload an existing template into the CloudStack cloud. ", responseObject = GetUploadParamsResponse.class, since =
39-
"4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
39+
@APICommand(name = "getUploadParamsForTemplate", description = "upload an existing template into the CloudStack cloud. ",
40+
responseObject = GetUploadParamsResponse.class, since = "4.6.0",
41+
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User},
42+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
4043
public class GetUploadParamsForTemplateCmd extends AbstractGetUploadParamsCmd {
4144
public static final Logger s_logger = Logger.getLogger(GetUploadParamsForTemplateCmd.class.getName());
4245

api/src/main/java/org/apache/cloudstack/query/QueryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public interface QueryService {
9292

9393
static final ConfigKey<String> UserVMBlacklistedDetails = new ConfigKey<String>("Advanced", String.class,
9494
"user.vm.blacklisted.details", "rootdisksize, cpuOvercommitRatio, memoryOvercommitRatio, Message.ReservedCapacityFreed.Flag",
95-
"Determines whether users can view certain VM settings", true);
95+
"Determines whether users can view certain VM settings. When set to empty, default value used is: rootdisksize, cpuOvercommitRatio, memoryOvercommitRatio, Message.ReservedCapacityFreed.Flag.", true);
9696

9797
static final ConfigKey<String> UserVMReadOnlyUIDetails = new ConfigKey<String>("Advanced", String.class,
9898
"user.vm.readonly.ui.details", "dataDiskController, rootDiskController",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3373,7 +3373,7 @@ public UsageRecordResponse createUsageResponse(Usage usageRecord, Map<String, Se
33733373
builder.append("Allocated VM usage ");
33743374
}
33753375
if (vm != null) {
3376-
builder.append("for ").append(vm.getHostName()).append(" (").append(vm.getInstanceName()).append(", ").append(vm.getUuid()).append(") ");
3376+
builder.append("for ").append(vm.getHostName()).append(" (").append(vm.getInstanceName()).append(") (").append(vm.getUuid()).append(") ");
33773377
}
33783378
if (svcOffering != null) {
33793379
builder.append("using service offering ").append(svcOffering.getName()).append(" (").append(svcOffering.getUuid()).append(") ");

server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@ public TemplateResponse newTemplateResponse(ResponseView view, TemplateJoinVO te
166166
templateResponse.setDomainId(template.getDomainUuid());
167167
templateResponse.setDomainName(template.getDomainName());
168168

169-
// If the user is an 'Admin' or 'the owner of template', add the template download status
170-
if (view == ResponseView.Full || template.getAccountId() == CallContext.current().getCallingAccount().getId() ) {
169+
// If the user is an 'Admin' or 'the owner of template' or template belongs to a project, add the template download status
170+
if (view == ResponseView.Full ||
171+
template.getAccountId() == CallContext.current().getCallingAccount().getId() ||
172+
template.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) {
171173
String templateStatus = getTemplateStatus(template);
172174
if (templateStatus != null) {
173175
templateResponse.setStatus(templateStatus);

0 commit comments

Comments
 (0)