bug 6752: fix updating resource limits for a domain by looking at the given accountName/domainId parameters rather than looking at the caller's account. If updating limits for an account, e.g. account 'foo' in domain 4, then execute updateResourceLimit&account=foo&domainid=4&..., but if updating the limit for a domain, don't specify the account parameter. When processing the command, if accountName is null, the limit for the domain will be properly updated.

status 6752: resolved fixed
This commit is contained in:
Kris McQueen 2010-10-25 17:32:14 -07:00
parent 0d9ad0c737
commit b3c7821b44
4 changed files with 13 additions and 15 deletions

View File

@ -110,7 +110,7 @@ public class ListResourceLimitsCmd extends BaseListCmd {
}
}
resourceLimitResponse.setResourceType(limit.getType().ordinal());
resourceLimitResponse.setResourceType(Integer.valueOf(limit.getType().ordinal()).toString());
resourceLimitResponse.setMax(limit.getMax());
resourceLimitResponse.setResponseName("resourcelimit");

View File

@ -103,7 +103,7 @@ public class UpdateResourceLimitCmd extends BaseCmd {
response.setDomainName(ApiDBUtils.findDomainById(accountTemp.getDomainId()).getName());
}
}
response.setResourceType(limit.getType().ordinal());
response.setResourceType(Integer.valueOf(limit.getType().ordinal()).toString());
response.setMax(limit.getMax());
response.setResponseName(getName());

View File

@ -31,7 +31,7 @@ public class ResourceLimitResponse extends BaseResponse {
private String domainName;
@SerializedName("resourcetype") @Param(description="resource type. Values include 0, 1, 2, 3, 4. See the resourceType parameter for more information on these values.")
private Integer resourceType;
private String resourceType;
@SerializedName("max") @Param(description="the maximum number of the resource. A -1 means the resource currently has no limit.")
private Long max;
@ -60,11 +60,11 @@ public class ResourceLimitResponse extends BaseResponse {
this.domainName = domainName;
}
public Integer getResourceType() {
public String getResourceType() {
return resourceType;
}
public void setResourceType(Integer resourceType) {
public void setResourceType(String resourceType) {
this.resourceType = resourceType;
}

View File

@ -410,6 +410,7 @@ public class AccountManagerImpl implements AccountManager {
public ResourceLimitVO updateResourceLimit(UpdateResourceLimitCmd cmd) throws InvalidParameterValueException {
Account account = (Account)UserContext.current().getAccount();
String accountName = cmd.getAccountName();
Long domainId = cmd.getDomainId();
Long max = cmd.getMax();
Integer type = cmd.getResourceType();
@ -447,9 +448,9 @@ public class AccountManagerImpl implements AccountManager {
}
if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
if ((domainId != null) && (account.getAccountName() == null) && domainId.equals(account.getDomainId())) {
if ((domainId != null) && (accountName == null) && domainId.equals(account.getDomainId())) {
// if the admin is trying to update their own domain, disallow...
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update resource limit for " + ((account.getAccountName() == null) ? "" : "account " + account.getAccountName() + " in ") + "domain " + domainId + ", permission denied");
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update resource limit for domain " + domainId + ", permission denied");
}
// If there is an existing ROOT domain limit, make sure its max isn't being exceeded
@ -471,15 +472,12 @@ public class AccountManagerImpl implements AccountManager {
if (domainId == null) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to update resource limit, unable to determine domain in which to update limit.");
} else if (account != null) {
if (account.getAccountName() != null) {
Account userAccount = _accountDao.findActiveAccount(account.getAccountName(), domainId);
if (userAccount == null) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find account by name " + account.getAccountName() + " in domain with id " + domainId);
}
accountId = userAccount.getId();
domainId = userAccount.getDomainId();
} else if (accountName != null) {
Account userAccount = _accountDao.findActiveAccount(accountName, domainId);
if (userAccount == null) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find account by name " + account.getAccountName() + " in domain with id " + domainId);
}
accountId = userAccount.getId();
}
if (accountId != null) domainId = null;