@@ -357,6 +357,7 @@ public Pair<List<BackupOffering>, Integer> listBackupOfferings(final ListBackupO
357357 final Long offeringId = cmd .getOfferingId ();
358358 final Long zoneId = cmd .getZoneId ();
359359 final String keyword = cmd .getKeyword ();
360+ Long domainId = cmd .getDomainId ();
360361
361362 if (offeringId != null ) {
362363 BackupOfferingVO offering = backupOfferingDao .findById (offeringId );
@@ -370,8 +371,13 @@ public Pair<List<BackupOffering>, Integer> listBackupOfferings(final ListBackupO
370371 SearchBuilder <BackupOfferingVO > sb = backupOfferingDao .createSearchBuilder ();
371372 sb .and ("zone_id" , sb .entity ().getZoneId (), SearchCriteria .Op .EQ );
372373 sb .and ("name" , sb .entity ().getName (), SearchCriteria .Op .EQ );
374+
373375 CallContext ctx = CallContext .current ();
374376 final Account caller = ctx .getCallingAccount ();
377+ if (Account .Type .ADMIN != caller .getType () && domainId == null ) {
378+ domainId = caller .getDomainId ();
379+ }
380+
375381 if (Account .Type .NORMAL == caller .getType ()) {
376382 sb .and ("user_backups_allowed" , sb .entity ().isUserDrivenBackupAllowed (), SearchCriteria .Op .EQ );
377383 }
@@ -384,13 +390,36 @@ public Pair<List<BackupOffering>, Integer> listBackupOfferings(final ListBackupO
384390 if (keyword != null ) {
385391 sc .setParameters ("name" , "%" + keyword + "%" );
386392 }
393+
387394 if (Account .Type .NORMAL == caller .getType ()) {
388395 sc .setParameters ("user_backups_allowed" , true );
389396 }
397+
390398 Pair <List <BackupOfferingVO >, Integer > result = backupOfferingDao .searchAndCount (sc , searchFilter );
399+
400+ if (domainId != null ) {
401+ List <BackupOfferingVO > filteredOfferings = new ArrayList <>();
402+ for (BackupOfferingVO offering : result .first ()) {
403+ List <Long > offeringDomains = backupOfferingDetailsDao .findDomainIds (offering .getId ());
404+ if (offeringDomains .isEmpty () || offeringDomains .contains (domainId ) || containsParentDomain (offeringDomains , domainId )) {
405+ filteredOfferings .add (offering );
406+ }
407+ }
408+ return new Pair <>(new ArrayList <>(filteredOfferings ), filteredOfferings .size ());
409+ }
410+
391411 return new Pair <>(new ArrayList <>(result .first ()), result .second ());
392412 }
393413
414+ private boolean containsParentDomain (List <Long > offeringDomains , Long domainId ) {
415+ for (Long offeringDomainId : offeringDomains ) {
416+ if (domainDao .isChildDomain (offeringDomainId , domainId )) {
417+ return true ;
418+ }
419+ }
420+ return false ;
421+ }
422+
394423 @ Override
395424 public boolean deleteBackupOffering (final Long offeringId ) {
396425 final BackupOfferingVO offering = backupOfferingDao .findById (offeringId );
0 commit comments