This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch 4.19
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.19 by this push:
     new bf464585785 List templates and ISOs by domain (#11179)
bf464585785 is described below

commit bf464585785b6c0848fb4b07953e12d1039af4ff
Author: Bernardo De Marco Gonçalves <bernardomg2...@gmail.com>
AuthorDate: Thu Jul 17 04:01:49 2025 -0300

    List templates and ISOs by domain (#11179)
---
 .../java/com/cloud/api/query/QueryManagerImpl.java | 28 +++++++++++++++-------
 ui/src/components/view/InfoCard.vue                |  3 +++
 ui/src/config/section/domain.js                    |  5 ++++
 3 files changed, 27 insertions(+), 9 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 d0f6fc0b16d..1d8e8687051 100644
--- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
@@ -29,6 +29,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.UUID;
 import java.util.stream.Collectors;
@@ -4443,6 +4444,8 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
         boolean showRemovedTmpl = cmd.getShowRemoved();
         Account caller = CallContext.current().getCallingAccount();
         Long parentTemplateId = cmd.getParentTemplateId();
+        Long domainId = cmd.getDomainId();
+        boolean isRecursive = cmd.isRecursive();
 
         boolean listAll = false;
         if (templateFilter != null && templateFilter == TemplateFilter.all) {
@@ -4453,7 +4456,7 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
         }
 
         List<Long> permittedAccountIds = new ArrayList<Long>();
-        Ternary<Long, Boolean, ListProjectResourcesCriteria> 
domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), 
cmd.isRecursive(), null);
+        Ternary<Long, Boolean, ListProjectResourcesCriteria> 
domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
         accountMgr.buildACLSearchParameters(
                 caller, id, cmd.getAccountName(), cmd.getProjectId(), 
permittedAccountIds,
                 domainIdRecursiveListProject, listAll, false
@@ -4481,7 +4484,7 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
                 null, cmd.getPageSizeVal(), cmd.getStartIndex(), 
cmd.getZoneId(), cmd.getStoragePoolId(),
                 cmd.getImageStoreId(), hypervisorType, showDomr, 
cmd.listInReadyState(), permittedAccounts, caller,
                 listProjectResourcesCriteria, tags, showRemovedTmpl, 
cmd.getIds(), parentTemplateId, cmd.getShowUnique(),
-                templateType, isVnf);
+                templateType, isVnf, domainId, isRecursive);
     }
 
     private Pair<List<TemplateJoinVO>, Integer> 
searchForTemplatesInternal(Long templateId, String name, String keyword,
@@ -4490,7 +4493,7 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
             boolean showDomr, boolean onlyReady, List<Account> 
permittedAccounts, Account caller,
             ListProjectResourcesCriteria listProjectResourcesCriteria, 
Map<String, String> tags,
             boolean showRemovedTmpl, List<Long> ids, Long parentTemplateId, 
Boolean showUnique, String templateType,
-            Boolean isVnf) {
+            Boolean isVnf, Long domainId, boolean isRecursive) {
 
         // check if zone is configured, if not, just return empty list
         List<HypervisorType> hypers = null;
@@ -4572,7 +4575,7 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
             if (!permittedAccounts.isEmpty()) {
                 domain = 
_domainDao.findById(permittedAccounts.get(0).getDomainId());
             } else {
-                domain = _domainDao.findById(caller.getDomainId());
+                domain = 
_domainDao.findById(Objects.requireNonNullElse(domainId, caller.getDomainId()));
             }
 
             setIdsListToSearchCriteria(sc, ids);
@@ -4584,10 +4587,14 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
                 sc.addAnd("accountType", SearchCriteria.Op.EQ, 
Account.Type.PROJECT);
             }
 
-            // add criteria for domain path in case of domain admin
+            // add criteria for domain path in case of admins
             if ((templateFilter == TemplateFilter.self || templateFilter == 
TemplateFilter.selfexecutable)
-                    && (caller.getType() == Account.Type.DOMAIN_ADMIN || 
caller.getType() == Account.Type.RESOURCE_DOMAIN_ADMIN)) {
-                sc.addAnd("domainPath", SearchCriteria.Op.LIKE, 
domain.getPath() + "%");
+                    && (accountMgr.isAdmin(caller.getAccountId()))) {
+                if (isRecursive) {
+                    sc.addAnd("domainPath", SearchCriteria.Op.LIKE, 
domain.getPath() + "%");
+                } else {
+                    sc.addAnd("domainPath", SearchCriteria.Op.EQ, 
domain.getPath());
+                }
             }
 
             List<Long> relatedDomainIds = new ArrayList<Long>();
@@ -4893,6 +4900,8 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
         Map<String, String> tags = cmd.getTags();
         boolean showRemovedISO = cmd.getShowRemoved();
         Account caller = CallContext.current().getCallingAccount();
+        Long domainId = cmd.getDomainId();
+        boolean isRecursive = cmd.isRecursive();
 
         boolean listAll = false;
         if (isoFilter != null && isoFilter == TemplateFilter.all) {
@@ -4904,7 +4913,7 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
 
 
         List<Long> permittedAccountIds = new ArrayList<>();
-        Ternary<Long, Boolean, ListProjectResourcesCriteria> 
domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), 
cmd.isRecursive(), null);
+        Ternary<Long, Boolean, ListProjectResourcesCriteria> 
domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
         accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), 
cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject, listAll, 
false);
         ListProjectResourcesCriteria listProjectResourcesCriteria = 
domainIdRecursiveListProject.third();
         List<Account> permittedAccounts = new ArrayList<>();
@@ -4917,7 +4926,8 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
         return searchForTemplatesInternal(cmd.getId(), cmd.getIsoName(), 
cmd.getKeyword(), isoFilter, true, cmd.isBootable(),
                 cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), 
cmd.getStoragePoolId(), cmd.getImageStoreId(),
                 hypervisorType, true, cmd.listInReadyState(), 
permittedAccounts, caller, listProjectResourcesCriteria,
-                tags, showRemovedISO, null, null, cmd.getShowUnique(), null, 
null);
+                tags, showRemovedISO, null, null, cmd.getShowUnique(), null, 
null,
+                domainId, isRecursive);
     }
 
     @Override
diff --git a/ui/src/components/view/InfoCard.vue 
b/ui/src/components/view/InfoCard.vue
index 00cb4748a88..e59735c51ea 100644
--- a/ui/src/components/view/InfoCard.vue
+++ b/ui/src/components/view/InfoCard.vue
@@ -1162,6 +1162,9 @@ export default {
         if (item.name === 'template') {
           query.templatefilter = 'self'
           query.filter = 'self'
+        } else if (item.name === 'iso') {
+          query.isofilter = 'self'
+          query.filter = 'self'
         }
 
         if (item.param === 'account') {
diff --git a/ui/src/config/section/domain.js b/ui/src/config/section/domain.js
index e6807f06278..fbe20ef8891 100644
--- a/ui/src/config/section/domain.js
+++ b/ui/src/config/section/domain.js
@@ -48,6 +48,11 @@ export default {
     name: 'template',
     title: 'label.templates',
     param: 'domainid'
+  },
+  {
+    name: 'iso',
+    title: 'label.isos',
+    param: 'domainid'
   }],
   tabs: [
     {

Reply via email to