--- /dev/null
+#
+# 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
}
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;
*
* 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;
}
private Date rememberTokenExpiresAt;
private Long createdAt;
private Long updatedAt;
+ private boolean local = true;
public Long getId() {
return id;
return this;
}
+ public boolean isLocal() {
+ return local;
+ }
+
+ public UserDto setLocal(boolean local) {
+ this.local = local;
+ return this;
+ }
+
public String getCryptedPassword() {
return cryptedPassword;
}
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
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}
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;
"SCM_ACCOUNTS" VARCHAR(4000),
"EXTERNAL_IDENTITY" VARCHAR(255),
"EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100),
+ "USER_LOCAL" BOOLEAN,
"CREATED_AT" BIGINT,
"UPDATED_AT" BIGINT
);
.setCryptedPassword("abcd")
.setExternalIdentity("johngithub")
.setExternalIdentityProvider("github")
+ .setLocal(true)
.setRememberToken("1234")
.setRememberTokenExpiresAt(new Date())
.setCreatedAt(date)
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);
@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)
.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");
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