]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6467 When updating a user, the default group should not be set 595/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 21 Oct 2015 14:35:35 +0000 (16:35 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 22 Oct 2015 07:29:09 +0000 (09:29 +0200)
server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java
server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
server/sonar-server/src/test/resources/org/sonar/server/user/UserUpdaterTest/associate_default_groups_when_updating_user.xml

index 57e6c2e35e58917f7c5c8c34636cfdb9d3f2b199..5b62331ab6771c78fe585f3ea8c5ab5097a12d17 100644 (file)
@@ -95,6 +95,7 @@ public class UserUpdater {
       UserDto existingUser = dbClient.userDao().selectByLogin(dbSession, login);
       if (existingUser == null) {
         saveUser(dbSession, userDto);
+        addDefaultGroup(dbSession, userDto);
       } else {
         if (existingUser.isActive()) {
           throw new IllegalArgumentException(String.format("An active user with login '%s' already exists", login));
@@ -107,6 +108,7 @@ public class UserUpdater {
           .setPasswordConfirmation(newUser.passwordConfirmation());
         updateUserDto(dbSession, updateUser, existingUser);
         updateUser(dbSession, existingUser);
+        addDefaultGroup(dbSession, existingUser);
         isUserReactivated = true;
       }
       dbSession.commit();
@@ -311,7 +313,6 @@ public class UserUpdater {
     long now = system2.now();
     userDto.setActive(true).setUpdatedAt(now);
     dbClient.userDao().update(dbSession, userDto);
-    addDefaultGroup(dbSession, userDto);
   }
 
   private static void setEncryptedPassWord(String password, UserDto userDto) {
index 64a6d7177a8a18b0c06cfc6dd7b7f2d81daf0114..22898e5c06e06f621915b5db485daafedfb8416d 100644 (file)
@@ -36,9 +36,11 @@ import org.sonar.api.platform.NewUserHandler;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.user.GroupDao;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.GroupMembershipDao;
 import org.sonar.db.user.GroupMembershipQuery;
+import org.sonar.db.user.UserDao;
 import org.sonar.db.user.UserDto;
 import org.sonar.db.user.UserGroupDao;
 import org.sonar.server.db.DbClient;
@@ -46,8 +48,6 @@ import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.Message;
 import org.sonar.server.exceptions.ServerException;
-import org.sonar.db.user.GroupDao;
-import org.sonar.db.user.UserDao;
 import org.sonar.server.user.index.UserIndexDefinition;
 import org.sonar.server.user.index.UserIndexer;
 import org.sonar.server.util.Validation;
@@ -794,12 +794,12 @@ public class UserUpdaterTest {
     }
   }
 
-
   @Test
-  public void associate_default_group_when_updating_user() {
+  public void not_associate_default_group_when_updating_user() {
     db.prepareDbUnit(getClass(), "associate_default_groups_when_updating_user.xml");
     createDefaultGroup();
 
+    // Existing user, he has no group, and should not be associated to the default one
     userUpdater.update(UpdateUser.create("marius")
       .setName("Marius2")
       .setEmail("marius2@mail.com")
@@ -811,7 +811,7 @@ public class UserUpdaterTest {
     GroupMembershipFinder.Membership membership = groupMembershipFinder.find(GroupMembershipQuery.builder().login("marius").groupSearch("sonar-users").build());
     assertThat(membership.groups()).hasSize(1);
     assertThat(membership.groups().get(0).name()).isEqualTo("sonar-users");
-    assertThat(membership.groups().get(0).isMember()).isTrue();
+    assertThat(membership.groups().get(0).isMember()).isFalse();
   }
 
   @Test
index 617fe0f8389a6726b900e568f51e0c795b326b41..926b75324ad7b9f3000a788f868844ebd6a88787 100644 (file)
@@ -3,8 +3,4 @@
   <users id="101" login="marius" name="Marius" email="marius@lesbronzes.fr" active="[true]" scm_accounts="&#10;ma&#10;marius33&#10;" created_at="1418215735482" updated_at="1418215735485"
          salt="79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8365" crypted_password="650d2261c98361e2f67f90ce5c65a95e7d8ea2fg"/>
 
-  <groups id="1" name="sonar-devs" description="Sonar Devs" created_at="2014-09-08" updated_at="2014-09-08"/>
-
-  <groups_users user_id="101" group_id="1"/>
-
 </dataset>