]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5612 Disabled users are displayed in global and project permissions page
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 6 Oct 2014 09:16:30 +0000 (11:16 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 6 Oct 2014 09:44:11 +0000 (11:44 +0200)
sonar-core/src/main/resources/org/sonar/core/permission/PermissionMapper.xml
sonar-core/src/test/java/org/sonar/core/permission/UserWithPermissionDaoTest.java
sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionDaoTest/select_only_enable_users.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionDaoTest/users_with_permissions.xml
sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml

index b3957662fa9d9a0438544fcd8d35df10ca8bc649..efb946a92c3a5716fb36768418ed5503db631af1 100644 (file)
@@ -15,6 +15,7 @@
       AND user_role.resource_id IS NULL
     </if>
     <where>
+      u.active = ${_true}
       <choose>
         <when test="query.membership() == 'IN'">
           AND user_role.role IS NOT NULL
index 896d6f87de0983def2b82edd9bb16f8d8c312732..0265d269137467aba6f61a705023f18b1827eb84 100644 (file)
 
 package org.sonar.core.permission;
 
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 
+import javax.annotation.Nullable;
+
 import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -112,6 +116,23 @@ public class UserWithPermissionDaoTest extends AbstractDaoTestCase {
     assertThat(result).hasSize(3);
   }
 
+  @Test
+  public void select_only_enable_users() throws Exception {
+    setupData("select_only_enable_users");
+
+    PermissionQuery query = PermissionQuery.builder().permission("user").build();
+    List<UserWithPermissionDto> result = dao.selectUsers(query, COMPONENT_ID);
+    assertThat(result).hasSize(3);
+
+    // Disabled user should not be returned
+    assertThat(Iterables.find(result, new Predicate<UserWithPermissionDto>() {
+      @Override
+      public boolean apply(@Nullable UserWithPermissionDto input) {
+        return input.getLogin().equals("disabledUser");
+      }
+    }, null)).isNull();
+  }
+
   @Test
   public void should_be_sorted_by_user_name() throws Exception {
     setupData("users_with_permissions_should_be_sorted_by_user_name");
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionDaoTest/select_only_enable_users.xml b/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionDaoTest/select_only_enable_users.xml
new file mode 100644 (file)
index 0000000..662af1a
--- /dev/null
@@ -0,0 +1,18 @@
+<dataset>
+
+  <users id="200" login="user1" name="User1" active="[true]"/>
+  <users id="201" login="user2" name="User2" active="[true]"/>
+  <users id="202" login="user3" name="User3" active="[true]"/>
+  <users id="999" login="disabledUser" name="disabledUser" active="[false]"/>
+
+  <!-- Project permissions -->
+  <user_roles id="1" user_id="200" resource_id="100" role="user"/>
+  <user_roles id="2" user_id="200" resource_id="100" role="admin"/>
+  <user_roles id="3" user_id="200" resource_id="100" role="codeviewer"/>
+
+  <user_roles id="4" user_id="201" resource_id="100" role="user"/>
+
+  <!-- Global permission -->
+  <user_roles id="10" user_id="200" resource_id="[null]" role="admin"/>
+
+</dataset>
index c67ff39f25b22b71f70d5cd9031812560bc6eb5e..6f40d31f21d35f704cc7e1d9997bf54325b1a056 100644 (file)
@@ -1,8 +1,8 @@
 <dataset>
 
-  <users id="200" login="user1" name="User1"/>
-  <users id="201" login="user2" name="User2"/>
-  <users id="202" login="user3" name="User3"/>
+  <users id="200" login="user1" name="User1" active="[true]"/>
+  <users id="201" login="user2" name="User2" active="[true]"/>
+  <users id="202" login="user3" name="User3" active="[true]"/>
 
   <!-- Project permissions -->
   <user_roles id="1" user_id="200" resource_id="100" role="user"/>
index 3bb7487923cf7972e5bcc17fc5d6ebbfedf090a4..6b39124ce6ceb7694c5289ab6174a589c71eeeee 100644 (file)
@@ -1,8 +1,8 @@
 <dataset>
 
-  <users id="200" login="user3" name="User3"/>
-  <users id="201" login="user1" name="User1"/>
-  <users id="202" login="user2" name="User2"/>
+  <users id="200" login="user3" name="User3" active="[true]"/>
+  <users id="201" login="user1" name="User1" active="[true]"/>
+  <users id="202" login="user2" name="User2" active="[true]"/>
 
   <user_roles id="1" user_id="200" resource_id="100" role="user"/>
   <user_roles id="2" user_id="200" resource_id="100" role="admin"/>