Skip to content

Commit 7b3af54

Browse files
bernardodemarcodhslove
authored andcommitted
List templates and ISOs by domain (apache#11179)
1 parent 25f556e commit 7b3af54

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.List;
3131
import java.util.ListIterator;
3232
import java.util.Map;
33+
import java.util.Objects;
3334
import java.util.Set;
3435
import java.util.UUID;
3536
import java.util.stream.Collectors;
@@ -4838,6 +4839,8 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
48384839
boolean showRemovedTmpl = cmd.getShowRemoved();
48394840
Account caller = CallContext.current().getCallingAccount();
48404841
Long parentTemplateId = cmd.getParentTemplateId();
4842+
Long domainId = cmd.getDomainId();
4843+
boolean isRecursive = cmd.isRecursive();
48414844

48424845
boolean listAll = false;
48434846
if (templateFilter != null && templateFilter == TemplateFilter.all) {
@@ -4848,7 +4851,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
48484851
}
48494852

48504853
List<Long> permittedAccountIds = new ArrayList<Long>();
4851-
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
4854+
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
48524855
accountMgr.buildACLSearchParameters(
48534856
caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds,
48544857
domainIdRecursiveListProject, listAll, false
@@ -4876,8 +4879,8 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
48764879
return searchForTemplatesInternal(id, cmd.getTemplateName(), cmd.getKeyword(), templateFilter, false,
48774880
null, cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), cmd.getStoragePoolId(),
48784881
cmd.getImageStoreId(), hypervisorType, showDomr, cmd.listInReadyState(), permittedAccounts, caller,
4879-
listProjectResourcesCriteria, tags, showRemovedTmpl, cmd.getIds(), parentTemplateId, cmd.getShowUnique(),
4880-
templateType, isVnf, cmd.getArch(), cmd.getOsCategoryId(), forCks, cmd.getKvdoEnable(), cmd.getExtensionId());
4882+
listProjectResourcesCriteria, tags, showRemovedTmpl, cmd.getIds(), parentTemplateId, cmd.getShowUnique(),
4883+
templateType, isVnf, cmd.getArch(), cmd.getOsCategoryId(), forCks, cmd.getKvdoEnable(), cmd.getExtensionId(), domainId, isRecursive);
48814884
}
48824885

48834886
private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long templateId, String name, String keyword,
@@ -4886,7 +4889,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
48864889
boolean showDomr, boolean onlyReady, List<Account> permittedAccounts, Account caller,
48874890
ListProjectResourcesCriteria listProjectResourcesCriteria, Map<String, String> tags,
48884891
boolean showRemovedTmpl, List<Long> ids, Long parentTemplateId, Boolean showUnique, String templateType,
4889-
Boolean isVnf, CPU.CPUArch arch, Long osCategoryId, Boolean forCks, Boolean kvdoEnable, Long extensionId) {
4892+
Boolean isVnf, CPU.CPUArch arch, Long osCategoryId, Boolean forCks, Boolean kvdoEnable, Long extensionId, Long domainId, boolean isRecursive) {
48904893

48914894
// check if zone is configured, if not, just return empty list
48924895
List<HypervisorType> hypers = null;
@@ -4994,7 +4997,7 @@ else if (!template.isPublicTemplate() && caller.getType() != Account.Type.ADMIN)
49944997
if (!permittedAccounts.isEmpty()) {
49954998
domain = _domainDao.findById(permittedAccounts.get(0).getDomainId());
49964999
} else {
4997-
domain = _domainDao.findById(caller.getDomainId());
5000+
domain = _domainDao.findById(Objects.requireNonNullElse(domainId, caller.getDomainId()));
49985001
}
49995002

50005003
setIdsListToSearchCriteria(sc, ids);
@@ -5006,10 +5009,14 @@ else if (!template.isPublicTemplate() && caller.getType() != Account.Type.ADMIN)
50065009
sc.addAnd("accountType", SearchCriteria.Op.EQ, Account.Type.PROJECT);
50075010
}
50085011

5009-
// add criteria for domain path in case of domain admin
5012+
// add criteria for domain path in case of admins
50105013
if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable)
5011-
&& (caller.getType() == Account.Type.DOMAIN_ADMIN || caller.getType() == Account.Type.RESOURCE_DOMAIN_ADMIN)) {
5012-
sc.addAnd("domainPath", SearchCriteria.Op.LIKE, domain.getPath() + "%");
5014+
&& (accountMgr.isAdmin(caller.getAccountId()))) {
5015+
if (isRecursive) {
5016+
sc.addAnd("domainPath", SearchCriteria.Op.LIKE, domain.getPath() + "%");
5017+
} else {
5018+
sc.addAnd("domainPath", SearchCriteria.Op.EQ, domain.getPath());
5019+
}
50135020
}
50145021

50155022
List<Long> relatedDomainIds = new ArrayList<Long>();
@@ -5320,6 +5327,8 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
53205327
Map<String, String> tags = cmd.getTags();
53215328
boolean showRemovedISO = cmd.getShowRemoved();
53225329
Account caller = CallContext.current().getCallingAccount();
5330+
Long domainId = cmd.getDomainId();
5331+
boolean isRecursive = cmd.isRecursive();
53235332

53245333
boolean listAll = false;
53255334
if (isoFilter != null && isoFilter == TemplateFilter.all) {
@@ -5331,7 +5340,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
53315340

53325341

53335342
List<Long> permittedAccountIds = new ArrayList<>();
5334-
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
5343+
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
53355344
accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject, listAll, false);
53365345
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
53375346
List<Account> permittedAccounts = new ArrayList<>();
@@ -5345,7 +5354,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
53455354
cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), cmd.getStoragePoolId(), cmd.getImageStoreId(),
53465355
hypervisorType, true, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria,
53475356
tags, showRemovedISO, null, null, cmd.getShowUnique(), null, null,
5348-
cmd.getArch(), cmd.getOsCategoryId(), null, null);
5357+
cmd.getArch(), cmd.getOsCategoryId(), null, null, domainId, isRecursive);
53495358
}
53505359

53515360
@Override

ui/src/components/view/InfoCard.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,9 @@ export default {
14181418
if (item.name === 'template') {
14191419
query.templatefilter = 'self'
14201420
query.filter = 'self'
1421+
} else if (item.name === 'iso') {
1422+
query.isofilter = 'self'
1423+
query.filter = 'self'
14211424
}
14221425
14231426
if (item.param === 'account') {

ui/src/config/section/domain.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export default {
4848
name: 'template',
4949
title: 'label.templates',
5050
param: 'domainid'
51+
},
52+
{
53+
name: 'iso',
54+
title: 'label.isos',
55+
param: 'domainid'
5156
}],
5257
tabs: [
5358
{

0 commit comments

Comments
 (0)