diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2015-05-20 15:18:41 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2015-05-26 16:04:31 +0200 |
commit | 35b83f482e98d782a68715a0bc40aa741938daa9 (patch) | |
tree | 02e5b20c604e8d7c6b60b46704f4238a352dd981 | |
parent | 295873f03f60376c9dac7cb9e3e7906470a832d4 (diff) | |
download | sonarqube-35b83f482e98d782a68715a0bc40aa741938daa9.tar.gz sonarqube-35b83f482e98d782a68715a0bc40aa741938daa9.zip |
SONAR-6467 Highlight reactivation of a user upon creation/update
3 files changed, 40 insertions, 4 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/CreateAction.java index be89ca92fbc..143ca191130 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/CreateAction.java @@ -56,7 +56,8 @@ public class CreateAction implements UsersWsAction { @Override public void define(WebService.NewController controller) { WebService.NewAction action = controller.createAction("create") - .setDescription("Create a user. Requires Administer System permission") + .setDescription("Create a user. If a deactivated user account exists with the given login, it will be reactivated. " + + "Requires Administer System permission") .setSince("3.7") .setPost(true) .setHandler(this); diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/UpdateAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/UpdateAction.java index 19d6c41db86..d3cf1fa69fe 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/UpdateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/UpdateAction.java @@ -52,7 +52,8 @@ public class UpdateAction implements UsersWsAction { @Override public void define(WebService.NewController controller) { WebService.NewAction action = controller.createAction("update") - .setDescription("Update a user. Requires Administer System permission. Since 5.2, a user's password can only be changed using the 'change_password' action.") + .setDescription("Update a user. If a deactivated user account exists with the given login, it will be reactivated. " + + "Requires Administer System permission. Since 5.2, a user's password can only be changed using the 'change_password' action.") .setSince("3.7") .setPost(true) .setHandler(this) diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java index a96cd3b697c..9f17e500e9e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java @@ -21,6 +21,7 @@ package org.sonar.server.user; import com.google.common.base.Strings; +import java.util.List; import org.elasticsearch.search.SearchHit; import org.junit.After; import org.junit.Before; @@ -54,8 +55,6 @@ import org.sonar.server.user.index.UserIndexer; import org.sonar.server.util.Validation; import org.sonar.test.DbTests; -import java.util.List; - import static com.google.common.collect.Lists.newArrayList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.MapEntry.entry; @@ -603,6 +602,41 @@ public class UserUpdaterTest { } @Test + public void reactivate_user_on_update() { + db.prepareDbUnit(getClass(), "reactivate_user.xml"); + when(system2.now()).thenReturn(1418215735486L); + createDefaultGroup(); + + userUpdater.update(UpdateUser.create("marius") + .setName("Marius2") + .setEmail("marius2@mail.com") + .setPassword("password2") + .setPasswordConfirmation("password2") + .setScmAccounts(newArrayList("ma2"))); + session.commit(); + session.clearCache(); + + UserDto dto = userDao.selectNullableByLogin(session, "marius"); + assertThat(dto.isActive()).isTrue(); + assertThat(dto.getName()).isEqualTo("Marius2"); + assertThat(dto.getEmail()).isEqualTo("marius2@mail.com"); + assertThat(dto.getScmAccountsAsList()).containsOnly("ma2"); + + assertThat(dto.getSalt()).isNotEqualTo("79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8365"); + assertThat(dto.getCryptedPassword()).isNotEqualTo("650d2261c98361e2f67f90ce5c65a95e7d8ea2fg"); + assertThat(dto.getCreatedAt()).isEqualTo(1418215735482L); + assertThat(dto.getUpdatedAt()).isEqualTo(1418215735486L); + + List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER); + assertThat(indexUsers).hasSize(1); + assertThat(indexUsers.get(0).getSource()) + .contains( + entry("login", "marius"), + entry("name", "Marius2"), + entry("email", "marius2@mail.com")); + } + + @Test public void update_user_with_scm_accounts_containing_blank_entry() { db.prepareDbUnit(getClass(), "update_user.xml"); createDefaultGroup(); |