Skip to content

Commit 5bdac75

Browse files
committed
Adjust how the parameters behave
1 parent e4ee69e commit 5bdac75

File tree

3 files changed

+11
-48
lines changed

3 files changed

+11
-48
lines changed

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaSummaryCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public void setDomainId(Long domainId) {
107107
}
108108

109109
public Boolean isListAll() {
110-
return ObjectUtils.defaultIfNull(listAll, Boolean.FALSE);
110+
// If a domain ID was specified, then allow listing all summaries of domain
111+
return ObjectUtils.defaultIfNull(listAll, Boolean.FALSE) || domainId != null;
111112
}
112113

113114
public void setListAll(Boolean listAll) {

plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,6 @@ public Pair<List<QuotaSummaryResponse>, Integer> createQuotaSummaryResponse(Quot
205205
}
206206

207207
protected Pair<List<QuotaSummaryResponse>, Integer> getQuotaSummaryResponseWithListAll(QuotaSummaryCmd cmd, Account caller) {
208-
Long accountId = cmd.getEntityOwnerId();
209-
if (accountId == -1) {
210-
accountId = cmd.isListAll() ? null : caller.getAccountId();
211-
}
212-
213208
Long domainId = cmd.getDomainId();
214209
if (domainId != null) {
215210
DomainVO domain = domainDao.findByIdIncludingRemoved(domainId);
@@ -220,6 +215,12 @@ protected Pair<List<QuotaSummaryResponse>, Integer> getQuotaSummaryResponseWithL
220215

221216
String domainPath = getDomainPathByDomainIdForDomainAdmin(caller);
222217

218+
Long accountId = cmd.getEntityOwnerId();
219+
if (accountId == -1) {
220+
// No specific account was provided
221+
accountId = cmd.isListAll() ? null : caller.getAccountId();
222+
}
223+
223224
String keyword = null;
224225
if (Account.Type.ADMIN.equals(caller.getType())) {
225226
keyword = cmd.getKeyword();
@@ -250,7 +251,8 @@ protected String getDomainPathByDomainIdForDomainAdmin(Account caller) {
250251
}
251252

252253
protected Pair<List<QuotaSummaryResponse>, Integer> getQuotaSummaryResponse(Long accountId, String accountName, Long domainId, String domainPath, QuotaSummaryCmd cmd) {
253-
if (accountId == -1) {
254+
if (accountId != null && accountId == -1) {
255+
// Either no specific account as provided, or list all is disabled
254256
accountId = CallContext.current().getCallingAccountId();
255257
}
256258

@@ -301,33 +303,6 @@ protected QuotaSummaryResponse getQuotaSummaryResponse(QuotaSummaryVO summary) {
301303
return response;
302304
}
303305

304-
protected QuotaSummaryResponse getQuotaSummaryResponse(final Account account) {
305-
Calendar[] period = quotaStatement.getCurrentStatementTime();
306-
307-
if (account != null) {
308-
QuotaSummaryResponse qr = new QuotaSummaryResponse();
309-
DomainVO domain = domainDao.findById(account.getDomainId());
310-
BigDecimal curBalance = _quotaBalanceDao.lastQuotaBalance(account.getAccountId(), account.getDomainId(), period[1].getTime());
311-
BigDecimal quotaUsage = quotaUsageDao.findTotalQuotaUsage(account.getAccountId(), account.getDomainId(), null, period[0].getTime(), period[1].getTime());
312-
313-
qr.setAccountId(account.getUuid());
314-
qr.setAccountName(account.getAccountName());
315-
qr.setDomainId(domain.getUuid());
316-
qr.setDomainPath(domain.getName());
317-
qr.setBalance(curBalance);
318-
qr.setQuotaUsage(quotaUsage);
319-
qr.setState(account.getState());
320-
qr.setStartDate(period[0].getTime());
321-
qr.setEndDate(period[1].getTime());
322-
qr.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
323-
qr.setQuotaEnabled(QuotaConfig.QuotaAccountEnabled.valueIn(account.getId()));
324-
qr.setObjectName("summary");
325-
return qr;
326-
} else {
327-
return new QuotaSummaryResponse();
328-
}
329-
}
330-
331306
public boolean isUserAllowedToSeeActivationRules(User user) {
332307
List<ApiDiscoveryResponse> apiList = (List<ApiDiscoveryResponse>) apiDiscoveryService.listApis(user, null).getResponses();
333308
return apiList.stream().anyMatch(response -> StringUtils.equalsAny(response.getName(), "quotaTariffCreate", "quotaTariffUpdate"));

server/src/main/java/com/cloud/api/dispatch/ParamProcessWorker.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,7 @@ public void processParameters(final BaseCmd cmd, final Map params) {
312312

313313
protected void doAccessChecks(BaseCmd cmd, Map<Object, AccessType> entitiesToAccess) {
314314
Account caller = CallContext.current().getCallingAccount();
315-
List<Long> entityOwners = cmd.getEntityOwnerIds();
316-
Account[] owners = null;
317-
if (entityOwners != null) {
318-
owners = entityOwners.stream().map(id -> _accountMgr.getAccount(id)).toArray(Account[]::new);
319-
} else {
320-
if (cmd.getEntityOwnerId() == Account.ACCOUNT_ID_SYSTEM && cmd instanceof BaseAsyncCmd && ((BaseAsyncCmd)cmd).getApiResourceType() == ApiCommandResourceType.Network) {
321-
if (logger.isDebugEnabled()) {
322-
logger.debug("Skipping access check on the network owner if the owner is ROOT/system.");
323-
}
324-
owners = new Account[]{};
325-
} else {
326-
owners = new Account[]{_accountMgr.getAccount(cmd.getEntityOwnerId())};
327-
}
328-
}
315+
Account[] owners = getEntityOwners(cmd);
329316

330317
if (cmd instanceof BaseAsyncCreateCmd) {
331318
// check that caller can access the owner account.

0 commit comments

Comments
 (0)