GutoVeronezi commented on a change in pull request #5866:
URL: https://github.com/apache/cloudstack/pull/5866#discussion_r792587791
##########
File path: server/src/main/java/com/cloud/usage/UsageServiceImpl.java
##########
@@ -397,6 +363,59 @@ public boolean
generateUsageRecords(GenerateUsageRecordsCmd cmd) {
return new Pair<List<? extends Usage>, Integer>(usageRecords.first(),
usageRecords.second());
}
+ private Long getDomainScopeForQuery(ListUsageRecordsCmd cmd, Long
accountId, Long domainId, Account caller, boolean isDomainAdmin) {
+ if (isDomainAdmin) {
Review comment:
We could invert this statement and return `domainId` to reduce the
indentation.
##########
File path: server/src/main/java/com/cloud/usage/UsageServiceImpl.java
##########
@@ -397,6 +363,59 @@ public boolean
generateUsageRecords(GenerateUsageRecordsCmd cmd) {
return new Pair<List<? extends Usage>, Integer>(usageRecords.first(),
usageRecords.second());
}
+ private Long getDomainScopeForQuery(ListUsageRecordsCmd cmd, Long
accountId, Long domainId, Account caller, boolean isDomainAdmin) {
+ if (isDomainAdmin) {
+ if (domainId != null) {
+ Account callerAccount =
_accountService.getAccount(caller.getId());
+ Domain domain = _domainDao.findById(domainId);
+ _accountService.checkAccess(callerAccount, domain);
+ } else {
+ domainId = caller.getDomainId();
+ }
+
+ if (cmd.getAccountId() != null) {
+ checkDomainAdminAccountAccess(accountId, domainId);
+ }
+ }
+ return domainId;
+ }
+
+ @NotNull
+ private Long getAccountIdFromDomainPlusName(Long domainId, String
accountName, Account caller) {
+ Long accountId;
+ Account userAccount = null;
+ if (_domainDao.isChildDomain(caller.getDomainId(), domainId)) {
Review comment:
We could invert this statement to reduce indentation.
##########
File path: server/src/main/java/com/cloud/usage/UsageServiceImpl.java
##########
@@ -397,6 +363,59 @@ public boolean
generateUsageRecords(GenerateUsageRecordsCmd cmd) {
return new Pair<List<? extends Usage>, Integer>(usageRecords.first(),
usageRecords.second());
}
+ private Long getDomainScopeForQuery(ListUsageRecordsCmd cmd, Long
accountId, Long domainId, Account caller, boolean isDomainAdmin) {
+ if (isDomainAdmin) {
+ if (domainId != null) {
+ Account callerAccount =
_accountService.getAccount(caller.getId());
+ Domain domain = _domainDao.findById(domainId);
+ _accountService.checkAccess(callerAccount, domain);
+ } else {
+ domainId = caller.getDomainId();
+ }
+
+ if (cmd.getAccountId() != null) {
+ checkDomainAdminAccountAccess(accountId, domainId);
+ }
+ }
+ return domainId;
+ }
+
+ @NotNull
+ private Long getAccountIdFromDomainPlusName(Long domainId, String
accountName, Account caller) {
+ Long accountId;
+ Account userAccount = null;
+ if (_domainDao.isChildDomain(caller.getDomainId(), domainId)) {
+ Filter filter = new Filter(AccountVO.class, "id", Boolean.FALSE,
null, null);
+ List<AccountVO> accounts = _accountDao.listAccounts(accountName,
domainId, filter);
+ if (accounts.size() > 0) {
+ userAccount = accounts.get(0);
+ }
+ if (userAccount != null) {
+ accountId = userAccount.getId();
+ } else {
+ throw new InvalidParameterValueException("Unable to find
account " + accountName + " in domain " + domainId);
+ }
+ } else {
+ throw new PermissionDeniedException("Invalid Domain Id or
Account");
+ }
+ return accountId;
+ }
+
+ @NotNull
+ private Long GetAccountIdFromProject(Long projectId) {
+ Long accountId;
+ Project project = _projectMgr.getProject(projectId);
+ if (project == null) {
+ throw new InvalidParameterValueException("Unable to find project
by id " + projectId);
+ }
+ final long projectAccountId = project.getProjectAccountId();
+ if(s_logger.isInfoEnabled()) {
Review comment:
```suggestion
if (s_logger.isInfoEnabled()) {
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]