mirror of https://github.com/apache/cloudstack.git
Merge 6093caa403 into 9bbd32a8ef
This commit is contained in:
commit
75a8c3603e
|
|
@ -2158,16 +2158,33 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||
return deleteAccount(account, callerUserId, caller);
|
||||
}
|
||||
|
||||
protected void checkIfAccountManagesProjects(long accountId) {
|
||||
List<Long> managedProjectIds = _projectAccountDao.listAdministratedProjectIds(accountId);
|
||||
if (!CollectionUtils.isEmpty(managedProjectIds)) {
|
||||
throw new InvalidParameterValueException(String.format(
|
||||
"Unable to delete account [%s], because it manages the following project(s): %s. Please, remove the account from these projects or demote it to a regular project role first.",
|
||||
accountId, managedProjectIds
|
||||
));
|
||||
protected void checkIfAccountManagesProjects(long accountId) {
|
||||
List<Long> managedProjectIds = _projectAccountDao.listAdministratedProjectIds(accountId);
|
||||
|
||||
if (CollectionUtils.isEmpty(managedProjectIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Long> activeManagedProjects = new ArrayList<>();
|
||||
|
||||
for (Long projectId : managedProjectIds) {
|
||||
ProjectVO project = _projectDao.findById(projectId);
|
||||
if (project != null && project.getRemoved() == null) {
|
||||
activeManagedProjects.add(projectId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!activeManagedProjects.isEmpty()) {
|
||||
throw new InvalidParameterValueException(
|
||||
String.format(
|
||||
"Unable to delete account [%s], because it manages the following project(s): %s. Please, remove the account from these projects or demote it to a regular project role first.",
|
||||
accountId, activeManagedProjects
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected boolean isDeleteNeeded(AccountVO account, long accountId, Account caller) {
|
||||
if (account == null) {
|
||||
logger.info(String.format("The account, identified by id %d, doesn't exist", accountId ));
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.Role;
|
||||
|
|
@ -74,6 +76,7 @@ import com.cloud.vm.UserVmManagerImpl;
|
|||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.snapshot.VMSnapshotVO;
|
||||
import com.cloud.projects.ProjectVO;
|
||||
|
||||
public class AccountManagerImplTest extends AccountManagentImplTestBase {
|
||||
|
||||
|
|
@ -1624,6 +1627,23 @@ public class AccountManagerImplTest extends AccountManagentImplTestBase {
|
|||
accountManagerImpl.checkCallerApiPermissionsForUserOrAccountOperations(accountMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckIfAccountManagesOnlyDeletedProjectsDoesNotThrow() {
|
||||
long accountId = 42L;
|
||||
long projectId = 100L;
|
||||
|
||||
Mockito.when(projectAccountDao.listAdministratedProjectIds(accountId))
|
||||
.thenReturn(List.of(projectId));
|
||||
|
||||
ProjectVO deletedProject = Mockito.mock(ProjectVO.class);
|
||||
Mockito.when(deletedProject.getRemoved()).thenReturn(new Date());
|
||||
|
||||
Mockito.when(projectDao.findById(projectId))
|
||||
.thenReturn(deletedProject);
|
||||
|
||||
accountManager.checkIfAccountManagesProjects(accountId);
|
||||
}
|
||||
|
||||
@Test(expected = InvalidParameterValueException.class)
|
||||
public void testPasswordChangeRequiredWithSamlThrowsException() {
|
||||
accountManagerImpl.createUser(
|
||||
|
|
|
|||
Loading…
Reference in New Issue