3030import java .util .List ;
3131import java .util .ListIterator ;
3232import java .util .Map ;
33+ import java .util .Objects ;
3334import java .util .Set ;
3435import java .util .UUID ;
3536import 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
0 commit comments