mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
bug 9620: fixed updateUser api to make updates only for the fields that are specified in the request
status 9620: resolved fixed
This commit is contained in:
parent
8b100f7c4d
commit
5be1f94c0d
@ -1403,32 +1403,42 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
|
||||
checkAccess(UserContext.current().getCaller(), account);
|
||||
|
||||
if (firstName == null) {
|
||||
firstName = user.getFirstname();
|
||||
if (firstName != null) {
|
||||
user.setFirstname(firstName);
|
||||
}
|
||||
if (lastName == null) {
|
||||
lastName = user.getLastname();
|
||||
if (lastName != null) {
|
||||
user.setLastname(lastName);
|
||||
}
|
||||
if (userName == null) {
|
||||
userName = user.getUsername();
|
||||
if (userName != null) {
|
||||
//don't allow to have same user names in the same domain
|
||||
List<UserVO> duplicatedUsers = _userDao.findUsersLike(userName);
|
||||
for (UserVO duplicatedUser : duplicatedUsers) {
|
||||
if (duplicatedUser.getId() != user.getId()) {
|
||||
Account duplicatedUserAccount = _accountDao.findById(duplicatedUser.getAccountId());
|
||||
if (duplicatedUserAccount.getDomainId() == account.getDomainId()) {
|
||||
throw new InvalidParameterValueException("User with name " + userName + " already exists in domain " + duplicatedUserAccount.getDomainId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
user.setUsername(userName);
|
||||
}
|
||||
if (password == null) {
|
||||
password = user.getPassword();
|
||||
if (password != null) {
|
||||
user.setPassword(password);
|
||||
}
|
||||
if (email == null) {
|
||||
email = user.getEmail();
|
||||
if (email != null) {
|
||||
user.setEmail(email);
|
||||
}
|
||||
if (timeZone == null) {
|
||||
timeZone = user.getTimezone();
|
||||
if (timeZone != null) {
|
||||
user.setTimezone(timeZone);
|
||||
}
|
||||
if (apiKey == null) {
|
||||
apiKey = user.getApiKey();
|
||||
if (apiKey != null) {
|
||||
user.setApiKey(apiKey);
|
||||
}
|
||||
if (secretKey == null) {
|
||||
secretKey = user.getSecretKey();
|
||||
if (secretKey != null) {
|
||||
user.setSecretKey(secretKey);
|
||||
}
|
||||
|
||||
Long accountId = user.getAccountId();
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("updating user with id: " + id);
|
||||
@ -1447,8 +1457,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_userDao.update(id, userName, password, firstName, lastName, email, accountId, timeZone, apiKey, secretKey);
|
||||
|
||||
_userDao.update(id, user);
|
||||
} catch (Throwable th) {
|
||||
s_logger.error("error updating user", th);
|
||||
throw new CloudRuntimeException("Unable to update user " + id);
|
||||
|
||||
@ -33,21 +33,6 @@ public interface UserDao extends GenericDao<UserVO, Long>{
|
||||
UserVO getUser(long userId);
|
||||
List<UserVO> findUsersLike(String username);
|
||||
|
||||
/**
|
||||
* updates a user with the new username, password, firstname, lastname, email,accountId, timezone
|
||||
* @param id
|
||||
* @param username
|
||||
* @param password
|
||||
* @param firstname
|
||||
* @param lastname
|
||||
* @param email
|
||||
* @param accountId
|
||||
* @param timezone
|
||||
* @param apikey
|
||||
* @param secretkey
|
||||
*/
|
||||
void update(long id, String username, String password, String firstname, String lastname, String email, Long accountId, String timezone, String apiKey, String secretKey);
|
||||
|
||||
List<UserVO> listByAccount(long accountId);
|
||||
|
||||
/**
|
||||
|
||||
@ -26,7 +26,6 @@ import com.cloud.user.UserVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
/**
|
||||
* Implementation of the UserDao
|
||||
@ -116,29 +115,6 @@ public class UserDaoImpl extends GenericDaoBase<UserVO, Long> implements UserDao
|
||||
SearchCriteria<UserVO> sc = SecretKeySearch.create();
|
||||
sc.setParameters("secretKey", secretKey);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(long id, String username, String password, String firstname, String lastname, String email, Long accountId, String timezone, String apiKey, String secretKey)
|
||||
{
|
||||
UserVO dbUser = getUser(username);
|
||||
if ((dbUser == null) || (dbUser.getId() == id)) {
|
||||
UserVO ub = createForUpdate();
|
||||
ub.setUsername(username);
|
||||
ub.setPassword(password);
|
||||
ub.setFirstname(firstname);
|
||||
ub.setLastname(lastname);
|
||||
ub.setEmail(email);
|
||||
ub.setAccountId(accountId);
|
||||
ub.setTimezone(timezone);
|
||||
ub.setApiKey(apiKey);
|
||||
ub.setSecretKey(secretKey);
|
||||
update(id, ub);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CloudRuntimeException("unable to update user -- a user with that name exists");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user