rafaelweingartner commented on a change in pull request #3058: CLOUDSTACK-3049: 
update dynamic role for an account
URL: https://github.com/apache/cloudstack/pull/3058#discussion_r236713067
 
 

 ##########
 File path: server/src/main/java/com/cloud/user/AccountManagerImpl.java
 ##########
 @@ -1714,23 +1720,37 @@ public AccountVO updateAccount(UpdateAccountCmd cmd) {
         // Check if user performing the action is allowed to modify this 
account
         checkAccess(getCurrentCallingAccount(), 
_domainMgr.getDomain(account.getDomainId()));
 
-        // check if the given account name is unique in this domain for 
updating
-        Account duplicateAcccount = 
_accountDao.findActiveAccount(newAccountName, domainId);
-        if (duplicateAcccount != null && duplicateAcccount.getId() != 
account.getId()) {
-            throw new InvalidParameterValueException(
-                    "There already exists an account with the name:" + 
newAccountName + " in the domain:" + domainId + " with existing account id:" + 
duplicateAcccount.getId());
+        if(newAccountName != null) {
 
 Review comment:
   What I am saying is the following:
   
   Instead of (the current code):
   ```
    if(newAccountName != null) {
   
               if (newAccountName.isEmpty()) {
                   throw new InvalidParameterValueException("The new account 
name for account '" + account.getUuid() + "' " +
                           "within domain '" + domainId + "'  is empty string. 
Account will be not renamed.");
               }
   
               // check if the new proposed account name is absent in the domain
               Account existingAccount = 
_accountDao.findActiveAccount(newAccountName, domainId);
               if (existingAccount != null && existingAccount.getId() != 
account.getId()) {
                   throw new InvalidParameterValueException("The account with 
the proposed name '" +
                           newAccountName + "' exists in the domain '" +
                           domainId + "' with existing account id '" + 
existingAccount.getId() + "'");
               }
   
               acctForUpdate.setAccountName(newAccountName);
           }
   ```
   
   You can do the following:
   
   ```
    if(StringUtils.isBlank(newAccountName)) {
            throw new InvalidParameterValueException("The new account name for 
account '" + account.getUuid() + "' " +
                           "within domain '" + domainId + "'  is an empty 
string. Account will be not renamed.");
   
     }
   
        // check if the new proposed account name is absent in the domain
        Account existingAccount = _accountDao.findActiveAccount(newAccountName, 
domainId);
        if (existingAccount != null && existingAccount.getId() != 
account.getId()) {
                throw new InvalidParameterValueException("The account with the 
proposed name '" +
                                newAccountName + "' exists in the domain '" +
                                domainId + "' with existing account id '" + 
existingAccount.getId() + "'");
        }
   
     acctForUpdate.setAccountName(newAccountName);
   
   ```
   
   By doing that you remove one nesting level.
   
   Did you understand what I am saying now?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to