]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17040 added search by login and email to permission template users search
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Fri, 14 Oct 2022 11:59:34 +0000 (13:59 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 14 Oct 2022 20:03:03 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/template/PermissionTemplateMapper.xml
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/TemplateUsersActionTest.java

index 4e8d0e12354cf9d468e4f1534df87ff22744b053..bbffb1287b3c50fbc6035073537c9abc20a8b76d 100644 (file)
@@ -66,8 +66,8 @@
     <if test="query.searchQueryToSql != null">
       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 '/')
+      or lower(u.email) like #{query.searchQueryToSql,jdbcType=VARCHAR} ESCAPE '/'
+      or lower(u.login) like #{query.searchQueryToSql,jdbcType=VARCHAR} ESCAPE '/')
     </if>
     <!-- filter rows with user permissions -->
     <if test="query.withAtLeastOnePermission()">
index c67173c0a291dd407c7d86fde068df00b559afa5..8c9a5c8d2e0271f7cdcd7dd28fbe4186a806a09f 100644 (file)
     <where>
       u.active = ${_true}
       <if test="query.getSearchQueryToSql() != null">
-        AND lower(u.name) like #{query.searchQueryToSqlLowercase} ESCAPE '/'
+        AND (lower(u.name) like #{query.searchQueryToSqlLowercase} ESCAPE '/'
+        OR lower(u.login) like #{query.searchQueryToSqlLowercase} ESCAPE '/'
+        OR lower(u.email) like #{query.searchQueryToSqlLowercase} ESCAPE '/')
       </if>
       <if test="query.withAtLeastOnePermission()">
         and ptu.permission_reference is not null
index 3eaa679246ad5fed6a1c31d3789cfbb9d44787e2..61ec6d30ab9a046d935e55ff0e037d6e8a479f14 100644 (file)
@@ -26,7 +26,6 @@ import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.web.UserRole;
-import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.permission.GlobalPermission;
 import org.sonar.db.permission.template.PermissionTemplateDto;
@@ -153,6 +152,52 @@ public class TemplateUsersActionTest extends BasePermissionWsTest<TemplateUsersA
     assertThat(response.getUsersList()).extracting("login").containsOnly("login-1");
   }
 
+  @Test
+  public void search_using_text_query_with_email() {
+    loginAsAdmin();
+
+    UserDto user1 = insertUser(newUserDto().setLogin("orange").setName("name-1").setEmail("email-1"));
+    UserDto user2 = insertUser(newUserDto().setLogin("crANBerry").setName("name-2").setEmail("email-2"));
+    UserDto user3 = insertUser(newUserDto().setLogin("apple").setName("name-3").setEmail("email-3"));
+
+    String templateName = addUsersToSomeTemplate(user1, user2, user3);
+
+    Permissions.UsersWsResponse response = newRequest(null, null)
+      .setParam(PARAM_TEMPLATE_NAME, templateName)
+      .setParam(WebService.Param.TEXT_QUERY, "ran")
+      .executeProtobuf(Permissions.UsersWsResponse.class);
+
+    assertThat(response.getUsersList()).hasSize(2);
+    assertThat(response.getUsersList()).extracting("login").containsExactlyInAnyOrder("orange", "crANBerry");
+  }
+
+  @Test
+  public void search_using_text_query_with_login() {
+    loginAsAdmin();
+
+    UserDto user1 = insertUser(newUserDto().setLogin("login-1").setName("name-1").setEmail("xYZ@1984.com"));
+    UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("xyz2@1984.com"));
+    UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("hello@1984.com"));
+
+    String templateName = addUsersToSomeTemplate(user1, user2, user3);
+
+    Permissions.UsersWsResponse response = newRequest(null, null)
+      .setParam(PARAM_TEMPLATE_NAME, templateName)
+      .setParam(WebService.Param.TEXT_QUERY, "xyz")
+      .executeProtobuf(Permissions.UsersWsResponse.class);
+
+    assertThat(response.getUsersList()).hasSize(2);
+    assertThat(response.getUsersList()).extracting("email").containsExactlyInAnyOrder("xYZ@1984.com", "xyz2@1984.com");
+  }
+
+  private String addUsersToSomeTemplate(UserDto user1, UserDto user2, UserDto user3) {
+    PermissionTemplateDto template = addTemplate();
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user1), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user2), template.getName());
+    addUserToTemplate(newPermissionTemplateUser(USER, template, user3), template.getName());
+    return template.getName();
+  }
+
   @Test
   public void search_using_permission() {
     UserDto user1 = insertUser(newUserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));