From 38366c86abcf790ea44f43135bf6aec6486e1e84 Mon Sep 17 00:00:00 2001 From: davidjumani Date: Mon, 14 Mar 2022 13:25:49 +0530 Subject: [PATCH 1/3] Fix recursive lookup for offerings for users --- .../src/main/java/com/cloud/api/query/QueryManagerImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java index 6f239e9cc5f8..0395250568cd 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -2925,7 +2925,7 @@ private Pair, Integer> searchForDiskOfferingsInternal(L if ((_accountMgr.isNormalUser(account.getId()) || _accountMgr.isDomainAdmin(account.getId())) || account.getType() == Account.Type.RESOURCE_DOMAIN_ADMIN) { if (isRecursive) { // domain + all sub-domains if (account.getType() == Account.Type.NORMAL) { - throw new InvalidParameterValueException("Only ROOT admins and Domain admins can list disk offerings with isrecursive=true"); + isRecursive = false; } } } @@ -3153,7 +3153,7 @@ private Pair, Integer> searchForServiceOfferingsInte } if (isRecursive) { // domain + all sub-domains if (caller.getType() == Account.Type.NORMAL) { - throw new InvalidParameterValueException("Only ROOT admins and Domain admins can list service offerings with isrecursive=true"); + isRecursive = false; } } } else { From 35ca3088d5603167ae8e8668695ef853d0fed7f0 Mon Sep 17 00:00:00 2001 From: davidjumani Date: Tue, 15 Mar 2022 16:23:17 +0530 Subject: [PATCH 2/3] Revert "Fix recursive lookup for offerings for users" This reverts commit 38366c86abcf790ea44f43135bf6aec6486e1e84. --- .../src/main/java/com/cloud/api/query/QueryManagerImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java index 0395250568cd..6f239e9cc5f8 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -2925,7 +2925,7 @@ private Pair, Integer> searchForDiskOfferingsInternal(L if ((_accountMgr.isNormalUser(account.getId()) || _accountMgr.isDomainAdmin(account.getId())) || account.getType() == Account.Type.RESOURCE_DOMAIN_ADMIN) { if (isRecursive) { // domain + all sub-domains if (account.getType() == Account.Type.NORMAL) { - isRecursive = false; + throw new InvalidParameterValueException("Only ROOT admins and Domain admins can list disk offerings with isrecursive=true"); } } } @@ -3153,7 +3153,7 @@ private Pair, Integer> searchForServiceOfferingsInte } if (isRecursive) { // domain + all sub-domains if (caller.getType() == Account.Type.NORMAL) { - isRecursive = false; + throw new InvalidParameterValueException("Only ROOT admins and Domain admins can list service offerings with isrecursive=true"); } } } else { From 16f653d6a4712152ab93fa38887da901bf0cc2bf Mon Sep 17 00:00:00 2001 From: davidjumani Date: Tue, 15 Mar 2022 16:28:32 +0530 Subject: [PATCH 3/3] Set isrecursive as false by default of users --- .../apache/cloudstack/api/BaseListDomainResourcesCmd.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseListDomainResourcesCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseListDomainResourcesCmd.java index e9a9e5b1ed96..1440a1570e7c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseListDomainResourcesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseListDomainResourcesCmd.java @@ -16,7 +16,10 @@ // under the License. package org.apache.cloudstack.api; +import com.cloud.user.Account; + import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.context.CallContext; public abstract class BaseListDomainResourcesCmd extends BaseListCmd implements IBaseListDomainResourcesCmd { @@ -42,7 +45,10 @@ public boolean listAll() { @Override public boolean isRecursive() { if (listAll()) { - return recursive == null ? true : recursive; + Account caller = CallContext.current().getCallingAccount(); + if (caller.getType() != Account.Type.NORMAL) { + return recursive == null ? true : recursive; + } } return recursive == null ? false : recursive; }