Skip to content

Commit a3c80eb

Browse files
author
Jessica Wang
committed
CLOUDSTACK-109: cloudstack UI - (1) detailView widget - pass context to isEditable() when calling it. (2) account page - Edit action - allow to update network domain on system-generated default admin account.
1 parent 309be01 commit a3c80eb

2 files changed

Lines changed: 101 additions & 63 deletions

File tree

ui/scripts/accounts.js

Lines changed: 100 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -282,59 +282,71 @@
282282

283283
});
284284

285-
$.ajax({
286-
url: createURL("updateResourceLimit&resourceType=0&max=" + todb(args.data.vmLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
287-
dataType: "json",
288-
async: false,
289-
success: function(json) {
290-
accountObj["vmLimit"] = args.data.vmLimit;
291-
}
292-
});
293-
294-
$.ajax({
295-
url: createURL("updateResourceLimit&resourceType=1&max=" + todb(args.data.ipLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
296-
dataType: "json",
297-
async: false,
298-
success: function(json) {
299-
accountObj["ipLimit"] = args.data.ipLimit;
300-
}
301-
});
285+
if(args.data.vmLimit != null) {
286+
$.ajax({
287+
url: createURL("updateResourceLimit&resourceType=0&max=" + todb(args.data.vmLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
288+
dataType: "json",
289+
async: false,
290+
success: function(json) {
291+
accountObj["vmLimit"] = args.data.vmLimit;
292+
}
293+
});
294+
}
302295

303-
$.ajax({
304-
url: createURL("updateResourceLimit&resourceType=2&max=" + todb(args.data.volumeLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
305-
dataType: "json",
306-
async: false,
307-
success: function(json) {
308-
accountObj["volumeLimit"] = args.data.volumeLimit;
309-
}
310-
});
296+
if(args.data.ipLimit != null) {
297+
$.ajax({
298+
url: createURL("updateResourceLimit&resourceType=1&max=" + todb(args.data.ipLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
299+
dataType: "json",
300+
async: false,
301+
success: function(json) {
302+
accountObj["ipLimit"] = args.data.ipLimit;
303+
}
304+
});
305+
}
311306

312-
$.ajax({
313-
url: createURL("updateResourceLimit&resourceType=3&max=" + todb(args.data.snapshotLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
314-
dataType: "json",
315-
async: false,
316-
success: function(json) {
317-
accountObj["snapshotLimit"] = args.data.snapshotLimit;
318-
}
319-
});
307+
if(args.data.volumeLimit != null) {
308+
$.ajax({
309+
url: createURL("updateResourceLimit&resourceType=2&max=" + todb(args.data.volumeLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
310+
dataType: "json",
311+
async: false,
312+
success: function(json) {
313+
accountObj["volumeLimit"] = args.data.volumeLimit;
314+
}
315+
});
316+
}
320317

321-
$.ajax({
322-
url: createURL("updateResourceLimit&resourceType=4&max=" + todb(args.data.templateLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
323-
dataType: "json",
324-
async: false,
325-
success: function(json) {
326-
accountObj["templateLimit"] = args.data.templateLimit;
327-
}
328-
});
329-
330-
$.ajax({
331-
url: createURL("updateResourceLimit&resourceType=7&max=" + todb(args.data.vpcLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
332-
dataType: "json",
333-
async: false,
334-
success: function(json) {
335-
accountObj["vpcLimit"] = args.data.vpcLimit;
336-
}
337-
});
318+
if(args.data.snapshotLimit != null) {
319+
$.ajax({
320+
url: createURL("updateResourceLimit&resourceType=3&max=" + todb(args.data.snapshotLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
321+
dataType: "json",
322+
async: false,
323+
success: function(json) {
324+
accountObj["snapshotLimit"] = args.data.snapshotLimit;
325+
}
326+
});
327+
}
328+
329+
if(args.data.templateLimit != null) {
330+
$.ajax({
331+
url: createURL("updateResourceLimit&resourceType=4&max=" + todb(args.data.templateLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
332+
dataType: "json",
333+
async: false,
334+
success: function(json) {
335+
accountObj["templateLimit"] = args.data.templateLimit;
336+
}
337+
});
338+
}
339+
340+
if(args.data.vpcLimit != null) {
341+
$.ajax({
342+
url: createURL("updateResourceLimit&resourceType=7&max=" + todb(args.data.vpcLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid),
343+
dataType: "json",
344+
async: false,
345+
success: function(json) {
346+
accountObj["vpcLimit"] = args.data.vpcLimit;
347+
}
348+
});
349+
}
338350

339351
if(errorMsg == "")
340352
args.response.success({data: accountObj});
@@ -546,27 +558,57 @@
546558
},
547559
vmLimit: {
548560
label: 'label.instance.limits',
549-
isEditable: true
561+
isEditable: function(context) {
562+
if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin
563+
return true;
564+
else
565+
return false;
566+
}
550567
},
551568
ipLimit: {
552569
label: 'label.ip.limits',
553-
isEditable: true
570+
isEditable: function(context) {
571+
if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin
572+
return true;
573+
else
574+
return false;
575+
}
554576
},
555577
volumeLimit: {
556578
label: 'label.volume.limits',
557-
isEditable: true
579+
isEditable: function(context) {
580+
if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin
581+
return true;
582+
else
583+
return false;
584+
}
558585
},
559586
snapshotLimit: {
560587
label: 'label.snapshot.limits',
561-
isEditable: true
588+
isEditable: function(context) {
589+
if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin
590+
return true;
591+
else
592+
return false;
593+
}
562594
},
563595
templateLimit: {
564596
label: 'label.template.limits',
565-
isEditable: true
597+
isEditable: function(context) {
598+
if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin
599+
return true;
600+
else
601+
return false;
602+
}
566603
},
567604
vpcLimit: {
568605
label: 'VPC limits',
569-
isEditable: true
606+
isEditable: function(context) {
607+
if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin
608+
return true;
609+
else
610+
return false;
611+
}
570612
},
571613

572614
vmtotal: { label: 'label.total.of.vm' },
@@ -1091,12 +1133,8 @@
10911133
if (jsonObj.state == 'Destroyed') return [];
10921134

10931135
if(isAdmin()) {
1094-
if(!(jsonObj.domain == "ROOT" && jsonObj.name == "admin" && jsonObj.accounttype == 1)) { //if not system-generated default admin account
1095-
//allowedActions.push("edit");
1096-
if (jsonObj.accounttype == roleTypeUser || jsonObj.accounttype == roleTypeDomainAdmin) {
1097-
//allowedActions.push("updateResourceLimits");
1098-
allowedActions.push("edit");
1099-
}
1136+
allowedActions.push("edit"); //updating networkdomain is allowed on any account, including system-generated default admin account
1137+
if(!(jsonObj.domain == "ROOT" && jsonObj.name == "admin" && jsonObj.accounttype == 1)) { //if not system-generated default admin account
11001138
if(jsonObj.state == "enabled") {
11011139
allowedActions.push("disable");
11021140
allowedActions.push("lock");

ui/scripts/ui/widgets/detailView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@
789789

790790
// Set up editable metadata
791791
if(typeof(value.isEditable) == 'function')
792-
$value.data('detail-view-is-editable', value.isEditable());
792+
$value.data('detail-view-is-editable', value.isEditable(context));
793793
else //typeof(value.isEditable) == 'boolean' or 'undefined'
794794
$value.data('detail-view-is-editable', value.isEditable);
795795
if (value.select) {

0 commit comments

Comments
 (0)