Spaceman1984 commented on a change in pull request #4717:
URL: https://github.com/apache/cloudstack/pull/4717#discussion_r586297186



##########
File path: server/src/main/java/com/cloud/usage/UsageServiceImpl.java
##########
@@ -234,22 +286,27 @@ public boolean 
generateUsageRecords(GenerateUsageRecordsCmd cmd) {
 
         SearchCriteria<UsageVO> sc = _usageDao.createSearchCriteria();
 
-        if (accountId != -1 && accountId != Account.ACCOUNT_ID_SYSTEM && 
!isAdmin && !isDomainAdmin) {
-            sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
-        }
-
-        if (isDomainAdmin) {
-            SearchCriteria<DomainVO> sdc = _domainDao.createSearchCriteria();
-            sdc.addOr("path", SearchCriteria.Op.LIKE, 
_domainDao.findById(caller.getDomainId()).getPath() + "%");
-            List<DomainVO> domains = _domainDao.search(sdc, null);
-            List<Long> domainIds = new ArrayList<Long>();
-            for (DomainVO domain : domains)
-                domainIds.add(domain.getId());
-            sc.addAnd("domainId", SearchCriteria.Op.IN, domainIds.toArray());
+        if (accountId != -1 && accountId != Account.ACCOUNT_ID_SYSTEM && 
!isAdmin) {
+            // account exists and either domain on user role
+            // If not recursive and the account belongs to the user/domain 
admin, or the account was passed in, filter
+            if ((accountId == caller.getId() && !cmd.isRecursive()) || 
cmd.getAccountId() != null){
+                sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+            }
         }
 
         if (domainId != null) {
-            sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+            if (cmd.isRecursive()) {
+                SearchCriteria<DomainVO> sdc = 
_domainDao.createSearchCriteria();
+                sdc.addOr("path", SearchCriteria.Op.LIKE, 
_domainDao.findById(domainId).getPath() + "%");
+                List<DomainVO> domains = _domainDao.search(sdc, null);

Review comment:
       @rhtyd Using findAllChildren here would not pass the top domain.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to