.setPageIndex(request.mandatoryParamAsInt(Param.PAGE))
.setPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE))
.setSearchQuery(textQuery);
- if (project.isPresent()) {
- permissionQuery.setComponentUuid(project.get().getUuid());
- }
+ project.ifPresent(projectId -> permissionQuery.setComponentUuid(projectId.getUuid()));
if (permission != null) {
if (project.isPresent()) {
validateProjectPermission(permission);
public void search_also_for_users_without_permission_when_filtering_name() throws Exception {
// User with permission on project
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()));
- UserDto user = db.users().insertUser(newUserDto("with-permission", "with-permission", null));
+ UserDto user = db.users().insertUser(newUserDto("with-permission-login", "with-permission-name", "with-permission-email"));
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
// User without permission
- UserDto withoutPermission = db.users().insertUser(newUserDto("without-permission", "without-permission", null));
- UserDto anotherUser = db.users().insertUser(newUserDto("another-user", "another-user", null));
+ UserDto withoutPermission = db.users().insertUser(newUserDto("without-permission-login", "without-permission-name", "without-permission-email"));
+ UserDto anotherUser = db.users().insertUser(newUserDto("another-user", "another-user", "another-user"));
loginAsAdminOnDefaultOrganization();
- String result = newRequest()
- .setParam(PARAM_PROJECT_ID, project.uuid())
- .setParam(TEXT_QUERY, "with")
- .execute()
- .getInput();
+ String result = newRequest().setParam(PARAM_PROJECT_ID, project.uuid()).setParam(TEXT_QUERY, "name").execute().getInput();
- assertThat(result)
- .contains(user.getLogin())
- .contains(withoutPermission.getLogin())
- .doesNotContain(anotherUser.getLogin());
+ assertThat(result).contains(user.getLogin(), withoutPermission.getLogin()).doesNotContain(anotherUser.getLogin());
+ }
+
+ @Test
+ public void search_also_for_users_without_permission_when_filtering_email() throws Exception {
+ // User with permission on project
+ ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()));
+ UserDto user = db.users().insertUser(newUserDto("with-permission-login", "with-permission-name", "with-permission-email"));
+ db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
+
+ // User without permission
+ UserDto withoutPermission = db.users().insertUser(newUserDto("without-permission-login", "without-permission-name", "without-permission-email"));
+ UserDto anotherUser = db.users().insertUser(newUserDto("another-user", "another-user", "another-user"));
+
+ loginAsAdminOnDefaultOrganization();
+ String result = newRequest().setParam(PARAM_PROJECT_ID, project.uuid()).setParam(TEXT_QUERY, "email").execute().getInput();
+
+ assertThat(result).contains(user.getLogin(), withoutPermission.getLogin()).doesNotContain(anotherUser.getLogin());
+ }
+
+ @Test
+ public void search_also_for_users_without_permission_when_filtering_login() throws Exception {
+ // User with permission on project
+ ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()));
+ UserDto user = db.users().insertUser(newUserDto("with-permission-login", "with-permission-name", "with-permission-email"));
+ db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
+
+ // User without permission
+ UserDto withoutPermission = db.users().insertUser(newUserDto("without-permission-login", "without-permission-name", "without-permission-email"));
+ UserDto anotherUser = db.users().insertUser(newUserDto("another-user", "another-user", "another-user"));
+
+ loginAsAdminOnDefaultOrganization();
+ String result = newRequest().setParam(PARAM_PROJECT_ID, project.uuid()).setParam(TEXT_QUERY, "login").execute().getInput();
+
+ assertThat(result).contains(user.getLogin(), withoutPermission.getLogin()).doesNotContain(anotherUser.getLogin());
}
@Test
private final String componentUuid;
private final String template;
- // filter on name of users or groups
+ // filter on login, email or name of users or groups
private final String searchQuery;
private final String searchQueryToSql;
+ private final String searchQueryToSqlLowercase;
// filter users or groups who have at least one permission. It does make
// sense when the filter "permission" is set.
this.componentUuid = builder.componentUuid;
this.template = builder.template;
this.searchQuery = builder.searchQuery;
- this.searchQueryToSql = builder.searchQuery == null ? null : buildLikeValue(builder.searchQuery, WildcardPosition.BEFORE_AND_AFTER).toLowerCase(Locale.ENGLISH);
+ this.searchQueryToSql = builder.searchQuery == null ? null : buildLikeValue(builder.searchQuery, WildcardPosition.BEFORE_AND_AFTER);
+ this.searchQueryToSqlLowercase = builder.searchQuery == null ? null : searchQueryToSql.toLowerCase(Locale.ENGLISH);
this.pageSize = builder.pageSize;
this.pageOffset = offset(builder.pageIndex, builder.pageSize);
}
return searchQueryToSql;
}
+ @CheckForNull
+ public String getSearchQueryToSqlLowercase() {
+ return searchQueryToSqlLowercase;
+ }
+
public int getPageSize() {
return pageSize;
}
left join projects p on sub.componentId = p.id
<where>
<if test="query.searchQueryToSql != null">
- and lower(sub.name) like #{query.searchQueryToSql,jdbcType=VARCHAR} ESCAPE '/'
+ and lower(sub.name) like #{query.searchQueryToSqlLowercase,jdbcType=VARCHAR} ESCAPE '/'
</if>
<!-- filter rows with group permissions -->
<if test="query.withAtLeastOnePermission()">
and u.login in <foreach collection="userLogins" open="(" close=")" item="userLogin" separator=",">#{userLogin,jdbcType=VARCHAR}</foreach>
</if>
<if test="query.searchQueryToSql != null">
- and lower(u.name) like #{query.searchQueryToSql,jdbcType=VARCHAR} ESCAPE '/'
+ and (
+ lower(u.name) like #{query.searchQueryToSqlLowercase,jdbcType=VARCHAR} ESCAPE '/'
+ or u.email like #{query.searchQueryToSql,jdbcType=VARCHAR} ESCAPE '/'
+ or u.login like #{query.searchQueryToSql,jdbcType=VARCHAR} ESCAPE '/')
+
</if>
<!-- filter rows with user permissions -->
<if test="query.withAtLeastOnePermission()">
<where>
u.active = ${_true}
<if test="query.getSearchQueryToSql() != null">
- AND lower(u.name) like #{query.searchQueryToSql} ESCAPE '/'
+ AND lower(u.name) like #{query.searchQueryToSqlLowercase} ESCAPE '/'
</if>
<if test="query.withAtLeastOnePermission()">
and ptu.permission_reference is not null
) groups
<where>
<if test="query.searchQueryToSql != null">
- AND LOWER(groups.name) LIKE #{query.searchQueryToSql} ESCAPE '/'
+ AND LOWER(groups.name) LIKE #{query.searchQueryToSqlLowercase} ESCAPE '/'
</if>
<if test="query.withAtLeastOnePermission()">
AND groups.permission IS NOT NULL
public DbTester dbTester = DbTester.create(System2.INSTANCE);
private UserPermissionDao underTest = new UserPermissionDao();
- private UserDto user1 = newUserDto().setLogin("login1").setName("Marius").setActive(true);
- private UserDto user2 = newUserDto().setLogin("login2").setName("Marie").setActive(true);
- private UserDto user3 = newUserDto().setLogin("login3").setName("Bernard").setActive(true);
+ private UserDto user1 = newUserDto().setLogin("login1").setName("Marius").setEmail("email1@email.com").setActive(true);
+ private UserDto user2 = newUserDto().setLogin("login2").setName("Marie").setEmail("email2@email.com").setActive(true);
+ private UserDto user3 = newUserDto().setLogin("zanother").setName("Zoe").setEmail("zanother3@another.com").setActive(true);
private OrganizationDto organizationDto;
private ComponentDto project1;
private ComponentDto project2;
// (that's a non-sense, but still this is required for api/permissions/groups
// when filtering users by name)
query = PermissionQuery.builder().build();
- expectPermissions(organizationDto, query, null, project1Perm, global2, global3, org2Global2, global1, org2Global1);
+ expectPermissions(organizationDto, query, null, global2, global3, org2Global2, global1, org2Global1, project1Perm);
// return empty list if non-null but empty logins
expectPermissions(organizationDto, query, Collections.emptyList());
expectPermissions(organizationDto, query, null);
// search by user name (matches 2 users)
- query = PermissionQuery.builder().withAtLeastOnePermission().setSearchQuery("Mari").build();
+ query = PermissionQuery.builder().withAtLeastOnePermission().setSearchQuery("mari").build();
expectPermissions(organizationDto, query, null, global2, global3, global1);
+ // search by user login
+ query = PermissionQuery.builder().withAtLeastOnePermission().setSearchQuery("ogin2").build();
+ expectPermissions(organizationDto, query, null, global2, global3);
+
+ // search by user email
+ query = PermissionQuery.builder().withAtLeastOnePermission().setSearchQuery("mail2").build();
+ expectPermissions(organizationDto, query, null, global2, global3);
+
// search by user name (matches 2 users) and global permission
query = PermissionQuery.builder().setSearchQuery("Mari").setPermission(PROVISIONING).build();
expectPermissions(organizationDto, query, null, global3);