aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-01-06 12:38:41 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-01-06 13:09:12 +0100
commit2d7c48d39d0e3465692d776f4fe9bca7b69ad0cf (patch)
treee653a80ba409a55e3c87011751a7a1a5c79ab000 /sonar-core
parent56b361c1785c7e13386e9469ff558c861471d3ba (diff)
downloadsonarqube-2d7c48d39d0e3465692d776f4fe9bca7b69ad0cf.tar.gz
sonarqube-2d7c48d39d0e3465692d776f4fe9bca7b69ad0cf.zip
SONAR-5830 Check scm account is not already used
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/user/UserMapper.java3
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml30
-rw-r--r--sonar-core/src/main/resources/org/sonar/l10n/core.properties2
3 files changed, 32 insertions, 3 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java b/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java
index 329fd09beeb..48fda4f8dc8 100644
--- a/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java
@@ -32,6 +32,9 @@ public interface UserMapper {
UserDto selectByLogin(String login);
@CheckForNull
+ UserDto selectNullableByScmAccountOrLoginOrName(String scmAccount);
+
+ @CheckForNull
UserDto selectUser(long userId);
/**
diff --git a/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml b/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml
index d505e1c742e..a50be05abc9 100644
--- a/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml
@@ -19,19 +19,43 @@
<select id="selectByLogin" parameterType="String" resultType="User">
SELECT
<include refid="userColumns"/>
- FROM users u WHERE u.login=#{login}
+ FROM users u
+ WHERE u.login=#{login}
+ </select>
+
+ <select id="selectNullableByScmAccountOrLoginOrName" parameterType="String" resultType="User">
+ SELECT
+ <include refid="userColumns"/>
+ FROM users u
+ WHERE
+ u.login=#{scmAccount}
+ OR u.email=#{scmAccount}
+ OR
+ <choose>
+ <when test="_databaseId == 'mssql'">
+ u.scm_accounts LIKE '%,' + #{scmAccount} + ',%'
+ </when>
+ <when test="_databaseId == 'mysql'">
+ u.scm_accounts LIKE concat('%,', #{scmAccount}, ',%')
+ </when>
+ <otherwise>
+ u.scm_accounts LIKE '%,' || #{scmAccount} || ',%'
+ </otherwise>
+ </choose>
</select>
<select id="selectUser" parameterType="long" resultType="User">
SELECT
<include refid="userColumns"/>
- FROM users u WHERE u.id=#{id}
+ FROM users u
+ WHERE u.id=#{id}
</select>
<select id="selectUserByLogin" parameterType="string" resultType="User">
SELECT
<include refid="userColumns"/>
- FROM users u WHERE u.login=#{id} AND u.active=${_true}
+ FROM users u
+ WHERE u.login=#{id} AND u.active=${_true}
</select>
<select id="selectUsersByLogins" parameterType="map" resultType="User">
diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties
index d701500fbd3..13eaa3d208f 100644
--- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties
+++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties
@@ -1984,6 +1984,8 @@ user.bad_login=Use only letters, numbers, and .-_@ please.
user.password_doesnt_match_confirmation=Password doesn't match confirmation.
user.reactivated=The user '{0}' has been reactivated.
user.add_scm_account=Add SCM account
+user.scm_account_already_used=The scm account '{0}' is already used by user '{1} ({2})'
+user.login_or_email_used_as_scm_account=Login and email are automatically considered as SCM accounts
#------------------------------------------------------------------------------