Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions server/src/main/java/com/cloud/user/AccountManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2100,14 +2100,30 @@ public boolean deleteUserAccount(long accountId) {

protected void checkIfAccountManagesProjects(long accountId) {
List<Long> managedProjectIds = _projectAccountDao.listAdministratedProjectIds(accountId);
if (!CollectionUtils.isEmpty(managedProjectIds)) {
throw new InvalidParameterValueException(String.format(

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, managedProjectIds
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 ));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
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 {

Expand Down Expand Up @@ -1388,6 +1389,9 @@ public void checkIfAccountManagesProjectsTestThrowExceptionWhenTheAccountIsAProj
List<Long> managedProjectIds = List.of(1L);

Mockito.when(_projectAccountDao.listAdministratedProjectIds(accountId)).thenReturn(managedProjectIds);
ProjectVO project = Mockito.mock(ProjectVO.class);
Mockito.when(project.getRemoved()).thenReturn(null);
Mockito.when(_projectDao.findById(1L)).thenReturn(project);
accountManagerImpl.checkIfAccountManagesProjects(accountId);
}

Expand Down
Loading