From: Julien Lancelot Date: Thu, 9 Oct 2014 15:08:34 +0000 (+0200) Subject: SONAR-5612 Do not return disabled users on the permission template users list X-Git-Tag: 4.5.1-RC1~47 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a2e88db394ecb5ceba9c01e87612de7e2c5e5cf1;p=sonarqube.git SONAR-5612 Do not return disabled users on the permission template users list --- diff --git a/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml b/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml index 64fb208e8e9..c153b3564fd 100644 --- a/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml @@ -73,6 +73,7 @@ AND ptu.permission_reference=#{query.permission} AND ptu.template_id=#{templateId} + u.active = ${_true} AND ptu.permission_reference IS NOT NULL diff --git a/sonar-core/src/test/java/org/sonar/core/permission/UserWithPermissionTemplateDaoTest.java b/sonar-core/src/test/java/org/sonar/core/permission/UserWithPermissionTemplateDaoTest.java index ed0dc5358fb..e0f0aea1167 100644 --- a/sonar-core/src/test/java/org/sonar/core/permission/UserWithPermissionTemplateDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/permission/UserWithPermissionTemplateDaoTest.java @@ -20,11 +20,15 @@ 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 result = dao.selectUsers(query, 999L); + assertThat(result).hasSize(3); + + // Disabled user should not be returned + assertThat(Iterables.find(result, new Predicate() { + @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 index 00000000000..14833919475 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/select_only_enable_users.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/users_with_permissions.xml b/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/users_with_permissions.xml index 9c9f018aa2b..e886636bd9b 100644 --- a/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/users_with_permissions.xml +++ b/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/users_with_permissions.xml @@ -1,8 +1,8 @@ - - - + + + diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml b/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml index 54acdf839b2..fd8b981c203 100644 --- a/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml +++ b/sonar-core/src/test/resources/org/sonar/core/permission/UserWithPermissionTemplateDaoTest/users_with_permissions_should_be_sorted_by_user_name.xml @@ -1,8 +1,8 @@ - - - + + +