Fixed listNetworks for the case when a) caller is an admin 2) projectId=-1 is specified - admin wasn't able to list networks belonging to regular users' projects

This commit is contained in:
Alena Prokharchyk 2012-11-06 16:02:20 -08:00
parent 9d7f48c40d
commit 74622a4dc3
3 changed files with 8 additions and 6 deletions

View File

@ -26,7 +26,6 @@ import com.cloud.api.BaseListCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.ZoneResponse;
import com.cloud.dc.DataCenter;

View File

@ -203,6 +203,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.Nic;
import com.cloud.vm.Nic.ReservationStrategy;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
@ -3030,7 +3031,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
if (!_accountMgr.isAdmin(caller.getType()) || (!listAll && (projectId != null && projectId != -1 && domainId == null))) {
if (!_accountMgr.isAdmin(caller.getType()) || (!listAll && (projectId != null && projectId.longValue() != -1 && domainId == null))) {
permittedAccounts.add(caller.getId());
domainId = caller.getDomainId();
}
@ -3038,8 +3039,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
// set project information
boolean skipProjectNetworks = true;
if (projectId != null) {
if (projectId == -1) {
permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
if (projectId.longValue() == -1) {
if (!_accountMgr.isAdmin(caller.getType())) {
permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
}
} else {
permittedAccounts.clear();
Project project = _projectMgr.getProject(projectId);

View File

@ -1576,7 +1576,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
// set project information
if (projectId != null) {
if (projectId == -1) {
if (projectId.longValue() == -1) {
permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
} else {
permittedAccounts.clear();
@ -2327,7 +2327,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
// set project information
if (projectId != null) {
if (!forProjectInvitation) {
if (projectId == -1) {
if (projectId.longValue() == -1) {
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
} else {