fix(vm.create): correctly check resourceSet objects

Related to vatesfr/xo-web#1620
This commit is contained in:
Julien Fontanet 2016-10-04 15:49:48 +02:00
parent e094437168
commit fdd395e2b6

View File

@ -61,16 +61,9 @@ extract = (obj, prop) ->
# TODO: Implement ACLs # TODO: Implement ACLs
create = $coroutine (params) -> create = $coroutine (params) ->
checkLimits = limits = null
{ user } = this { user } = this
resourceSet = extract(params, 'resourceSet') resourceSet = extract(params, 'resourceSet')
if resourceSet if not resourceSet and user.permission isnt 'admin'
yield this.checkResourceSetConstraints(resourceSet, user.id, objectIds)
checkLimits = $coroutine (limits2) =>
yield this.allocateLimitsInResourceSet(limits, resourceSet)
yield this.allocateLimitsInResourceSet(limits2, resourceSet)
else unless user.permission is 'admin'
throw new Unauthorized() throw new Unauthorized()
template = extract(params, 'template') template = extract(params, 'template')
@ -147,6 +140,13 @@ create = $coroutine (params) ->
installation = extract(params, 'installation') installation = extract(params, 'installation')
params.installRepository = installation && installation.repository params.installRepository = installation && installation.repository
checkLimits = null
if resourceSet
yield this.checkResourceSetConstraints(resourceSet, user.id, objectIds)
checkLimits = $coroutine (limits2) =>
yield this.allocateLimitsInResourceSet(limits, resourceSet)
yield this.allocateLimitsInResourceSet(limits2, resourceSet)
xapiVm = yield xapi.createVm(template._xapiId, params, checkLimits) xapiVm = yield xapi.createVm(template._xapiId, params, checkLimits)
vm = xapi.xo.addObject(xapiVm) vm = xapi.xo.addObject(xapiVm)
@ -257,7 +257,7 @@ create.params = {
} }
create.resolve = { create.resolve = {
template: ['template', 'VM-template', 'administrate'], template: ['template', 'VM-template'],
} }
exports.create = create exports.create = create