You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by we...@apache.org on 2013/10/21 14:30:34 UTC

git commit: updated refs/heads/master to 90521a3

Updated Branches:
  refs/heads/master b79b2182e -> 90521a3e1


allow Domain Admin to list usage records in the domain


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/90521a3e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/90521a3e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/90521a3e

Branch: refs/heads/master
Commit: 90521a3e15ab3e1848d039b279da1847c0b10c52
Parents: b79b218
Author: Wei Zhou <w....@leaseweb.com>
Authored: Mon Oct 21 14:30:17 2013 +0200
Committer: Wei Zhou <w....@leaseweb.com>
Committed: Mon Oct 21 14:30:17 2013 +0200

----------------------------------------------------------------------
 client/tomcatconf/commands.properties.in         |  2 +-
 server/src/com/cloud/usage/UsageServiceImpl.java | 18 ++++++++++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/90521a3e/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 96e841a..0296de0 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -493,7 +493,7 @@ listVirtualRouterElements=7
 
 #### usage commands
 generateUsageRecords=1
-listUsageRecords=1
+listUsageRecords=7
 listUsageTypes=1
 
 #### traffic monitor commands

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/90521a3e/server/src/com/cloud/usage/UsageServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/usage/UsageServiceImpl.java b/server/src/com/cloud/usage/UsageServiceImpl.java
index 2ffb01d..0fed51c 100755
--- a/server/src/com/cloud/usage/UsageServiceImpl.java
+++ b/server/src/com/cloud/usage/UsageServiceImpl.java
@@ -39,6 +39,7 @@ import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
 import com.cloud.configuration.Config;
+import com.cloud.domain.DomainVO;
 import com.cloud.domain.dao.DomainDao;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.PermissionDeniedException;
@@ -150,7 +151,8 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
         } 
 
         boolean isAdmin = false;
-        
+        boolean isDomainAdmin = false;
+ 
         //If accountId couldn't be found using accountName and domainId, get it from userContext
         if(accountId == null){
             accountId = caller.getId();
@@ -158,6 +160,8 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
             //If account_id or account_name is explicitly mentioned, list records for the specified account only even if the caller is of type admin
             if(caller.getType() == Account.ACCOUNT_TYPE_ADMIN){
                 isAdmin = true;
+            } else if(caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN){
+                isDomainAdmin = true;
             }
             s_logger.debug("Account details not available. Using userContext accountId: " + accountId);
         }
@@ -179,10 +183,20 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
         
         SearchCriteria<UsageVO> sc = _usageDao.createSearchCriteria();
 
-        if (accountId != -1 && accountId != Account.ACCOUNT_ID_SYSTEM && !isAdmin) {
+        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 (domainId != null) {
             sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
         }