Skip to content

Commit 506520a

Browse files
author
Jessica Wang
committed
CLOUDSTACK-1888: UI > Domains > allow domain-admin to update resource limits on its sub-domains (but disallow on its own domain).
1 parent 1f85124 commit 506520a

1 file changed

Lines changed: 71 additions & 55 deletions

File tree

ui/scripts/domains.js

Lines changed: 71 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,31 @@
9999
var domainObj;
100100

101101
var data = {
102-
id: args.context.domains[0].id,
103-
networkdomain: args.data.networkdomain
102+
id: args.context.domains[0].id
104103
};
105104

106-
if (args.data.name != null) {
105+
if (args.data.name != null) { //args.data.name == undefined means name field is not editable (when log in as normal user or domain admin)
107106
$.extend(data, {
108107
name: args.data.name
109108
});
110109
}
111-
112-
$.ajax({
113-
url: createURL("updateDomain"),
114-
async: false,
115-
data: data,
116-
success: function(json) {
117-
domainObj = json.updatedomainresponse.domain;
118-
}
119-
});
110+
111+
if (args.data.networkdomain != null) { //args.data.networkdomain == undefined means networkdomain field is not editable (when log in as normal user or domain admin)
112+
$.extend(data, {
113+
networkdomain: args.data.networkdomain
114+
});
115+
}
116+
117+
if('name' in data || 'networkdomain' in data) {
118+
$.ajax({
119+
url: createURL("updateDomain"),
120+
async: false,
121+
data: data,
122+
success: function(json) {
123+
domainObj = json.updatedomainresponse.domain;
124+
}
125+
});
126+
}
120127

121128
if (args.data.vmLimit != null) {
122129
$.ajax({
@@ -328,8 +335,8 @@
328335
fields: [{
329336
name: {
330337
label: 'label.name',
331-
isEditable: function(context) {
332-
if (context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to change domain name
338+
isEditable: function(args) {
339+
if (isAdmin() && args.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to change domain name
333340
return true;
334341
else
335342
return false;
@@ -346,96 +353,101 @@
346353

347354
networkdomain: {
348355
label: 'label.network.domain',
349-
isEditable: true
356+
isEditable: function(args) {
357+
if (isAdmin())
358+
return true;
359+
else
360+
return false;
361+
}
350362
},
351363
vmLimit: {
352364
label: 'label.instance.limits',
353-
isEditable: function(context) {
354-
if (context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
355-
return true;
356-
else
365+
isEditable: function(args) {
366+
if (args.domains[0].id == g_domainid) //disallow to update the field on the domain you log in as
357367
return false;
368+
else
369+
return true;
358370
}
359371
},
360372
ipLimit: {
361373
label: 'label.ip.limits',
362-
isEditable: function(context) {
363-
if (context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
364-
return true;
365-
else
374+
isEditable: function(args) {
375+
if (args.domains[0].id == g_domainid) //disallow to update the field on the domain you log in as
366376
return false;
377+
else
378+
return true;
367379
}
368380
},
369381
volumeLimit: {
370382
label: 'label.volume.limits',
371-
isEditable: function(context) {
372-
if (context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
373-
return true;
374-
else
383+
isEditable: function(args) {
384+
if (args.domains[0].id == g_domainid) //disallow to update the field on the domain you log in as
375385
return false;
386+
else
387+
return true;
376388
}
377389
},
378390
snapshotLimit: {
379391
label: 'label.snapshot.limits',
380-
isEditable: function(context) {
381-
if (context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
382-
return true;
383-
else
392+
isEditable: function(args) {
393+
if (args.domains[0].id == g_domainid) //disallow to update the field on the domain you log in as
384394
return false;
395+
else
396+
return true;
385397
}
386398
},
387399
templateLimit: {
388400
label: 'label.template.limits',
389-
isEditable: function(context) {
390-
if (context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
391-
return true;
392-
else
401+
isEditable: function(args) {
402+
if (args.domains[0].id == g_domainid) //disallow to update the field on the domain you log in as
393403
return false;
404+
else
405+
return true;
394406
}
395407
},
396408
vpcLimit: {
397409
label: 'VPC limits',
398-
isEditable: function(context) {
399-
if (context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
400-
return true;
401-
else
410+
isEditable: function(args) {
411+
if (args.domains[0].id == g_domainid) //disallow to update the field on the domain you log in as
402412
return false;
413+
else
414+
return true;
403415
}
404416
},
405417
cpuLimit: {
406418
label: 'label.cpu.limits',
407-
isEditable: function(context) {
408-
if (context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
409-
return true;
410-
else
419+
isEditable: function(args) {
420+
if (args.domains[0].id == g_domainid) //disallow to update the field on the domain you log in as
411421
return false;
422+
else
423+
return true;
412424
}
413425
},
414426
memoryLimit: {
415427
label: 'label.memory.limits',
416-
isEditable: function(context) {
417-
if (context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
418-
return true;
419-
else
428+
isEditable: function(args) {
429+
if (args.domains[0].id == g_domainid) //disallow to update the field on the domain you log in as
420430
return false;
431+
else
432+
return true;
421433
}
422434
},
423435
primaryStorageLimit: {
424436
label: 'label.primary.storage.limits',
425-
isEditable: function(context) {
426-
if (context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
427-
return true;
428-
else
437+
isEditable: function(args) {
438+
if (args.domains[0].id == g_domainid) //disallow to update the field on the domain you log in as
429439
return false;
440+
else
441+
return true;
430442
}
431443
},
432444
secondaryStorageLimit: {
433445
label: 'label.secondary.storage.limits',
434-
isEditable: function(context) {
435-
if (context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
436-
return true;
437-
else
446+
isEditable: function(args) {
447+
if (args.domains[0].id == g_domainid) //disallow to update the field on the domain you log in as
438448
return false;
449+
else
450+
return true;
439451
}
440452
},
441453
accountTotal: {
@@ -620,6 +632,10 @@
620632
if (jsonObj.level != 0) { //ROOT domain (whose level is 0) is not allowed to delete
621633
allowedActions.push("delete");
622634
}
635+
} else if (isDomainAdmin()) {
636+
if (args.context.domains[0].id != g_domainid) {
637+
allowedActions.push("edit"); //merge updateResourceLimit into edit
638+
}
623639
}
624640
allowedActions.push("updateResourceCount");
625641
return allowedActions;

0 commit comments

Comments
 (0)