]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5612 Do not return disabled users on the permission template users list
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 9 Oct 2014 15:08:34 +0000 (17:08 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 10 Oct 2014 06:39:49 +0000 (08:39 +0200)
sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml
sonar-core/src/test/java/org/sonar/core/permission/UserWithPermissionTemplateDaoTest.java
sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/users_with_permissions.xml
sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml

index 64fb208e8e9668175188452a450d83a89b5bcc30..c153b3564fd384f80c216a071912e2ddd7091dee 100644 (file)
@@ -73,6 +73,7 @@
       AND ptu.permission_reference=#{query.permission}
       AND ptu.template_id=#{templateId}
     <where>
+      u.active = ${_true}
       <choose>
         <when test="query.membership() == 'IN'">
           AND ptu.permission_reference IS NOT NULL
index ed0dc5358fbf359ff8c690a95bb4e63c919d4c79..e0f0aea11671132dba2095c2d3d8d4298e6fa4c7 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.api.utils.System2;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 
+import javax.annotation.Nullable;
+
 import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -98,6 +102,23 @@ public class UserWithPermissionTemplateDaoTest extends AbstractDaoTestCase {
     assertThat(dao.selectUsers(PermissionQuery.builder().permission("user").membership(PermissionQuery.OUT).build(), TEMPLATE_ID)).hasSize(1);
   }
 
+  @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, 999L);
+    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 search_by_user_name() throws Exception {
     setupData("users_with_permissions");
diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml b/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml
new file mode 100644 (file)
index 0000000..1483391
--- /dev/null
@@ -0,0 +1,14 @@
+<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]"/>
+
+  <perm_templates_users id="1" user_id="200" permission_reference="user" template_id="50"/>
+  <perm_templates_users id="2" user_id="200" permission_reference="admin" template_id="50"/>
+  <perm_templates_users id="3" user_id="200" permission_reference="codeviewer" template_id="50"/>
+
+  <perm_templates_users id="4" user_id="201" permission_reference="user" template_id="50"/>
+
+</dataset>
index 9c9f018aa2b283978fe8ef741d5688106b065e1e..e886636bd9b3c46e8100044f1c5576701bb34173 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]"/>
 
   <perm_templates_users id="1" user_id="200" permission_reference="user" template_id="50"/>
   <perm_templates_users id="2" user_id="200" permission_reference="admin" template_id="50"/>
index 54acdf839b270357f3d28a2c2b16868b92e6d410..fd8b981c203cf34aa0696cc7d8ed9b8908c5d4ed 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]"/>
 
   <perm_templates_users id="1" user_id="200" permission_reference="user" template_id="50"/>
   <perm_templates_users id="2" user_id="200" permission_reference="admin" template_id="50"/>