Skip to content

Commit 655fcc9

Browse files
author
Boris Schrijver
committed
Made interface changes related to CLOUDSTACK-8580
Added responses to ListCapabilities to reflect CLOUDSTACK-8580 changes. This to add these options to the gui. See issue CLOUDSTACK-8580. https://github.com/kevindierkx/cloudstack/commit/3be14e978aa0c9b286d9f57bf1fc60ebe50990c7 Removed comments as proposed by Daan Hoogland.
1 parent fa56b3f commit 655fcc9

6 files changed

Lines changed: 38 additions & 15 deletions

File tree

‎api/src/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818

1919
import java.util.Map;
2020

21-
import org.apache.log4j.Logger;
22-
2321
import org.apache.cloudstack.api.APICommand;
2422
import org.apache.cloudstack.api.BaseCmd;
2523
import org.apache.cloudstack.api.response.CapabilitiesResponse;
24+
import org.apache.log4j.Logger;
2625

2726
import com.cloud.user.Account;
2827

@@ -57,6 +56,8 @@ public void execute() {
5756
response.setDiskOffMaxSize((Long)capabilities.get("customDiskOffMaxSize"));
5857
response.setRegionSecondaryEnabled((Boolean)capabilities.get("regionSecondaryEnabled"));
5958
response.setKVMSnapshotEnabled((Boolean)capabilities.get("KVMSnapshotEnabled"));
59+
response.setAllowUserViewDestroyedVM((Boolean)capabilities.get("allowUserViewDestroyedVM"));
60+
response.setAllowUserExpungeRecoverVM((Boolean)capabilities.get("allowUserExpungeRecoverVM"));
6061
if (capabilities.containsKey("apiLimitInterval")) {
6162
response.setApiLimitInterval((Integer)capabilities.get("apiLimitInterval"));
6263
}

‎api/src/org/apache/cloudstack/api/response/CapabilitiesResponse.java‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.response;
1818

19-
import com.google.gson.annotations.SerializedName;
20-
2119
import org.apache.cloudstack.api.ApiConstants;
2220
import org.apache.cloudstack.api.BaseResponse;
2321

2422
import com.cloud.serializer.Param;
23+
import com.google.gson.annotations.SerializedName;
2524

2625
@SuppressWarnings("unused")
2726
public class CapabilitiesResponse extends BaseResponse {
@@ -73,6 +72,14 @@ public class CapabilitiesResponse extends BaseResponse {
7372
@Param(description = "Max allowed number of api requests within the specified interval")
7473
private Integer apiLimitMax;
7574

75+
@SerializedName("allowuserviewdestroyedvm")
76+
@Param(description = "true if the user is allowed to view destroyed virtualmachines, false otherwise", since = "4.6.0")
77+
private boolean allowUserViewDestroyedVM;
78+
79+
@SerializedName("allowuserexpungerecovervm")
80+
@Param(description = "true if the user can recover and expunge virtualmachines, false otherwise", since = "4.6.0")
81+
private boolean allowUserExpungeRecoverVM;
82+
7683
public void setSecurityGroupsEnabled(boolean securityGroupsEnabled) {
7784
this.securityGroupsEnabled = securityGroupsEnabled;
7885
}
@@ -121,4 +128,11 @@ public void setApiLimitMax(Integer apiLimitMax) {
121128
this.apiLimitMax = apiLimitMax;
122129
}
123130

124-
}
131+
public void setAllowUserViewDestroyedVM(boolean allowUserViewDestroyedVM) {
132+
this.allowUserViewDestroyedVM = allowUserViewDestroyedVM;
133+
}
134+
135+
public void setAllowUserExpungeRecoverVM(boolean allowUserExpungeRecoverVM) {
136+
this.allowUserExpungeRecoverVM = allowUserExpungeRecoverVM;
137+
}
138+
}

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@
525525
import com.cloud.alert.AlertVO;
526526
import com.cloud.alert.dao.AlertDao;
527527
import com.cloud.api.ApiDBUtils;
528+
import com.cloud.api.query.QueryManagerImpl;
528529
import com.cloud.capacity.Capacity;
529530
import com.cloud.capacity.CapacityVO;
530531
import com.cloud.capacity.dao.CapacityDao;
@@ -3378,6 +3379,9 @@ public Map<String, Object> listCapabilities(final ListCapabilitiesCmd cmd) {
33783379
final Integer apiLimitInterval = Integer.valueOf(_configDao.getValue(Config.ApiLimitInterval.key()));
33793380
final Integer apiLimitMax = Integer.valueOf(_configDao.getValue(Config.ApiLimitMax.key()));
33803381

3382+
final boolean allowUserViewDestroyedVM = (QueryManagerImpl.AllowUserViewDestroyedVM.valueIn(caller.getId()) | _accountService.isAdmin(caller.getId()));
3383+
final boolean allowUserExpungeRecoverVM = (UserVmManager.AllowUserExpungeRecoverVm.valueIn(caller.getId()) | _accountService.isAdmin(caller.getId()));
3384+
33813385
// check if region-wide secondary storage is used
33823386
boolean regionSecondaryEnabled = false;
33833387
final List<ImageStoreVO> imgStores = _imgStoreDao.findRegionImageStores();
@@ -3395,6 +3399,8 @@ public Map<String, Object> listCapabilities(final ListCapabilitiesCmd cmd) {
33953399
capabilities.put("customDiskOffMaxSize", diskOffMaxSize);
33963400
capabilities.put("regionSecondaryEnabled", regionSecondaryEnabled);
33973401
capabilities.put("KVMSnapshotEnabled", KVMSnapshotEnabled);
3402+
capabilities.put("allowUserViewDestroyedVM", allowUserViewDestroyedVM);
3403+
capabilities.put("allowUserExpungeRecoverVM", allowUserExpungeRecoverVM);
33983404
if (apiLimitEnabled) {
33993405
capabilities.put("apiLimitInterval", apiLimitInterval);
34003406
capabilities.put("apiLimitMax", apiLimitMax);

‎ui/scripts/cloudStack.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@
143143
if (json.listcapabilitiesresponse.capability.userpublictemplateenabled != null) {
144144
g_userPublicTemplateEnabled = json.listcapabilitiesresponse.capability.userpublictemplateenabled.toString(); //convert boolean to string if it's boolean
145145
}
146-
g_userProjectsEnabled = json.listcapabilitiesresponse.capability.allowusercreateprojects;
147146

147+
g_allowUserExpungeRecoverVm = json.listcapabilitiesresponse.capability.allowuserexpungerecovervm;
148+
g_userProjectsEnabled = json.listcapabilitiesresponse.capability.allowusercreateprojects;
148149

149150
g_cloudstackversion = json.listcapabilitiesresponse.capability.cloudstackversion;
150151

@@ -274,9 +275,9 @@
274275
if (json.listcapabilitiesresponse.capability.userpublictemplateenabled != null) {
275276
g_userPublicTemplateEnabled = json.listcapabilitiesresponse.capability.userpublictemplateenabled.toString(); //convert boolean to string if it's boolean
276277
}
278+
g_allowUserExpungeRecoverVm = json.listcapabilitiesresponse.capability.allowuserexpungerecovervm;
277279
g_userProjectsEnabled = json.listcapabilitiesresponse.capability.allowusercreateprojects;
278280

279-
280281
g_cloudstackversion = json.listcapabilitiesresponse.capability.cloudstackversion;
281282

282283
if (json.listcapabilitiesresponse.capability.apilimitinterval != null && json.listcapabilitiesresponse.capability.apilimitmax != null) {

‎ui/scripts/instances.js‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,9 @@
618618
createForm: {
619619
title: 'label.action.destroy.instance',
620620
desc: 'label.action.destroy.instance',
621-
isWarning: true,
621+
isWarning: true,
622622
preFilter: function(args) {
623-
if (isAdmin() || isDomainAdmin()) {
624-
args.$form.find('.form-item[rel=expunge]').css('display', 'inline-block');
625-
} else {
623+
if (! g_allowUserExpungeRecoverVm) {
626624
args.$form.find('.form-item[rel=expunge]').hide();
627625
}
628626
},
@@ -2425,11 +2423,13 @@
24252423
var allowedActions = [];
24262424

24272425
if (jsonObj.state == 'Destroyed') {
2428-
if (isAdmin() || isDomainAdmin()) {
2426+
if (g_allowUserExpungeRecoverVm) {
24292427
allowedActions.push("recover");
24302428
}
2431-
if (isAdmin() || isDomainAdmin())
2429+
2430+
if (g_allowUserExpungeRecoverVm) {
24322431
allowedActions.push("expunge");
2432+
}
24332433
} else if (jsonObj.state == 'Running') {
24342434
allowedActions.push("stop");
24352435
allowedActions.push("restart");
@@ -2498,8 +2498,9 @@
24982498
} else if (jsonObj.state == 'Error') {
24992499
allowedActions.push("destroy");
25002500
} else if (jsonObj.state == 'Expunging') {
2501-
if (isAdmin() || isDomainAdmin())
2501+
if (g_allowUserExpungeRecoverVm) {
25022502
allowedActions.push("expunge");
2503+
}
25032504
}
25042505
return allowedActions;
25052506
}

‎ui/scripts/sharedFunctions.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var g_supportELB = null;
3030
var g_kvmsnapshotenabled = null;
3131
var g_regionsecondaryenabled = null;
3232
var g_userPublicTemplateEnabled = "true";
33+
var g_allowUserExpungeRecoverVm = "false";
3334
var g_cloudstackversion = null;
3435
var g_queryAsyncJobResultInterval = 3000;
3536
var g_idpList = null;
@@ -2332,4 +2333,3 @@ $.validator.addMethod("ipv4cidr", function(value, element) {
23322333

23332334
return true;
23342335
}, "The specified IPv4 CIDR is invalid.");
2335-

0 commit comments

Comments
 (0)