DaanHoogland commented on code in PR #9173:
URL: https://github.com/apache/cloudstack/pull/9173#discussion_r1627495823


##########
server/src/main/java/com/cloud/user/AccountManagerImpl.java:
##########
@@ -1287,16 +1287,33 @@ public Pair<Long, Account> 
doInTransaction(TransactionStatus status) {
         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()));
+    /*
+     Role change should follow the below conditions:
+     - Caller should not be of Unknown role type
+     - New role's type should not be Unknown
+     - Caller should not be able to escalate or de-escalate an account's role 
which is of same or higher role type
+     - New role should not of type Admin with domain other than ROOT domain
+     */
+    protected void validateRoleChange(Account account, Role role, Account 
caller) {
+        Role currentRole = roleService.findRole(account.getRoleId());
+        Role callerRole = roleService.findRole(caller.getRoleId());
+        String errorMsg = String.format("Unable to update account role to %s", 
role.getName());

Review Comment:
   meybe add commas to the messages? i.e:
   ```suggestion
           String errorMsg = String.format("Unable to update account role to 
%s, ", role.getName());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to