From d1ac3f1f5c78f08b2276b6971fc9a4e1bba26ba9 Mon Sep 17 00:00:00 2001 From: Rakesh Venkatesh Date: Tue, 23 Mar 2021 12:09:01 +0100 Subject: [PATCH] Allow domain admins to create offering without mentioning domainid While creating disk/service offering by domains we need to specify domain id else it wont be created. Provide an enhancement so that we dont need to pass domainid and it will be taken from the callers user similar to other api's Another bug fix Currently while creating any offering, we need to specify a domain id or a list of domain id. If an offering is created on a domain then all its child domains should see it and all the parents domain should see it as well but it should not be visible to sibling domain isrecursive=true ensures that all child domains can see it but if a service offering is created for the domain at the leaf of the domain path then its parent cant see it if isrecurise is true. so we need to pass isrecursive=false so that the parent domain can see the child offerings --- .../configuration/ConfigurationManagerImpl.java | 16 ++++++++-------- ui/src/config/section/offering.js | 2 -- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java index f5de35af3ed2..afff84d81638 100755 --- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2503,11 +2503,11 @@ protected ServiceOfferingVO createServiceOffering(final long userId, final boole } final Account account = _accountDao.findById(user.getAccountId()); if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) { - if (filteredDomainIds.isEmpty()) { - throw new InvalidParameterValueException(String.format("Unable to create public service offering by admin: %s because it is domain-admin", user.getUuid())); - } if (tags != null || hostTag != null) { - throw new InvalidParameterValueException(String.format("Unable to create service offering with storage tags or host tags by admin: %s because it is domain-admin", user.getUuid())); + throw new InvalidParameterValueException(String.format("Unable to create service offering with storage tags or host tags by user: %s because it is domain-admin", user.getUsername())); + } + if (CollectionUtils.isEmpty(filteredDomainIds)) { + filteredDomainIds.add(account.getDomainId()); } for (Long domainId : filteredDomainIds) { if (!_domainDao.isChildDomain(account.getDomainId(), domainId)) { @@ -2937,11 +2937,11 @@ protected DiskOfferingVO createDiskOffering(final Long userId, final List } final Account account = _accountDao.findById(user.getAccountId()); if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) { - if (filteredDomainIds.isEmpty()) { - throw new InvalidParameterValueException(String.format("Unable to create public disk offering by admin: %s because it is domain-admin", user.getUuid())); - } if (tags != null) { - throw new InvalidParameterValueException(String.format("Unable to create disk offering with storage tags by admin: %s because it is domain-admin", user.getUuid())); + throw new InvalidParameterValueException(String.format("Unable to create disk offering with storage tags by user: %s because it is domain-admin", user.getUsername())); + } + if (CollectionUtils.isEmpty(filteredDomainIds)) { + filteredDomainIds.add(account.getDomainId()); } for (Long domainId : filteredDomainIds) { if (domainId == null || !_domainDao.isChildDomain(account.getDomainId(), domainId)) { diff --git a/ui/src/config/section/offering.js b/ui/src/config/section/offering.js index 085d85989f6f..8a4f0f190af6 100644 --- a/ui/src/config/section/offering.js +++ b/ui/src/config/section/offering.js @@ -28,7 +28,6 @@ export default { docHelp: 'adminguide/service_offerings.html#compute-and-disk-service-offerings', icon: 'cloud', permission: ['listServiceOfferings', 'listDomains'], - params: { isrecursive: 'true' }, columns: ['name', 'displaytext', 'cpunumber', 'cpuspeed', 'memory', 'domain', 'zone', 'order'], details: () => { var fields = ['name', 'id', 'displaytext', 'offerha', 'provisioningtype', 'storagetype', 'iscustomized', 'limitcpuuse', 'cpunumber', 'cpuspeed', 'memory', 'hosttags', 'tags', 'domain', 'zone', 'created'] @@ -117,7 +116,6 @@ export default { icon: 'hdd', docHelp: 'adminguide/service_offerings.html#compute-and-disk-service-offerings', permission: ['listDiskOfferings', 'listDomains'], - params: { isrecursive: 'true' }, columns: ['name', 'displaytext', 'disksize', 'domain', 'zone', 'order'], details: () => { var fields = ['name', 'id', 'displaytext', 'disksize', 'provisioningtype', 'storagetype', 'iscustomized', 'tags', 'domain', 'zone', 'created']