mirror of https://github.com/apache/cloudstack.git
api: Update account type when updating account role (#6156)
* api: Update account type when updating account role * extract code to validate role change
This commit is contained in:
parent
306baea228
commit
9cc8da2a30
|
|
@ -1181,6 +1181,18 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||
return _userAccountDao.findById(userId);
|
||||
}
|
||||
|
||||
private boolean isValidRoleChange(Account account, Role role) {
|
||||
Long currentAccRoleId = account.getRoleId();
|
||||
Role currentRole = roleService.findRole(currentAccRoleId);
|
||||
|
||||
if (role.getRoleType().ordinal() < currentRole.getRoleType().ordinal() && ((account.getType() == Account.Type.NORMAL && role.getRoleType().getAccountType().ordinal() > Account.Type.NORMAL.ordinal()) ||
|
||||
account.getType().ordinal() > Account.Type.NORMAL.ordinal() && role.getRoleType().getAccountType().ordinal() < account.getType().ordinal() && role.getRoleType().getAccountType().ordinal() > 0)) {
|
||||
throw new PermissionDeniedException(String.format("Unable to update account role to %s as you are " +
|
||||
"attempting to escalate the account %s to account type %s which has higher privileges", role.getName(), account.getAccountName(), role.getRoleType().getAccountType().name()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* if there is any permission under the requested role that is not permitted for the caller, refuse
|
||||
*/
|
||||
|
|
@ -1897,7 +1909,10 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||
"in the domain '" + domainId + "'.");
|
||||
}
|
||||
|
||||
Role role = roleService.findRole(roleId);
|
||||
isValidRoleChange(account, role);
|
||||
acctForUpdate.setRoleId(roleId);
|
||||
acctForUpdate.setType(role.getRoleType().getAccountType());
|
||||
checkRoleEscalation(getCurrentCallingAccount(), acctForUpdate);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue