|
76 | 76 | import org.apache.cloudstack.framework.messagebus.PublishScope;
|
77 | 77 | import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
78 | 78 | import org.apache.cloudstack.network.RoutedIpv4Manager;
|
| 79 | +import org.apache.cloudstack.network.dao.NetworkPermissionDao; |
79 | 80 | import org.apache.cloudstack.region.gslb.GlobalLoadBalancerRuleDao;
|
80 | 81 | import org.apache.cloudstack.resourcedetail.UserDetailVO;
|
81 | 82 | import org.apache.cloudstack.resourcedetail.dao.UserDetailsDao;
|
@@ -303,6 +304,8 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
303 | 304 | private SSHKeyPairDao _sshKeyPairDao;
|
304 | 305 | @Inject
|
305 | 306 | private UserDataDao userDataDao;
|
| 307 | + @Inject |
| 308 | + private NetworkPermissionDao networkPermissionDao; |
306 | 309 |
|
307 | 310 | private List<QuerySelector> _querySelectors;
|
308 | 311 |
|
@@ -898,6 +901,9 @@ protected boolean cleanupAccount(AccountVO account, long callerUserId, Account c
|
898 | 901 | // delete the account from project accounts
|
899 | 902 | _projectAccountDao.removeAccountFromProjects(accountId);
|
900 | 903 |
|
| 904 | + // Delete account's network permissions |
| 905 | + networkPermissionDao.removeAccountPermissions(accountId); |
| 906 | + |
901 | 907 | if (account.getType() != Account.Type.PROJECT) {
|
902 | 908 | // delete the account from group
|
903 | 909 | _messageBus.publish(_name, MESSAGE_REMOVE_ACCOUNT_EVENT, PublishScope.LOCAL, accountId);
|
@@ -1943,22 +1949,23 @@ public boolean deleteUserAccount(long accountId) {
|
1943 | 1949 | return true;
|
1944 | 1950 | }
|
1945 | 1951 |
|
1946 |
| - // Account that manages project(s) can't be removed |
1947 |
| - List<Long> managedProjectIds = _projectAccountDao.listAdministratedProjectIds(accountId); |
1948 |
| - if (!managedProjectIds.isEmpty()) { |
1949 |
| - StringBuilder projectIds = new StringBuilder(); |
1950 |
| - for (Long projectId : managedProjectIds) { |
1951 |
| - projectIds.append(projectId).append(", "); |
1952 |
| - } |
1953 |
| - |
1954 |
| - throw new InvalidParameterValueException(String.format("The account %s with id %d manages project(s) with ids %s and can't be removed", account, accountId, projectIds)); |
1955 |
| - } |
| 1952 | + checkIfAccountManagesProjects(accountId); |
1956 | 1953 |
|
1957 | 1954 | CallContext.current().putContextParameter(Account.class, account.getUuid());
|
1958 | 1955 |
|
1959 | 1956 | return deleteAccount(account, callerUserId, caller);
|
1960 | 1957 | }
|
1961 | 1958 |
|
| 1959 | + protected void checkIfAccountManagesProjects(long accountId) { |
| 1960 | + List<Long> managedProjectIds = _projectAccountDao.listAdministratedProjectIds(accountId); |
| 1961 | + if (!CollectionUtils.isEmpty(managedProjectIds)) { |
| 1962 | + throw new InvalidParameterValueException(String.format( |
| 1963 | + "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.", |
| 1964 | + accountId, managedProjectIds |
| 1965 | + )); |
| 1966 | + } |
| 1967 | + } |
| 1968 | + |
1962 | 1969 | protected boolean isDeleteNeeded(AccountVO account, long accountId, Account caller) {
|
1963 | 1970 | if (account == null) {
|
1964 | 1971 | logger.info(String.format("The account, identified by id %d, doesn't exist", accountId ));
|
|
0 commit comments