aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql2
-rw-r--r--server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl1
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDto.java10
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java7
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTesting.java52
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml12
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions.xml9
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml9
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/exists_by_email.xml6
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/insert-result.xml3
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectActiveUserByLogin.xml9
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByIds.xml9
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByLogins.xml9
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByQuery.xml6
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByText.xml6
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_by_login.xml6
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_nullable_by_scm_account.xml6
-rw-r--r--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.xml6
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/update_user.xml3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboarded.java43
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java7
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullable.java46
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboarded.java54
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboardedTest.java43
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullableTest.java63
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboardedTest.java86
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboardedTest/users_without_onboarded_column.sql18
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullableTest/users_with_nullable_onboarded_column.sql19
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboardedTest/users_with_onboarded_column.sql19
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java24
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java5
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/user/DeprecatedUserFinderTest/fixture.xml6
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/user/index/UserIndexerTest/index.xml3
36 files changed, 528 insertions, 86 deletions
diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql b/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql
index 8d3b0c44ad4..cd82a9bb62d 100644
--- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql
+++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/rows-h2.sql
@@ -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');
diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
index b561d120bec..5901161d0d1 100644
--- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
+++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
@@ -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
);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDto.java
index 7f41ce65250..e85f6ed8785 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDto.java
@@ -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");
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml
index 63eafbcef3f..ef9d08398df 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml
@@ -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>
@@ -155,6 +156,7 @@
salt,
crypted_password,
is_root,
+ onboarded,
created_at,
updated_at
)
@@ -170,6 +172,7 @@
#{salt,jdbcType=VARCHAR},
#{cryptedPassword,jdbcType=VARCHAR},
#{root,jdbcType=BOOLEAN},
+ #{onboarded,jdbcType=BOOLEAN},
#{createdAt,jdbcType=BIGINT},
#{updatedAt,jdbcType=BIGINT}
)
@@ -184,6 +187,7 @@
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}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java
index 3acf9a2b530..c6f54ca0503 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java
@@ -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");
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTesting.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTesting.java
index 682699ad4d9..b9bba58527b 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTesting.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTesting.java
@@ -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);
}
}
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml
index 9ad332d06d7..c3a899ddf49 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml
@@ -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"
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions.xml
index 0339e3dbd55..8382a060d27 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions.xml
@@ -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"
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml
index 13a3f1f3e0a..56e76fad3f9 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/permission/template/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml
@@ -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"
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/exists_by_email.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/exists_by_email.xml
index 63dd4a57e8d..2226bb3ba34 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/exists_by_email.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/exists_by_email.xml
@@ -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>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/insert-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/insert-result.xml
index a15c10259bc..fe3a43320a9 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/insert-result.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/insert-result.xml
@@ -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-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectActiveUserByLogin.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectActiveUserByLogin.xml
index aa0b64fadf2..fba9650f48b 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectActiveUserByLogin.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectActiveUserByLogin.xml
@@ -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>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByIds.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByIds.xml
index 65e155941df..7340c944abb 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByIds.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByIds.xml
@@ -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>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByLogins.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByLogins.xml
index 65e155941df..7340c944abb 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByLogins.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByLogins.xml
@@ -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>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByQuery.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByQuery.xml
index 8f6bacd7c43..246d4caf77e 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByQuery.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByQuery.xml
@@ -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>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByText.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByText.xml
index 89b1302e298..c4308ee82af 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByText.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/selectUsersByText.xml
@@ -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>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_by_login.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_by_login.xml
index d07ecce8728..2ac78040cab 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_by_login.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_by_login.xml
@@ -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>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_nullable_by_scm_account.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_nullable_by_scm_account.xml
index 3ded656c9f4..54b486eb3e3 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_nullable_by_scm_account.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/select_nullable_by_scm_account.xml
@@ -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>
diff --git a/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 b/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
index 63dd4a57e8d..2226bb3ba34 100644
--- a/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
+++ b/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
@@ -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>
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/update_user.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/update_user.xml
index a15c10259bc..fe3a43320a9 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/update_user.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/user/UserDaoTest/update_user.xml
@@ -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
index 00000000000..7b6d202fcc1
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboarded.java
@@ -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());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
index 75ac30953ab..5dd66b02490 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
@@ -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
index 00000000000..26f4a372bb8
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullable.java
@@ -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
index 00000000000..98d2c6c816b
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboarded.java
@@ -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
index 00000000000..8ce88ef67c3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboardedTest.java
@@ -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);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
index 618c8014db3..068b8a76a41 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
@@ -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
index 00000000000..d948ac01576
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullableTest.java
@@ -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
index 00000000000..05fa5b6c574
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboardedTest.java
@@ -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
index 00000000000..d631feae68e
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboardedTest/users_without_onboarded_column.sql
@@ -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
index 00000000000..44a02df3f3d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullableTest/users_with_nullable_onboarded_column.sql
@@ -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
index 00000000000..44a02df3f3d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboardedTest/users_with_onboarded_column.sql
@@ -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-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
index 197ff9c0d5d..fdaf85ccec2 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
@@ -320,6 +320,7 @@ public class DeactivateActionTest {
.setLogin("ada.lovelace")
.setEmail("ada.lovelace@noteg.com")
.setName("Ada Lovelace")
+ .setLocal(true)
.setScmAccounts(singletonList("al")));
logInAsSystemAdministrator();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
index f03a1f887c8..fb56bfffbe6 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
@@ -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");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
index 2e18eac7982..227b9478c14 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
@@ -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());
}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/user/DeprecatedUserFinderTest/fixture.xml b/server/sonar-server/src/test/resources/org/sonar/server/user/DeprecatedUserFinderTest/fixture.xml
index 9a2455b3671..61028358669 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/user/DeprecatedUserFinderTest/fixture.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/user/DeprecatedUserFinderTest/fixture.xml
@@ -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>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/user/index/UserIndexerTest/index.xml b/server/sonar-server/src/test/resources/org/sonar/server/user/index/UserIndexerTest/index.xml
index 5ff55705813..c375007dd76 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/user/index/UserIndexerTest/index.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/user/index/UserIndexerTest/index.xml
@@ -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>