List templates and ISOs by domain (#11179)

This commit is contained in:
Bernardo De Marco Gonçalves 2025-07-17 04:01:49 -03:00 committed by GitHub
parent 06c80cdbe9
commit bf46458578
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 9 deletions

View File

@ -29,6 +29,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -4443,6 +4444,8 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
boolean showRemovedTmpl = cmd.getShowRemoved(); boolean showRemovedTmpl = cmd.getShowRemoved();
Account caller = CallContext.current().getCallingAccount(); Account caller = CallContext.current().getCallingAccount();
Long parentTemplateId = cmd.getParentTemplateId(); Long parentTemplateId = cmd.getParentTemplateId();
Long domainId = cmd.getDomainId();
boolean isRecursive = cmd.isRecursive();
boolean listAll = false; boolean listAll = false;
if (templateFilter != null && templateFilter == TemplateFilter.all) { if (templateFilter != null && templateFilter == TemplateFilter.all) {
@ -4453,7 +4456,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
} }
List<Long> permittedAccountIds = new ArrayList<Long>(); 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( accountMgr.buildACLSearchParameters(
caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds,
domainIdRecursiveListProject, listAll, false domainIdRecursiveListProject, listAll, false
@ -4481,7 +4484,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
null, cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), cmd.getStoragePoolId(), null, cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), cmd.getStoragePoolId(),
cmd.getImageStoreId(), hypervisorType, showDomr, cmd.listInReadyState(), permittedAccounts, caller, cmd.getImageStoreId(), hypervisorType, showDomr, cmd.listInReadyState(), permittedAccounts, caller,
listProjectResourcesCriteria, tags, showRemovedTmpl, cmd.getIds(), parentTemplateId, cmd.getShowUnique(), 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, 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, boolean showDomr, boolean onlyReady, List<Account> permittedAccounts, Account caller,
ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags, ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags,
boolean showRemovedTmpl, List<Long> ids, Long parentTemplateId, Boolean showUnique, String templateType, 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 // check if zone is configured, if not, just return empty list
List<HypervisorType> hypers = null; List<HypervisorType> hypers = null;
@ -4572,7 +4575,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
if (!permittedAccounts.isEmpty()) { if (!permittedAccounts.isEmpty()) {
domain = _domainDao.findById(permittedAccounts.get(0).getDomainId()); domain = _domainDao.findById(permittedAccounts.get(0).getDomainId());
} else { } else {
domain = _domainDao.findById(caller.getDomainId()); domain = _domainDao.findById(Objects.requireNonNullElse(domainId, caller.getDomainId()));
} }
setIdsListToSearchCriteria(sc, ids); setIdsListToSearchCriteria(sc, ids);
@ -4584,10 +4587,14 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
sc.addAnd("accountType", SearchCriteria.Op.EQ, Account.Type.PROJECT); 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) if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable)
&& (caller.getType() == Account.Type.DOMAIN_ADMIN || caller.getType() == Account.Type.RESOURCE_DOMAIN_ADMIN)) { && (accountMgr.isAdmin(caller.getAccountId()))) {
sc.addAnd("domainPath", SearchCriteria.Op.LIKE, domain.getPath() + "%"); 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>(); List<Long> relatedDomainIds = new ArrayList<Long>();
@ -4893,6 +4900,8 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Map<String, String> tags = cmd.getTags(); Map<String, String> tags = cmd.getTags();
boolean showRemovedISO = cmd.getShowRemoved(); boolean showRemovedISO = cmd.getShowRemoved();
Account caller = CallContext.current().getCallingAccount(); Account caller = CallContext.current().getCallingAccount();
Long domainId = cmd.getDomainId();
boolean isRecursive = cmd.isRecursive();
boolean listAll = false; boolean listAll = false;
if (isoFilter != null && isoFilter == TemplateFilter.all) { if (isoFilter != null && isoFilter == TemplateFilter.all) {
@ -4904,7 +4913,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
List<Long> permittedAccountIds = new ArrayList<>(); 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); accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject, listAll, false);
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
List<Account> permittedAccounts = new ArrayList<>(); 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(), return searchForTemplatesInternal(cmd.getId(), cmd.getIsoName(), cmd.getKeyword(), isoFilter, true, cmd.isBootable(),
cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), cmd.getStoragePoolId(), cmd.getImageStoreId(), cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), cmd.getStoragePoolId(), cmd.getImageStoreId(),
hypervisorType, true, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, 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 @Override

View File

@ -1162,6 +1162,9 @@ export default {
if (item.name === 'template') { if (item.name === 'template') {
query.templatefilter = 'self' query.templatefilter = 'self'
query.filter = 'self' query.filter = 'self'
} else if (item.name === 'iso') {
query.isofilter = 'self'
query.filter = 'self'
} }
if (item.param === 'account') { if (item.param === 'account') {

View File

@ -48,6 +48,11 @@ export default {
name: 'template', name: 'template',
title: 'label.templates', title: 'label.templates',
param: 'domainid' param: 'domainid'
},
{
name: 'iso',
title: 'label.isos',
param: 'domainid'
}], }],
tabs: [ tabs: [
{ {