]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9356 Add column USERS.ONBOARDED
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 9 Jun 2017 15:35:22 +0000 (17:35 +0200)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 20 Jun 2017 11:10:53 +0000 (04:10 -0700)
36 files changed:
server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTesting.java
server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/exists_by_email.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/insert-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectActiveUserByLogin.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByIds.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByLogins.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByQuery.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByText.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_by_login.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_nullable_by_scm_account.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_nullable_by_scm_account_return_many_results_when_same_email_is_used_by_many_users.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/update_user.xml
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboarded.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboarded.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboardedTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboardedTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboardedTest/users_without_onboarded_column.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullableTest/users_with_nullable_onboarded_column.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboardedTest/users_with_onboarded_column.sql [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/user/DeprecatedUserFinderTest/fixture.xml
server/sonar-server/src/test/resources/org/sonar/server/user/index/UserIndexerTest/index.xml

index 8d3b0c44ad457196994e68bedc3f0a5cb1503228..cd82a9bb62d60ab6d5903a47085bd3a9f80e76b4 100644 (file)
@@ -1,4 +1,4 @@
-INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, IS_ROOT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', false, '1418215735482', '1418215735482');
+INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, IS_ROOT, ONBOARDED, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', false, false, '1418215735482', '1418215735482');
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
 
 INSERT INTO GROUPS(ID, ORGANIZATION_UUID, NAME, DESCRIPTION, CREATED_AT, UPDATED_AT) VALUES (1, 'AVdqnciQUUs7Zd3KPvFD', 'sonar-administrators', 'System administrators', '2011-09-26 22:27:51.0', '2011-09-26 22:27:51.0');
index b561d120bec073b4508a23a5fd58db6bdc80452e..5901161d0d1c68b5db2ee050e7c32c748de04e56 100644 (file)
@@ -407,6 +407,7 @@ CREATE TABLE "USERS" (
   "EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100),
   "IS_ROOT" BOOLEAN NOT NULL,
   "USER_LOCAL" BOOLEAN,
+  "ONBOARDED" BOOLEAN NOT NULL,
   "CREATED_AT" BIGINT,
   "UPDATED_AT" BIGINT
 );
index 7f41ce65250db45b96b01ef5cfa53b45f9bc2124..e85f6ed878543b07ad358ddb8b5abc69449e7593 100644 (file)
@@ -51,6 +51,7 @@ public class UserDto {
   private Long updatedAt;
   private boolean local = true;
   private boolean root = false;
+  private boolean onboarded = false;
 
   public Integer getId() {
     return id;
@@ -218,6 +219,15 @@ public class UserDto {
     this.root = root;
   }
 
+  public boolean isOnboarded() {
+    return onboarded;
+  }
+
+  public UserDto setOnboarded(boolean onboarded) {
+    this.onboarded = onboarded;
+    return this;
+  }
+
   public static String encryptPassword(String password, String salt) {
     requireNonNull(password, "Password cannot be empty");
     requireNonNull(salt, "Salt cannot be empty");
index 63eafbcef3f30d7e1cc14b0e83320c53d73e7a13..ef9d08398dfde6ec714d9bf3565288dd7cd5de21 100644 (file)
@@ -16,6 +16,7 @@
     u.external_identity_provider as "externalIdentityProvider",
     u.user_local as "local",
     u.is_root as "root",
+    u.onboarded as "onboarded",
     u.created_at as "createdAt",
     u.updated_at as "updatedAt"
   </sql>
       salt,
       crypted_password,
       is_root,
+      onboarded,
       created_at,
       updated_at
     )
       #{salt,jdbcType=VARCHAR},
       #{cryptedPassword,jdbcType=VARCHAR},
       #{root,jdbcType=BOOLEAN},
+      #{onboarded,jdbcType=BOOLEAN},
       #{createdAt,jdbcType=BIGINT},
       #{updatedAt,jdbcType=BIGINT}
     )
       external_identity=#{externalIdentity,jdbcType=VARCHAR},
       external_identity_provider=#{externalIdentityProvider,jdbcType=VARCHAR},
       user_local=#{local,jdbcType=BOOLEAN},
+      onboarded=#{onboarded,jdbcType=BOOLEAN},
       salt=#{salt,jdbcType=VARCHAR},
       crypted_password=#{cryptedPassword,jdbcType=BIGINT},
       updated_at=#{updatedAt,jdbcType=BIGINT}
index 3acf9a2b530c95e99fe731a189c17822693cc6be..c6f54ca0503d638872e9db809b8677f62599e975 100644 (file)
@@ -307,6 +307,7 @@ public class UserDaoTest {
       .setEmail("jo@hn.com")
       .setScmAccounts(",jo.hn,john2,")
       .setActive(true)
+      .setOnboarded(true)
       .setSalt("1234")
       .setCryptedPassword("abcd")
       .setExternalIdentity("johngithub")
@@ -324,6 +325,7 @@ public class UserDaoTest {
     assertThat(user.getName()).isEqualTo("John");
     assertThat(user.getEmail()).isEqualTo("jo@hn.com");
     assertThat(user.isActive()).isTrue();
+    assertThat(user.isOnboarded()).isTrue();
     assertThat(user.getScmAccounts()).isEqualTo(",jo.hn,john2,");
     assertThat(user.getSalt()).isEqualTo("1234");
     assertThat(user.getCryptedPassword()).isEqualTo("abcd");
@@ -344,7 +346,8 @@ public class UserDaoTest {
       .setCreatedAt(1418215735482L)
       .setUpdatedAt(1418215735482L)
       .setActive(true)
-      .setLocal(true);
+      .setLocal(true)
+      .setOnboarded(false);
     db.getDbClient().userDao().insert(db.getSession(), existingUser);
     db.getSession().commit();
 
@@ -355,6 +358,7 @@ public class UserDaoTest {
       .setEmail("jodoo@hn.com")
       .setScmAccounts(",jo.hn,john2,johndoo,")
       .setActive(false)
+      .setOnboarded(true)
       .setSalt("12345")
       .setCryptedPassword("abcde")
       .setExternalIdentity("johngithub")
@@ -371,6 +375,7 @@ public class UserDaoTest {
     assertThat(user.getName()).isEqualTo("John Doo");
     assertThat(user.getEmail()).isEqualTo("jodoo@hn.com");
     assertThat(user.isActive()).isFalse();
+    assertThat(user.isOnboarded()).isTrue();
     assertThat(user.getScmAccounts()).isEqualTo(",jo.hn,john2,johndoo,");
     assertThat(user.getSalt()).isEqualTo("12345");
     assertThat(user.getCryptedPassword()).isEqualTo("abcde");
index 682699ad4d9ac5b5728608acad755324f48a95d2..b9bba58527b17f62dc124abe2bafcce08e35889a 100644 (file)
@@ -23,70 +23,60 @@ import javax.annotation.Nullable;
 
 import static java.util.Collections.singletonList;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.apache.commons.lang.math.RandomUtils.nextBoolean;
 import static org.apache.commons.lang.math.RandomUtils.nextInt;
 import static org.apache.commons.lang.math.RandomUtils.nextLong;
 
 public class UserTesting {
 
   public static UserDto newUserDto() {
-    return newUserDto(randomAlphanumeric(30), randomAlphanumeric(30), randomAlphanumeric(30));
-  }
-
-  public static UserDto newUserDto(String login, String name, @Nullable String email) {
     return new UserDto()
       .setId(nextInt())
       .setActive(true)
-      .setLocal(true)
-      .setName(name)
-      .setEmail(email)
-      .setLogin(login)
+      .setLocal(nextBoolean())
+      .setLogin(randomAlphanumeric(30))
+      .setName(randomAlphanumeric(30))
+      .setEmail(randomAlphanumeric(30))
+      .setOnboarded(nextBoolean())
       .setScmAccounts(singletonList(randomAlphanumeric(40)))
-      .setExternalIdentity(login)
-      .setExternalIdentityProvider("sonarqube")
+      .setExternalIdentity(randomAlphanumeric(40))
+      .setExternalIdentityProvider(randomAlphanumeric(40))
       .setSalt(randomAlphanumeric(40))
       .setCryptedPassword(randomAlphanumeric(40))
       .setCreatedAt(nextLong())
       .setUpdatedAt(nextLong());
   }
 
+  public static UserDto newUserDto(String login, String name, @Nullable String email) {
+    return newUserDto()
+      .setName(name)
+      .setEmail(email)
+      .setLogin(login);
+  }
+
   public static UserDto newLocalUser(String login, String name, @Nullable String email) {
-    return new UserDto()
-      .setId(nextInt())
-      .setActive(true)
+    return newUserDto()
       .setLocal(true)
       .setName(name)
       .setEmail(email)
       .setLogin(login)
-      .setScmAccounts(singletonList(randomAlphanumeric(40)))
       .setExternalIdentity(login)
-      .setExternalIdentityProvider("sonarqube")
-      .setSalt(randomAlphanumeric(40))
-      .setCryptedPassword(randomAlphanumeric(40))
-      .setCreatedAt(nextLong())
-      .setUpdatedAt(nextLong());
+      .setExternalIdentityProvider("sonarqube");
   }
 
   public static UserDto newExternalUser(String login, String name, @Nullable String email) {
-    return new UserDto()
-      .setId(nextInt())
-      .setActive(true)
+    return newUserDto()
       .setLocal(false)
       .setName(name)
       .setEmail(email)
       .setLogin(login)
-      .setScmAccounts(singletonList(randomAlphanumeric(40)))
       .setExternalIdentity(randomAlphanumeric(40))
-      .setExternalIdentityProvider(randomAlphanumeric(40))
-      .setCreatedAt(nextLong())
-      .setUpdatedAt(nextLong());
+      .setExternalIdentityProvider(randomAlphanumeric(40));
   }
 
   public static UserDto newDisabledUser(String login) {
-    return new UserDto()
-      .setId(nextInt())
+    return newUserDto()
       .setLogin(login)
-      .setActive(false)
-      .setCreatedAt(nextLong())
-      .setUpdatedAt(nextLong());
+      .setActive(false);
   }
 }
index 9ad332d06d76474100926619cfe77330c769760c..c3a899ddf49db51295486378f701012ede962530 100644 (file)
@@ -4,22 +4,26 @@
          login="user1"
          name="User1"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="201"
          login="user2"
          name="User2"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="202"
          login="user3"
          name="User3"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="999"
          login="disabledUser"
          name="disabledUser"
          active="[false]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
   <organization_members
       user_id="200"
index 0339e3dbd5540f70eb3a3a0d365d10fee9a5efec..8382a060d2779bd238bfc996d17b51c3b7a833ac 100644 (file)
@@ -4,17 +4,20 @@
          login="user1"
          name="User1"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="201"
          login="user2"
          name="User2"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="202"
          login="user3"
          name="User3"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
   <organization_members
     user_id="200"
index 13a3f1f3e0abaa834bd6317948786d1165f452a2..56e76fad3f90241f9156419cb75cd43c02cc05e3 100644 (file)
@@ -4,17 +4,20 @@
          login="user3"
          name="User3"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="201"
          login="user1"
          name="User1"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="202"
          login="user2"
          name="User2"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
   <organization_members
       user_id="200"
index 63dd4a57e8dadce83a87c15a4d79fbae4c39975f..2226bb3ba34eeea049944251add3f04e9e009a49 100644 (file)
@@ -10,7 +10,8 @@
          updated_at="1418215735485"
          salt="79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8365"
          crypted_password="650d2261c98361e2f67f90ce5c65a95e7d8ea2fg"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="102"
          login="sbrandhof"
          name="Simon Brandhof"
@@ -21,6 +22,7 @@
          updated_at="1418215735485"
          salt="79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8366"
          crypted_password="650d2261c98361e2f67f90ce5c65a95e7d8ea2fh"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
 </dataset>
index a15c10259bcd463abfd074e6b360ff26277e27f4..fe3a43320a9a65f12bc12c0af5e1cca4fa1f0bea 100644 (file)
@@ -6,5 +6,6 @@
          created_at="1418215735482"
          updated_at="1418215735482"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 </dataset>
index aa0b64fadf2d10be3d4ff0a18f4aa596d5ee031f..fba9650f48b77cc5d9073475239c47c6358aeb2d 100644 (file)
@@ -7,7 +7,8 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[false]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
   <!-- active -->
   <users id="101"
@@ -17,7 +18,8 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
   <users id="102"
          login="jcdus"
@@ -26,7 +28,8 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
 
 </dataset>
index 65e155941df61cbf379b1073ea394cb55e51525e..7340c944abb6569f4db45a2aaf33aee3bb8b46e6 100644 (file)
@@ -6,7 +6,8 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[false]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="101"
          login="marius"
          name="Marius"
@@ -14,7 +15,8 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="102"
          login="jcdus"
          name="Jean-Claude Dus"
@@ -22,6 +24,7 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
 </dataset>
index 65e155941df61cbf379b1073ea394cb55e51525e..7340c944abb6569f4db45a2aaf33aee3bb8b46e6 100644 (file)
@@ -6,7 +6,8 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[false]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="101"
          login="marius"
          name="Marius"
@@ -14,7 +15,8 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="102"
          login="jcdus"
          name="Jean-Claude Dus"
@@ -22,6 +24,7 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
 </dataset>
index 8f6bacd7c43476347e60b7d735e1a992215b7d9f..246d4caf77e71794afe9bd7a3b8573609112bdd8 100644 (file)
@@ -6,7 +6,8 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[false]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="101"
          login="marius"
          name="Marius"
@@ -14,6 +15,7 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
 </dataset>
index 89b1302e298af22fb4301274ecba94a9ecdb7b05..c4308ee82affcf5ccbea42c7c6cdf27db1182d6e 100644 (file)
@@ -6,7 +6,8 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="102"
          login="sbrandhof"
          name="Simon Brandhof"
@@ -14,6 +15,7 @@
          created_at="1418215735482"
          updated_at="1418215735485"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
 </dataset>
index d07ecce8728dcbcf957f813813c128545b495d7a..2ac78040cab57f9a6e5cb792d8fed1be9da9bc5c 100644 (file)
@@ -10,7 +10,8 @@
          updated_at="1418215735485"
          salt="79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8365"
          crypted_password="650d2261c98361e2f67f90ce5c65a95e7d8ea2fg"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="102"
          login="sbrandhof"
          name="Simon Brandhof"
@@ -21,6 +22,7 @@
          updated_at="1418215735485"
          salt="79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8366"
          crypted_password="650d2261c98361e2f67f90ce5c65a95e7d8ea2fh"
-         is_root="[true]"/>
+         is_root="[true]"
+         onboarded="[true]"/>
 
 </dataset>
index 3ded656c9f455addbeeb467c1e78d77fe7331f21..54b486eb3e3dc076967e081e010dfae1e880f393 100644 (file)
@@ -10,7 +10,8 @@
          updated_at="1418215735485"
          salt="79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8365"
          crypted_password="650d2261c98361e2f67f90ce5c65a95e7d8ea2fg"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="102"
          login="sbrandhof"
          name="Simon Brandhof"
@@ -21,6 +22,7 @@
          updated_at="1418215735485"
          salt="79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8366"
          crypted_password="650d2261c98361e2f67f90ce5c65a95e7d8ea2fh"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
 </dataset>
index 63dd4a57e8dadce83a87c15a4d79fbae4c39975f..2226bb3ba34eeea049944251add3f04e9e009a49 100644 (file)
@@ -10,7 +10,8 @@
          updated_at="1418215735485"
          salt="79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8365"
          crypted_password="650d2261c98361e2f67f90ce5c65a95e7d8ea2fg"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="102"
          login="sbrandhof"
          name="Simon Brandhof"
@@ -21,6 +22,7 @@
          updated_at="1418215735485"
          salt="79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8366"
          crypted_password="650d2261c98361e2f67f90ce5c65a95e7d8ea2fh"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
 </dataset>
index a15c10259bcd463abfd074e6b360ff26277e27f4..fe3a43320a9a65f12bc12c0af5e1cca4fa1f0bea 100644 (file)
@@ -6,5 +6,6 @@
          created_at="1418215735482"
          updated_at="1418215735482"
          active="[true]"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 </dataset>
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboarded.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboarded.java
new file mode 100644 (file)
index 0000000..7b6d202
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v65;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
+
+public class AddUsersOnboarded extends DdlChange {
+  public AddUsersOnboarded(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDialect(), "users")
+      .addColumn(newBooleanColumnDefBuilder()
+        .setColumnName("onboarded")
+        .setIsNullable(true)
+        .build())
+      .build());
+  }
+}
index 75ac30953ab059147477a826cbb28512c74c7dc8..5dd66b0249086b88321a65d4d0471f1d3a18e058 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+
 package org.sonar.server.platform.db.migration.version.v65;
 
 import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
@@ -55,6 +56,10 @@ public class DbVersion65 implements DbVersion {
       .add(1726, "Update org_qprofiles to reference built-in profiles", UpdateOrgQProfilesToPointToBuiltInProfiles.class)
       .add(1727, "Delete rules_profiles orphans", DeleteOrphansFromRulesProfiles.class)
       .add(1728, "Rename column qprofile_changes.qprofile_key to qprofile_changes.rules_profile_uuid", RenameQProfileKeyToRulesProfileUuidOnQProfileChanges.class)
-      .add(1729, "Add index on qprofile_changes.rules_profile_uuid", AddIndexRulesProfileUuidOnQProfileChanges.class);
+      .add(1729, "Add index on qprofile_changes.rules_profile_uuid", AddIndexRulesProfileUuidOnQProfileChanges.class)
+      .add(1730, "Add USERS.ONBOARDED", AddUsersOnboarded.class)
+      .add(1731, "Populate USERS.ONBOARDED", PopulateUsersOnboarded.class)
+      .add(1732, "Make USERS.ONBOARDED not nullable", MakeUsersOnboardedNotNullable.class)
+    ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullable.java
new file mode 100644 (file)
index 0000000..26f4a37
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v65;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
+
+public class MakeUsersOnboardedNotNullable extends DdlChange {
+
+  public MakeUsersOnboardedNotNullable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    BooleanColumnDef column = newBooleanColumnDefBuilder()
+      .setColumnName("onboarded")
+      .setIsNullable(false)
+      .build();
+    context.execute(new AlterColumnsBuilder(getDialect(), "users")
+      .updateColumn(column)
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboarded.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboarded.java
new file mode 100644 (file)
index 0000000..98d2c6c
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v65;
+
+import java.sql.SQLException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.Select;
+
+public class PopulateUsersOnboarded extends DataChange {
+
+  private final System2 system2;
+
+  public PopulateUsersOnboarded(Database db, System2 system2) {
+    super(db);
+    this.system2 = system2;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.prepareUpsert("update users set onboarded=?, updated_at=?")
+      .setBoolean(1, true)
+      .setLong(2, system2.now())
+      .execute()
+      .commit();
+    long users = context.prepareSelect("select count(u.id) from users u").get(Select.LONG_READER);
+    if (users == 1) {
+      context.prepareUpsert("update users set onboarded=?, updated_at=? where login=?")
+        .setBoolean(1, false)
+        .setLong(2, system2.now())
+        .setString(3, "admin")
+        .execute()
+        .commit();
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboardedTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboardedTest.java
new file mode 100644 (file)
index 0000000..8ce88ef
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v65;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+public class AddUsersOnboardedTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddUsersOnboardedTest.class, "users_without_onboarded_column.sql");
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private AddUsersOnboarded underTest = new AddUsersOnboarded(db.database());
+
+  @Test
+  public void execute_adds_nullable_boolean_column_private_to_table_PROJECTS() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("users", "onboarded", Types.BOOLEAN, null, true);
+  }
+}
index 618c8014db3dcdcfdcf977c725a0d371bd97d8fb..068b8a76a41855a177d80b2f499f670224e93404 100644 (file)
@@ -35,6 +35,6 @@ public class DbVersion65Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 30);
+    verifyMigrationCount(underTest, 33);
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullableTest.java
new file mode 100644 (file)
index 0000000..d948ac0
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v65;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class MakeUsersOnboardedNotNullableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MakeUsersOnboardedNotNullableTest.class, "users_with_nullable_onboarded_column.sql");
+
+  private MakeUsersOnboardedNotNullable underTest = new MakeUsersOnboardedNotNullable(db.database());
+
+  @Test
+  public void execute_makes_column_component_uuid_not_nullable_on_empty_table() throws SQLException {
+    underTest.execute();
+
+    verifyColumn();
+  }
+
+  @Test
+  public void execute_makes_column_component_uuid_not_nullable_on_populated_table() throws SQLException {
+    insertUser();
+    insertUser();
+    insertUser();
+
+    underTest.execute();
+
+    verifyColumn();
+  }
+
+  private void verifyColumn() {
+    db.assertColumnDefinition("users", "onboarded", Types.BOOLEAN, null, false);
+  }
+
+  private void insertUser() {
+    db.executeInsert(
+      "users",
+      "ONBOARDED", true,
+      "IS_ROOT", true);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboardedTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboardedTest.java
new file mode 100644 (file)
index 0000000..05fa5b6
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v65;
+
+import java.sql.SQLException;
+import java.util.stream.Collectors;
+import org.assertj.core.groups.Tuple;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.api.utils.internal.TestSystem2;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.groups.Tuple.tuple;
+
+public class PopulateUsersOnboardedTest {
+
+  private final static long PAST = 100_000_000_000l;
+  private final static long NOW = 500_000_000_000l;
+
+  private System2 system2 = new TestSystem2().setNow(NOW);
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(PopulateUsersOnboardedTest.class, "users_with_onboarded_column.sql");
+
+  public PopulateUsersOnboarded underTest = new PopulateUsersOnboarded(db.database(), system2);
+
+  @Test
+  public void set_onboarded_to_true() throws SQLException {
+    insertUser("admin");
+    insertUser("user");
+    assertUsers(tuple("admin", false, PAST), tuple("user", false, PAST));
+
+    underTest.execute();
+
+    assertUsers(tuple("admin", true, NOW), tuple("user", true, NOW));
+  }
+
+  @Test
+  public void set_onboarded_to_false_when_single_admin_user() throws SQLException {
+    insertUser("admin");
+
+    underTest.execute();
+
+    assertUsers(tuple("admin", false, NOW));
+  }
+
+  @Test
+  public void set_onboarded_to_true_when_single_user_but_not_admin() throws SQLException {
+    insertUser("user");
+
+    underTest.execute();
+
+    assertUsers(tuple("user", true, NOW));
+  }
+
+  private void insertUser(String login) {
+    db.executeInsert("USERS", "LOGIN", login, "ONBOARDED", false, "IS_ROOT", true, "CREATED_AT", PAST, "UPDATED_AT", PAST);
+  }
+
+  private void assertUsers(Tuple... expectedTuples) {
+    assertThat(db.select("SELECT LOGIN, ONBOARDED, UPDATED_AT FROM USERS")
+      .stream()
+      .map(map -> new Tuple(map.get("LOGIN"), map.get("ONBOARDED"), map.get("UPDATED_AT")))
+      .collect(Collectors.toList()))
+        .containsExactlyInAnyOrder(expectedTuples);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboardedTest/users_without_onboarded_column.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboardedTest/users_without_onboarded_column.sql
new file mode 100644 (file)
index 0000000..d631fea
--- /dev/null
@@ -0,0 +1,18 @@
+CREATE TABLE "USERS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "LOGIN" VARCHAR(255),
+  "NAME" VARCHAR(200),
+  "EMAIL" VARCHAR(100),
+  "CRYPTED_PASSWORD" VARCHAR(40),
+  "SALT" VARCHAR(40),
+  "ACTIVE" BOOLEAN DEFAULT TRUE,
+  "SCM_ACCOUNTS" VARCHAR(4000),
+  "EXTERNAL_IDENTITY" VARCHAR(255),
+  "EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100),
+  "IS_ROOT" BOOLEAN NOT NULL,
+  "USER_LOCAL" BOOLEAN,
+  "CREATED_AT" BIGINT,
+  "UPDATED_AT" BIGINT
+);
+CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS" ("LOGIN");
+CREATE INDEX "USERS_UPDATED_AT" ON "USERS" ("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullableTest/users_with_nullable_onboarded_column.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullableTest/users_with_nullable_onboarded_column.sql
new file mode 100644 (file)
index 0000000..44a02df
--- /dev/null
@@ -0,0 +1,19 @@
+CREATE TABLE "USERS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "LOGIN" VARCHAR(255),
+  "NAME" VARCHAR(200),
+  "EMAIL" VARCHAR(100),
+  "CRYPTED_PASSWORD" VARCHAR(40),
+  "SALT" VARCHAR(40),
+  "ACTIVE" BOOLEAN DEFAULT TRUE,
+  "SCM_ACCOUNTS" VARCHAR(4000),
+  "EXTERNAL_IDENTITY" VARCHAR(255),
+  "EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100),
+  "IS_ROOT" BOOLEAN NOT NULL,
+  "USER_LOCAL" BOOLEAN,
+  "ONBOARDED" BOOLEAN,
+  "CREATED_AT" BIGINT,
+  "UPDATED_AT" BIGINT
+);
+CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS" ("LOGIN");
+CREATE INDEX "USERS_UPDATED_AT" ON "USERS" ("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboardedTest/users_with_onboarded_column.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboardedTest/users_with_onboarded_column.sql
new file mode 100644 (file)
index 0000000..44a02df
--- /dev/null
@@ -0,0 +1,19 @@
+CREATE TABLE "USERS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "LOGIN" VARCHAR(255),
+  "NAME" VARCHAR(200),
+  "EMAIL" VARCHAR(100),
+  "CRYPTED_PASSWORD" VARCHAR(40),
+  "SALT" VARCHAR(40),
+  "ACTIVE" BOOLEAN DEFAULT TRUE,
+  "SCM_ACCOUNTS" VARCHAR(4000),
+  "EXTERNAL_IDENTITY" VARCHAR(255),
+  "EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100),
+  "IS_ROOT" BOOLEAN NOT NULL,
+  "USER_LOCAL" BOOLEAN,
+  "ONBOARDED" BOOLEAN,
+  "CREATED_AT" BIGINT,
+  "UPDATED_AT" BIGINT
+);
+CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS" ("LOGIN");
+CREATE INDEX "USERS_UPDATED_AT" ON "USERS" ("UPDATED_AT");
index 197ff9c0d5dee307ac7658770e992d6cdd074ee9..fdaf85ccec236c75e69186a4384986f6ed610c19 100644 (file)
@@ -320,6 +320,7 @@ public class DeactivateActionTest {
       .setLogin("ada.lovelace")
       .setEmail("ada.lovelace@noteg.com")
       .setName("Ada Lovelace")
+      .setLocal(true)
       .setScmAccounts(singletonList("al")));
     logInAsSystemAdministrator();
 
index f03a1f887c851db27bf4da02173ba1edc014078b..fb56bfffbe6b8e68370b3cdde9508d9aa84d7596 100644 (file)
@@ -37,7 +37,6 @@ import org.sonar.db.user.UserTesting;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.issue.ws.AvatarResolverImpl;
 import org.sonar.server.tester.UserSessionRule;
-import org.sonar.server.user.index.UserDoc;
 import org.sonar.server.user.index.UserIndex;
 import org.sonar.server.user.index.UserIndexDefinition;
 import org.sonar.server.user.index.UserIndexer;
@@ -72,11 +71,13 @@ public class SearchActionTest {
   private WsTester ws = new WsTester(new UsersWs(new SearchAction(userSession, index, dbClient, new AvatarResolverImpl())));
 
   @Test
-  public void search_json_example() throws Exception {
+  public void test_json_example() throws Exception {
     UserDto fmallet = db.users().insertUser(newUserDto("fmallet", "Freddy Mallet", "f@m.com")
       .setActive(true)
       .setLocal(true)
-      .setScmAccounts(emptyList()));
+      .setScmAccounts(emptyList())
+      .setExternalIdentity("fmallet")
+      .setExternalIdentityProvider("sonarqube"));
     UserDto simon = db.users().insertUser(newUserDto("sbrandhof", "Simon", "s.brandhof@company.tld")
       .setActive(true)
       .setLocal(false)
@@ -127,16 +128,13 @@ public class SearchActionTest {
   public void search_with_query() throws Exception {
     loginAsSimpleUser();
     injectUsers(5);
-    UserDto user = db.users().insertUser(newUserDto("user-%_%-login", "user-name", "user@mail.com").setScmAccounts(singletonList("user1")));
-    esTester.putDocuments(UserIndexDefinition.INDEX_TYPE_USER.getIndex(), UserIndexDefinition.INDEX_TYPE_USER.getType(),
-      new UserDoc()
-        .setActive(true)
-        .setEmail(user.getEmail())
-        .setLogin(user.getLogin())
-        .setName(user.getName())
-        .setCreatedAt(user.getCreatedAt())
-        .setUpdatedAt(user.getUpdatedAt())
-        .setScmAccounts(user.getScmAccountsAsList()));
+    UserDto user = db.users().insertUser(u -> u
+      .setLogin("user-%_%-login")
+      .setName("user-name")
+      .setEmail("user@mail.com")
+      .setLocal(true)
+      .setScmAccounts(singletonList("user1")));
+    userIndexer.indexOnStartup(null);
 
     ws.newGetRequest("api/users", "search").setParam("q", "user-%_%-").execute().assertJson(getClass(), "user_one.json");
     ws.newGetRequest("api/users", "search").setParam("q", "user@MAIL.com").execute().assertJson(getClass(), "user_one.json");
index 2e18eac798249ddb8381da3542ba628029eec0fc..227b9478c1466e5cd1d81a401dc9dd4707449f21 100644 (file)
@@ -222,10 +222,11 @@ public class UpdateActionTest {
       .setLogin("john")
       .setName("John")
       .setScmAccounts(newArrayList("jn"))
-      .setActive(true);
-    dbClient.userDao().insert(session, userDto)
+      .setActive(true)
+      .setLocal(true)
       .setExternalIdentity("jo")
       .setExternalIdentityProvider("sonarqube");
+    dbClient.userDao().insert(session, userDto);
     session.commit();
     userIndexer.index(userDto.getLogin());
   }
index 9a2455b367150f2af61c4f73a25cac78aa23cffe..61028358669315bf8940771f9af9d4ec03d0b814 100644 (file)
@@ -4,11 +4,13 @@
          login="simon"
          name="Simon Brandhof"
          email="simon.brandhof@sonarsource.com"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
   <users id="2"
          login="godin"
          name="Evgeny Mandrikov"
          email="evgeny.mandrikov@sonarsource.com"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
 </dataset>
index 5ff55705813cb618b6340db401399654a55e2885..c375007dd76eb399443f8dbcb08b67f624b26cc6 100644 (file)
@@ -8,6 +8,7 @@
          scm_accounts="&#10;user_1&#10;u1&#10;"
          created_at="1500000000000"
          updated_at="1500000000000"
-         is_root="[false]"/>
+         is_root="[false]"
+         onboarded="[true]"/>
 
 </dataset>