2929import java .util .List ;
3030import java .util .ListIterator ;
3131import java .util .Map ;
32+ import java .util .Objects ;
3233import java .util .Set ;
3334import java .util .UUID ;
3435import java .util .stream .Collectors ;
@@ -4443,6 +4444,8 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
44434444 boolean showRemovedTmpl = cmd .getShowRemoved ();
44444445 Account caller = CallContext .current ().getCallingAccount ();
44454446 Long parentTemplateId = cmd .getParentTemplateId ();
4447+ Long domainId = cmd .getDomainId ();
4448+ boolean isRecursive = cmd .isRecursive ();
44464449
44474450 boolean listAll = false ;
44484451 if (templateFilter != null && templateFilter == TemplateFilter .all ) {
@@ -4453,7 +4456,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
44534456 }
44544457
44554458 List <Long > permittedAccountIds = new ArrayList <Long >();
4456- Ternary <Long , Boolean , ListProjectResourcesCriteria > domainIdRecursiveListProject = new Ternary <>(cmd . getDomainId (), cmd . isRecursive () , null );
4459+ Ternary <Long , Boolean , ListProjectResourcesCriteria > domainIdRecursiveListProject = new Ternary <>(domainId , isRecursive , null );
44574460 accountMgr .buildACLSearchParameters (
44584461 caller , id , cmd .getAccountName (), cmd .getProjectId (), permittedAccountIds ,
44594462 domainIdRecursiveListProject , listAll , false
@@ -4481,7 +4484,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
44814484 null , cmd .getPageSizeVal (), cmd .getStartIndex (), cmd .getZoneId (), cmd .getStoragePoolId (),
44824485 cmd .getImageStoreId (), hypervisorType , showDomr , cmd .listInReadyState (), permittedAccounts , caller ,
44834486 listProjectResourcesCriteria , tags , showRemovedTmpl , cmd .getIds (), parentTemplateId , cmd .getShowUnique (),
4484- templateType , isVnf );
4487+ templateType , isVnf , domainId , isRecursive );
44854488 }
44864489
44874490 private Pair <List <TemplateJoinVO >, Integer > searchForTemplatesInternal (Long templateId , String name , String keyword ,
@@ -4490,7 +4493,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
44904493 boolean showDomr , boolean onlyReady , List <Account > permittedAccounts , Account caller ,
44914494 ListProjectResourcesCriteria listProjectResourcesCriteria , Map <String , String > tags ,
44924495 boolean showRemovedTmpl , List <Long > ids , Long parentTemplateId , Boolean showUnique , String templateType ,
4493- Boolean isVnf ) {
4496+ Boolean isVnf , Long domainId , boolean isRecursive ) {
44944497
44954498 // check if zone is configured, if not, just return empty list
44964499 List <HypervisorType > hypers = null ;
@@ -4572,7 +4575,7 @@ else if (!template.isPublicTemplate() && caller.getType() != Account.Type.ADMIN)
45724575 if (!permittedAccounts .isEmpty ()) {
45734576 domain = _domainDao .findById (permittedAccounts .get (0 ).getDomainId ());
45744577 } else {
4575- domain = _domainDao .findById (caller .getDomainId ());
4578+ domain = _domainDao .findById (Objects . requireNonNullElse ( domainId , caller .getDomainId () ));
45764579 }
45774580
45784581 setIdsListToSearchCriteria (sc , ids );
@@ -4584,10 +4587,14 @@ else if (!template.isPublicTemplate() && caller.getType() != Account.Type.ADMIN)
45844587 sc .addAnd ("accountType" , SearchCriteria .Op .EQ , Account .Type .PROJECT );
45854588 }
45864589
4587- // add criteria for domain path in case of domain admin
4590+ // add criteria for domain path in case of admins
45884591 if ((templateFilter == TemplateFilter .self || templateFilter == TemplateFilter .selfexecutable )
4589- && (caller .getType () == Account .Type .DOMAIN_ADMIN || caller .getType () == Account .Type .RESOURCE_DOMAIN_ADMIN )) {
4590- sc .addAnd ("domainPath" , SearchCriteria .Op .LIKE , domain .getPath () + "%" );
4592+ && (accountMgr .isAdmin (caller .getAccountId ()))) {
4593+ if (isRecursive ) {
4594+ sc .addAnd ("domainPath" , SearchCriteria .Op .LIKE , domain .getPath () + "%" );
4595+ } else {
4596+ sc .addAnd ("domainPath" , SearchCriteria .Op .EQ , domain .getPath ());
4597+ }
45914598 }
45924599
45934600 List <Long > relatedDomainIds = new ArrayList <Long >();
@@ -4893,6 +4900,8 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
48934900 Map <String , String > tags = cmd .getTags ();
48944901 boolean showRemovedISO = cmd .getShowRemoved ();
48954902 Account caller = CallContext .current ().getCallingAccount ();
4903+ Long domainId = cmd .getDomainId ();
4904+ boolean isRecursive = cmd .isRecursive ();
48964905
48974906 boolean listAll = false ;
48984907 if (isoFilter != null && isoFilter == TemplateFilter .all ) {
@@ -4904,7 +4913,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
49044913
49054914
49064915 List <Long > permittedAccountIds = new ArrayList <>();
4907- Ternary <Long , Boolean , ListProjectResourcesCriteria > domainIdRecursiveListProject = new Ternary <>(cmd . getDomainId (), cmd . isRecursive () , null );
4916+ Ternary <Long , Boolean , ListProjectResourcesCriteria > domainIdRecursiveListProject = new Ternary <>(domainId , isRecursive , null );
49084917 accountMgr .buildACLSearchParameters (caller , id , cmd .getAccountName (), cmd .getProjectId (), permittedAccountIds , domainIdRecursiveListProject , listAll , false );
49094918 ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject .third ();
49104919 List <Account > permittedAccounts = new ArrayList <>();
@@ -4917,7 +4926,8 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
49174926 return searchForTemplatesInternal (cmd .getId (), cmd .getIsoName (), cmd .getKeyword (), isoFilter , true , cmd .isBootable (),
49184927 cmd .getPageSizeVal (), cmd .getStartIndex (), cmd .getZoneId (), cmd .getStoragePoolId (), cmd .getImageStoreId (),
49194928 hypervisorType , true , cmd .listInReadyState (), permittedAccounts , caller , listProjectResourcesCriteria ,
4920- tags , showRemovedISO , null , null , cmd .getShowUnique (), null , null );
4929+ tags , showRemovedISO , null , null , cmd .getShowUnique (), null , null ,
4930+ domainId , isRecursive );
49214931 }
49224932
49234933 @ Override
0 commit comments