mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-18 11:34:23 +01:00
allow Domain Admin to list usage records in the domain
This commit is contained in:
parent
b79b2182ef
commit
90521a3e15
@ -493,7 +493,7 @@ listVirtualRouterElements=7
|
|||||||
|
|
||||||
#### usage commands
|
#### usage commands
|
||||||
generateUsageRecords=1
|
generateUsageRecords=1
|
||||||
listUsageRecords=1
|
listUsageRecords=7
|
||||||
listUsageTypes=1
|
listUsageTypes=1
|
||||||
|
|
||||||
#### traffic monitor commands
|
#### traffic monitor commands
|
||||||
|
|||||||
@ -39,6 +39,7 @@ import org.apache.log4j.Logger;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import com.cloud.configuration.Config;
|
import com.cloud.configuration.Config;
|
||||||
|
import com.cloud.domain.DomainVO;
|
||||||
import com.cloud.domain.dao.DomainDao;
|
import com.cloud.domain.dao.DomainDao;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.exception.PermissionDeniedException;
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
@ -150,6 +151,7 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isAdmin = false;
|
boolean isAdmin = false;
|
||||||
|
boolean isDomainAdmin = false;
|
||||||
|
|
||||||
//If accountId couldn't be found using accountName and domainId, get it from userContext
|
//If accountId couldn't be found using accountName and domainId, get it from userContext
|
||||||
if(accountId == null){
|
if(accountId == null){
|
||||||
@ -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 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){
|
if(caller.getType() == Account.ACCOUNT_TYPE_ADMIN){
|
||||||
isAdmin = true;
|
isAdmin = true;
|
||||||
|
} else if(caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN){
|
||||||
|
isDomainAdmin = true;
|
||||||
}
|
}
|
||||||
s_logger.debug("Account details not available. Using userContext accountId: " + accountId);
|
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();
|
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);
|
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) {
|
if (domainId != null) {
|
||||||
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
|
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user