@@ -3153,6 +3153,8 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
31533153 Object keyword = cmd .getKeyword ();
31543154 Long domainId = cmd .getDomainId ();
31553155 Boolean isRootAdmin = accountMgr .isRootAdmin (account .getAccountId ());
3156+ Long projectId = cmd .getProjectId ();
3157+ String accountName = cmd .getAccountName ();
31563158 Boolean isRecursive = cmd .isRecursive ();
31573159 Long zoneId = cmd .getZoneId ();
31583160 Long volumeId = cmd .getVolumeId ();
@@ -3246,9 +3248,9 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
32463248
32473249 // Filter offerings that are not associated with caller's domain
32483250 // Fetch the offering ids from the details table since theres no smart way to filter them in the join ... yet!
3249- Account caller = CallContext . current (). getCallingAccount ( );
3250- if (caller . getType () != Account .Type .ADMIN ) {
3251- Domain callerDomain = _domainDao .findById (caller .getDomainId ());
3251+ account = accountMgr . finalizeOwner ( account , accountName , domainId , projectId );
3252+ if (! Account .Type .ADMIN . equals ( account . getType ()) ) {
3253+ Domain callerDomain = _domainDao .findById (account .getDomainId ());
32523254 List <Long > domainIds = findRelatedDomainIds (callerDomain , isRecursive );
32533255
32543256 List <Long > ids = _diskOfferingDetailsDao .findOfferingIdsByDomainIds (domainIds );
@@ -3338,6 +3340,8 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
33383340 searchFilter .addOrderBy (ServiceOfferingJoinVO .class , "id" , true );
33393341
33403342 Account caller = CallContext .current ().getCallingAccount ();
3343+ Long projectId = cmd .getProjectId ();
3344+ String accountName = cmd .getAccountName ();
33413345 Object name = cmd .getServiceOfferingName ();
33423346 Object id = cmd .getId ();
33433347 Object keyword = cmd .getKeyword ();
@@ -3354,6 +3358,7 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
33543358 Boolean encryptRoot = cmd .getEncryptRoot ();
33553359 String storageType = cmd .getStorageType ();
33563360
3361+ final Account owner = accountMgr .finalizeOwner (caller , accountName , domainId , projectId );
33573362 SearchCriteria <ServiceOfferingJoinVO > sc = _srvOfferingJoinDao .createSearchCriteria ();
33583363 if (!accountMgr .isRootAdmin (caller .getId ()) && isSystem ) {
33593364 throw new InvalidParameterValueException ("Only ROOT admins can access system's offering" );
@@ -3365,8 +3370,8 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
33653370 if (domainId != null && !accountMgr .isRootAdmin (caller .getId ())) {
33663371 // check if the user's domain == so's domain || user's domain is a
33673372 // child of so's domain
3368- if (!isPermissible (caller .getDomainId (), domainId )) {
3369- throw new PermissionDeniedException ("The account:" + caller .getAccountName () + " does not fall in the same domain hierarchy as the service offering" );
3373+ if (!isPermissible (owner .getDomainId (), domainId )) {
3374+ throw new PermissionDeniedException ("The account:" + owner .getAccountName () + " does not fall in the same domain hierarchy as the service offering" );
33703375 }
33713376 }
33723377
@@ -3432,16 +3437,16 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
34323437 throw new InvalidParameterValueException ("Only root admins can access system's offering" );
34333438 }
34343439 if (isRecursive ) { // domain + all sub-domains
3435- if (caller .getType () == Account .Type .NORMAL ) {
3440+ if (owner .getType () == Account .Type .NORMAL ) {
34363441 throw new InvalidParameterValueException ("Only ROOT admins and Domain admins can list service offerings with isrecursive=true" );
34373442 }
34383443 }
34393444 } else {
34403445 // for root users
3441- if (caller .getDomainId () != 1 && isSystem ) { // NON ROOT admin
3442- throw new InvalidParameterValueException ("Non ROOT admins cannot access system's offering" );
3446+ if (owner .getDomainId () != 1 && isSystem ) { // NON ROOT admin
3447+ throw new InvalidParameterValueException ("Non ROOT admins cannot access system's offering. " );
34433448 }
3444- if (domainId != null ) {
3449+ if (domainId != null && accountName == null ) {
34453450 sc .addAnd ("domainId" , Op .FIND_IN_SET , String .valueOf (domainId ));
34463451 }
34473452 }
@@ -3527,8 +3532,8 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
35273532
35283533 // Filter offerings that are not associated with caller's domain
35293534 // Fetch the offering ids from the details table since theres no smart way to filter them in the join ... yet!
3530- if (caller .getType () != Account .Type .ADMIN ) {
3531- Domain callerDomain = _domainDao .findById (caller .getDomainId ());
3535+ if (owner .getType () != Account .Type .ADMIN ) {
3536+ Domain callerDomain = _domainDao .findById (owner .getDomainId ());
35323537 List <Long > domainIds = findRelatedDomainIds (callerDomain , isRecursive );
35333538
35343539 List <Long > ids = _srvOfferingDetailsDao .findOfferingIdsByDomainIds (domainIds );
0 commit comments