setEncryptedPassWord(password, userDto);
List<String> scmAccounts = sanitizeScmAccounts(newUser.scmAccounts());
- validateScmAccounts(dbSession, scmAccounts, login, email, messages);
+ validateScmAccounts(dbSession, scmAccounts, login, email, null, messages);
userDto.setScmAccounts(convertScmAccountsToCsv(scmAccounts));
if (!messages.isEmpty()) {
if (updateUser.isScmAccountsChanged()) {
List<String> scmAccounts = sanitizeScmAccounts(updateUser.scmAccounts());
- validateScmAccounts(dbSession, scmAccounts, userDto.getLogin(), email != null ? email : userDto.getEmail(), messages);
+ validateScmAccounts(dbSession, scmAccounts, userDto.getLogin(), email != null ? email : userDto.getEmail(), userDto, messages);
userDto.setScmAccounts(convertScmAccountsToCsv(scmAccounts));
}
}
}
- private void validateScmAccounts(DbSession dbSession, @Nullable List<String> scmAccounts, @Nullable String login, @Nullable String email, List<Message> messages) {
+ private void validateScmAccounts(DbSession dbSession, @Nullable List<String> scmAccounts, @Nullable String login, @Nullable String email, @Nullable UserDto existingUser,
+ List<Message> messages) {
if (scmAccounts != null) {
for (String scmAccount : scmAccounts) {
if (scmAccount.equals(login) || scmAccount.equals(email)) {
} else {
UserDto matchingUser = dbClient.userDao().selectNullableByScmAccountOrLoginOrName(dbSession, scmAccount);
if (matchingUser != null) {
- messages.add(Message.of("user.scm_account_already_used", scmAccount, matchingUser.getName(), matchingUser.getLogin()));
+ if (existingUser == null || !matchingUser.getId().equals(existingUser.getId())) {
+ messages.add(Message.of("user.scm_account_already_used", scmAccount, matchingUser.getName(), matchingUser.getLogin()));
+ }
}
}
}
assertThat(dto.getCryptedPassword()).isEqualTo("650d2261c98361e2f67f90ce5c65a95e7d8ea2fg");
}
+ @Test
+ public void update_scm_accounts_with_same_values() throws Exception {
+ db.prepareDbUnit(getClass(), "update_user.xml");
+ createDefaultGroup();
+
+ userUpdater.update(UpdateUser.create("marius")
+ .setScmAccounts(newArrayList("ma", "marius33")));
+ session.commit();
+ session.clearCache();
+
+ UserDto dto = userDao.selectNullableByLogin(session, "marius");
+ assertThat(dto.getScmAccounts()).isEqualTo(",ma,marius33,");
+ }
+
@Test
public void remove_scm_accounts() throws Exception {
db.prepareDbUnit(getClass(), "update_user.xml");