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
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;
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");
--- /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]"/>
+
+ <!-- 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>
<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"/>
<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"/>