]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7249 Search email only on active users 740/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 1 Feb 2016 11:20:41 +0000 (12:20 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 1 Feb 2016 12:46:18 +0000 (13:46 +0100)
sonar-db/src/main/java/org/sonar/db/user/UserDao.java
sonar-db/src/main/resources/org/sonar/db/user/UserMapper.xml
sonar-db/src/test/java/org/sonar/db/user/UserDaoTest.java

index f65e2b941a195d531bfcb8d18813529ebcf6df79..7a9751dfc855e5a765edfd17c9f26862d6a1458c 100644 (file)
@@ -173,6 +173,8 @@ public class UserDao implements Dao {
   }
 
   /**
+   * Check if an active user with the given email exits in database
+   *
    * 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){
index 1e3eb253d427819aac6dcc62b195dcdcad98bb9e..7b7deb1f711d3bc234784175aa45612a9bf21e92 100644 (file)
@@ -94,7 +94,7 @@
   <select id="countByEmail" parameterType="String" resultType="long">
     SELECT count(u.id)
     FROM users u
-    where lower(u.email)=#{email}
+    where lower(u.email)=#{email} AND u.active=${_true}
   </select>
 
   <select id="selectGroupByName" parameterType="string" resultType="Group">
index 68181403823c082c9744fb280535df2797d331a8..a090b59b03bef7105098b6627a29f3631c986b57 100644 (file)
@@ -425,15 +425,20 @@ public class UserDaoTest {
 
   @Test
   public void exists_by_email() throws Exception {
-    db.prepareDbUnit(getClass(), "exists_by_email.xml");
+    UserDto activeUser = newActiveUser();
+    UserDto disableUser = newUser(false);
 
-    assertThat(underTest.doesEmailExist(session, "marius@lesbronzes.fr")).isTrue();
-    assertThat(underTest.doesEmailExist(session, "Marius@LesBronzes.fr")).isTrue();
+    assertThat(underTest.doesEmailExist(session, activeUser.getEmail())).isTrue();
+    assertThat(underTest.doesEmailExist(session, disableUser.getEmail())).isFalse();
     assertThat(underTest.doesEmailExist(session, "unknown")).isFalse();
   }
 
   private UserDto newActiveUser(){
-    UserDto dto = UserTesting.newUserDto().setActive(true);
+    return newUser(true);
+  }
+
+  private UserDto newUser(boolean active){
+    UserDto dto = UserTesting.newUserDto().setActive(active);
     underTest.insert(session, dto);
     return dto;
   }