listTemplates/listIsos - template filter "all" can be specified by admin only. Throw an error when user tries to use it

This commit is contained in:
Alena Prokharchyk 2012-10-04 09:46:09 -07:00
parent f4a2298ca9
commit 43b406279a
2 changed files with 16 additions and 4 deletions

View File

@ -23,7 +23,6 @@ import java.util.Set;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.BaseListTaggedResourcesCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;

View File

@ -1260,7 +1260,13 @@ public class ManagementServerImpl implements ManagementServer {
Account caller = UserContext.current().getCaller();
Map<String, String> tags = cmd.getTags();
boolean listAll = (caller.getType() != Account.ACCOUNT_TYPE_NORMAL && (isoFilter != null && isoFilter == TemplateFilter.all));
boolean listAll = false;
if (isoFilter != null && isoFilter == TemplateFilter.all) {
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
throw new InvalidParameterValueException("Filter " + TemplateFilter.all + " can be specified by admin only", null);
}
listAll = true;
}
List<Long> permittedAccountIds = new ArrayList<Long>();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
_accountMgr.buildACLSearchParameters(caller, cmd.getId(), cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject, listAll, false);
@ -1282,8 +1288,15 @@ public class ManagementServerImpl implements ManagementServer {
Long id = cmd.getId();
Map<String, String> tags = cmd.getTags();
Account caller = UserContext.current().getCaller();
boolean listAll = (caller.getType() != Account.ACCOUNT_TYPE_NORMAL && (templateFilter != null && templateFilter == TemplateFilter.all));
boolean listAll = false;
if (templateFilter != null && templateFilter == TemplateFilter.all) {
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
throw new InvalidParameterValueException("Filter " + TemplateFilter.all + " can be specified by admin only", null);
}
listAll = true;
}
List<Long> permittedAccountIds = new ArrayList<Long>();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject, listAll, false);