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
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;
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");
--- /dev/null
+<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>
<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"/>
<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"/>