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/87c897ff Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/87c897ff Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/87c897ff Branch: refs/heads/4.2 Commit: 87c897ff7556179f09d9bfb3514790183df047fb Parents: 9767de4 Author: Wei Zhou <[email protected]> Authored: Mon Oct 21 14:30:17 2013 +0200 Committer: Wei Zhou <[email protected]> Committed: Wed Oct 23 14:30:05 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/87c897ff/client/tomcatconf/commands.properties.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index d4aff29..66223f5 100644 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -495,7 +495,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/87c897ff/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 836a505..5c175d2 100755 --- a/server/src/com/cloud/usage/UsageServiceImpl.java +++ b/server/src/com/cloud/usage/UsageServiceImpl.java @@ -38,6 +38,7 @@ import org.springframework.stereotype.Component; import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; @@ -151,7 +152,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(); @@ -159,6 +161,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); } @@ -180,10 +184,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); }
