]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7254 Add USERS.LOCAL column
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 15 Mar 2016 12:55:10 +0000 (13:55 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 21 Mar 2016 14:03:28 +0000 (15:03 +0100)
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1119_add_users_local_column.rb [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/user/UserDao.java
sonar-db/src/main/java/org/sonar/db/user/UserDto.java
sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml
sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java

diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1119_add_users_local_column.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1119_add_users_local_column.rb
new file mode 100644 (file)
index 0000000..339033e
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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.
+#
+
+#
+# SonarQube 5.5
+# SONAR-7254
+#
+class AddUsersLocalColumn < ActiveRecord::Migration
+
+  def self.up
+    add_column 'users', 'user_local', :boolean
+  end
+
+end
index 7a9751dfc855e5a765edfd17c9f26862d6a1458c..d5119727b487e38707846afeee762aea2ca645ff 100644 (file)
@@ -108,15 +108,19 @@ public class UserDao implements Dao {
   }
 
   public List<UserDto> selectUsers(UserQuery query) {
-    SqlSession session = mybatis.openSession(false);
+    DbSession session = mybatis.openSession(false);
     try {
-      UserMapper mapper = session.getMapper(UserMapper.class);
-      return mapper.selectUsers(query);
+      return selectUsers(session, query);
     } finally {
       MyBatis.closeQuietly(session);
     }
   }
 
+  public List<UserDto> selectUsers(DbSession dbSession, UserQuery query) {
+    UserMapper mapper = dbSession.getMapper(UserMapper.class);
+    return mapper.selectUsers(query);
+  }
+
   public UserDto insert(SqlSession session, UserDto dto) {
     session.getMapper(UserMapper.class).insert(dto);
     return dto;
@@ -177,7 +181,7 @@ public class UserDao implements Dao {
    *
    * Please note that email is case insensitive, result for searching 'mail@email.com' or 'Mail@Email.com' will be the same
    */
-  public boolean doesEmailExist(DbSession dbSession, String email){
+  public boolean doesEmailExist(DbSession dbSession, String email) {
     return mapper(dbSession).countByEmail(email.toLowerCase()) > 0;
   }
 
index 5e24f8862554be1fbecc3c57e51253c34e3ecb9f..57db727c48c4f8c5e2eaaa1a7acae5c337bb7708 100644 (file)
@@ -49,6 +49,7 @@ public class UserDto {
   private Date rememberTokenExpiresAt;
   private Long createdAt;
   private Long updatedAt;
+  private boolean local = true;
 
   public Long getId() {
     return id;
@@ -156,6 +157,15 @@ public class UserDto {
     return this;
   }
 
+  public boolean isLocal() {
+    return local;
+  }
+
+  public UserDto setLocal(boolean local) {
+    this.local = local;
+    return this;
+  }
+
   public String getCryptedPassword() {
     return cryptedPassword;
   }
index 148c2af525560cc44fc83e03b1f1ffbcd6f3a0a3..bcfa9d1a242e66bca3661ae2f2c5bbae4aeec177 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.db.MyBatis;
 
 public class DatabaseVersion {
 
-  public static final int LAST_VERSION = 1118;
+  public static final int LAST_VERSION = 1119;
 
   /**
    * The minimum supported version which can be upgraded. Lower
index bd16343959a3205256c94db6f8779b6d3d6fc5e8..7d9e4d692307576af4048b2edb7bccc165b820a6 100644 (file)
@@ -14,6 +14,7 @@
     u.crypted_password as "cryptedPassword",
     u.external_identity as "externalIdentity",
     u.external_identity_provider as "externalIdentityProvider",
+    u.user_local as "local",
     u.remember_token as "rememberToken",
     u.remember_token_expires_at as "rememberTokenExpiresAt",
     u.created_at as "createdAt",
   </update>
 
   <insert id="insert" parameterType="User" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO users (login, name, email, active, scm_accounts, external_identity, external_identity_provider, salt, crypted_password,
+    INSERT INTO users (login, name, email, active, scm_accounts, external_identity, external_identity_provider, user_local, salt, crypted_password,
     remember_token, remember_token_expires_at, created_at, updated_at)
     VALUES (#{login,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{active,jdbcType=BOOLEAN},
     #{scmAccounts,jdbcType=VARCHAR}, #{externalIdentity,jdbcType=VARCHAR}, #{externalIdentityProvider,jdbcType=VARCHAR},
+    #{local,jdbcType=BOOLEAN},
     #{salt,jdbcType=VARCHAR}, #{cryptedPassword,jdbcType=VARCHAR},
     #{rememberToken,jdbcType=VARCHAR}, #{rememberTokenExpiresAt,jdbcType=TIMESTAMP},
     #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT})
   <insert id="update" parameterType="User" useGeneratedKeys="false">
     UPDATE users set name=#{name,jdbcType=VARCHAR}, email=#{email,jdbcType=VARCHAR}, active=#{active,jdbcType=BOOLEAN},
     scm_accounts=#{scmAccounts,jdbcType=VARCHAR}, external_identity=#{externalIdentity,jdbcType=VARCHAR}, external_identity_provider=#{externalIdentityProvider,jdbcType=VARCHAR},
+    user_local=#{local,jdbcType=BOOLEAN},
     salt=#{salt,jdbcType=VARCHAR}, crypted_password=#{cryptedPassword,jdbcType=BIGINT},
     remember_token=#{rememberToken,jdbcType=VARCHAR}, remember_token_expires_at=#{rememberTokenExpiresAt,jdbcType=TIMESTAMP},
     updated_at=#{updatedAt,jdbcType=BIGINT}
index 036642f43562d2ce16cc4ac32d34b9df05860bcd..67b26290e705e5851595d05e2c1205f02df73974 100644 (file)
@@ -396,6 +396,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1115');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1116');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1117');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1118');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1119');
 
-INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
+INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 36775ed6ed1d8ed2ec24be6277b7aa4671e9049d..eb657209f2ee163c059bf8abb6fd9b73f917b159 100644 (file)
@@ -303,6 +303,7 @@ CREATE TABLE "USERS" (
   "SCM_ACCOUNTS" VARCHAR(4000),
   "EXTERNAL_IDENTITY" VARCHAR(255),
   "EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100),
+  "USER_LOCAL" BOOLEAN,
   "CREATED_AT" BIGINT,
   "UPDATED_AT" BIGINT
 );
index 6724dbe11adb6b1cf063721c70a011223643e47c..09f42002021157ec898de6715fdf98009907e03f 100644 (file)
@@ -187,6 +187,7 @@ public class UserDaoTest {
       .setCryptedPassword("abcd")
       .setExternalIdentity("johngithub")
       .setExternalIdentityProvider("github")
+      .setLocal(true)
       .setRememberToken("1234")
       .setRememberTokenExpiresAt(new Date())
       .setCreatedAt(date)
@@ -206,6 +207,7 @@ public class UserDaoTest {
     assertThat(user.getCryptedPassword()).isEqualTo("abcd");
     assertThat(user.getExternalIdentity()).isEqualTo("johngithub");
     assertThat(user.getExternalIdentityProvider()).isEqualTo("github");
+    assertThat(user.isLocal()).isTrue();
     assertThat(user.getRememberToken()).isEqualTo("1234");
     assertThat(user.getRememberTokenExpiresAt()).isNotNull();
     assertThat(user.getCreatedAt()).isEqualTo(date);
@@ -214,9 +216,16 @@ public class UserDaoTest {
 
   @Test
   public void update_user() {
-    db.prepareDbUnit(getClass(), "update_user.xml");
-
-    Long date = DateUtils.parseDate("2014-06-21").getTime();
+    UserDto existingUser = new UserDto()
+      .setLogin("john")
+      .setName("John")
+      .setEmail("jo@hn.com")
+      .setCreatedAt(1418215735482L)
+      .setUpdatedAt(1418215735482L)
+      .setActive(true)
+      .setLocal(true);
+    db.getDbClient().userDao().insert(db.getSession(), existingUser);
+    db.getSession().commit();
 
     UserDto userDto = new UserDto()
       .setId(1L)
@@ -229,13 +238,14 @@ public class UserDaoTest {
       .setCryptedPassword("abcde")
       .setExternalIdentity("johngithub")
       .setExternalIdentityProvider("github")
-      .setUpdatedAt(date);
+      .setLocal(false)
+      .setUpdatedAt(1500000000000L);
     underTest.update(db.getSession(), userDto);
     db.getSession().commit();
 
-    UserDto user = underTest.selectUserById(1);
+    UserDto user = underTest.selectUserById(db.getSession(), existingUser.getId());
     assertThat(user).isNotNull();
-    assertThat(user.getId()).isEqualTo(1L);
+    assertThat(user.getId()).isEqualTo(existingUser.getId());
     assertThat(user.getLogin()).isEqualTo("john");
     assertThat(user.getName()).isEqualTo("John Doo");
     assertThat(user.getEmail()).isEqualTo("jodoo@hn.com");
@@ -245,8 +255,9 @@ public class UserDaoTest {
     assertThat(user.getCryptedPassword()).isEqualTo("abcde");
     assertThat(user.getExternalIdentity()).isEqualTo("johngithub");
     assertThat(user.getExternalIdentityProvider()).isEqualTo("github");
+    assertThat(user.isLocal()).isFalse();
     assertThat(user.getCreatedAt()).isEqualTo(1418215735482L);
-    assertThat(user.getUpdatedAt()).isEqualTo(date);
+    assertThat(user.getUpdatedAt()).isEqualTo(1500000000000L);
   }
 
   @Test