diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-09-22 17:34:34 +0200 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-10-02 17:18:15 +0200 |
commit | f96f99021d99319b935e8c620396743f7ce197a7 (patch) | |
tree | 40a11b82048ca4e4b363c9272b4ed37ba90a870c /sonar-ws | |
parent | 4c0d81eb984640587557787892ee3f1cbdcc193b (diff) | |
download | sonarqube-f96f99021d99319b935e8c620396743f7ce197a7.tar.gz sonarqube-f96f99021d99319b935e8c620396743f7ce197a7.zip |
SONAR-1330 Search for user allowed to edit single quality profile
Diffstat (limited to 'sonar-ws')
4 files changed, 192 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java index 340fd30d4a5..bc95c27b7b6 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesService.java @@ -23,6 +23,7 @@ import org.sonarqube.ws.MediaTypes; import org.sonarqube.ws.QualityProfiles; import org.sonarqube.ws.QualityProfiles.CopyWsResponse; import org.sonarqube.ws.QualityProfiles.CreateWsResponse; +import org.sonarqube.ws.QualityProfiles.SearchUsersResponse; import org.sonarqube.ws.QualityProfiles.SearchWsResponse; import org.sonarqube.ws.QualityProfiles.ShowResponse; import org.sonarqube.ws.client.BaseService; @@ -30,6 +31,10 @@ import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsConnector; +import static org.sonar.api.server.ws.WebService.Param.PAGE; +import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; +import static org.sonar.api.server.ws.WebService.Param.SELECTED; +import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ACTIVATE_RULE; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ADD_PROJECT; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ADD_USER; @@ -42,6 +47,7 @@ import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters. import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_REMOVE_USER; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_RESTORE; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SEARCH; +import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SEARCH_USERS; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SET_DEFAULT; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SHOW; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.CONTROLLER_QUALITY_PROFILES; @@ -190,4 +196,17 @@ public class QualityProfilesService extends BaseService { .setParam(PARAM_LANGUAGE, request.getLanguage()) .setParam(PARAM_LOGIN, request.getUserLogin())); } + + public SearchUsersResponse searchUsers(SearchUsersRequest request) { + return call( + new GetRequest(path(ACTION_SEARCH_USERS)) + .setParam(PARAM_ORGANIZATION, request.getOrganization()) + .setParam(PARAM_QUALITY_PROFILE, request.getQualityProfile()) + .setParam(PARAM_LANGUAGE, request.getLanguage()) + .setParam(TEXT_QUERY, request.getQuery()) + .setParam(SELECTED, request.getSelected()) + .setParam(PAGE, request.getPage()) + .setParam(PAGE_SIZE, request.getPageSize()), + SearchUsersResponse.parser()); + } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/SearchUsersRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/SearchUsersRequest.java new file mode 100644 index 00000000000..247efbdb20c --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/SearchUsersRequest.java @@ -0,0 +1,127 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonarqube.ws.client.qualityprofile; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +public class SearchUsersRequest { + + private String organization; + private String qualityProfile; + private String language; + private String selected; + private String query; + private Integer page; + private Integer pageSize; + + private SearchUsersRequest(Builder builder) { + this.organization = builder.organization; + this.qualityProfile = builder.qualityProfile; + this.language = builder.language; + this.selected = builder.selected; + this.query = builder.query; + this.page = builder.page; + this.pageSize = builder.pageSize; + } + + @CheckForNull + public String getOrganization() { + return organization; + } + + public String getQualityProfile() { + return qualityProfile; + } + + public String getLanguage() { + return language; + } + + @CheckForNull + public String getQuery() { + return query; + } + + public String getSelected() { + return selected; + } + + public Integer getPage() { + return page; + } + + public Integer getPageSize() { + return pageSize; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String organization; + private String qualityProfile; + private String language; + private String selected; + private String query; + private Integer page; + private Integer pageSize; + + public Builder setOrganization(@Nullable String organization) { + this.organization = organization; + return this; + } + + public Builder setQualityProfile(String qualityProfile) { + this.qualityProfile = qualityProfile; + return this; + } + + public Builder setLanguage(String language) { + this.language = language; + return this; + } + + public Builder setSelected(String selected) { + this.selected = selected; + return this; + } + + public Builder setQuery(@Nullable String query) { + this.query = query; + return this; + } + + public Builder setPage(Integer page) { + this.page = page; + return this; + } + + public Builder setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public SearchUsersRequest build() { + return new SearchUsersRequest(this); + } + } +} diff --git a/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto b/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto index a02f33fe395..2300e8baa77 100644 --- a/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto +++ b/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto @@ -20,6 +20,8 @@ syntax = "proto2"; package sonarqube.ws.qualityprofiles; +import "ws-commons.proto"; + option java_package = "org.sonarqube.ws"; option java_outer_classname = "QualityProfiles"; option optimize_for = SPEED; @@ -138,3 +140,15 @@ message ShowResponse { } } +// WS api/qualityprofiles/search_users +message SearchUsersResponse { + optional sonarqube.ws.commons.Paging paging = 1; + repeated User users = 2; + + message User { + optional string login = 1; + optional string name = 2; + optional string avatar = 3; + optional bool selected = 4; + } +} diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java index 63c4fcc8e8d..655686b3e07 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/qualityprofile/QualityProfilesServiceTest.java @@ -22,6 +22,7 @@ package org.sonarqube.ws.client.qualityprofile; import org.junit.Rule; import org.junit.Test; import org.sonarqube.ws.Common.Severity; +import org.sonarqube.ws.QualityProfiles; import org.sonarqube.ws.QualityProfiles.SearchWsResponse; import org.sonarqube.ws.QualityProfiles.ShowResponse; import org.sonarqube.ws.client.GetRequest; @@ -31,6 +32,10 @@ import org.sonarqube.ws.client.WsConnector; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; +import static org.sonar.api.server.ws.WebService.Param.PAGE; +import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; +import static org.sonar.api.server.ws.WebService.Param.SELECTED; +import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_DEFAULTS; import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_FROM_KEY; @@ -235,4 +240,31 @@ public class QualityProfilesServiceTest { .hasParam(PARAM_LOGIN, "john") .andNoOtherParam(); } + + @Test + public void search_users() { + underTest.searchUsers(SearchUsersRequest.builder() + .setOrganization("O1") + .setQualityProfile("P1") + .setLanguage("Xoo") + .setQuery("john") + .setSelected("all") + .setPage(5) + .setPageSize(50) + .build() + ); + GetRequest getRequest = serviceTester.getGetRequest(); + + assertThat(serviceTester.getGetParser()).isSameAs(QualityProfiles.SearchUsersResponse.parser()); + serviceTester.assertThat(getRequest) + .hasPath("search_users") + .hasParam(PARAM_ORGANIZATION, "O1") + .hasParam(PARAM_QUALITY_PROFILE, "P1") + .hasParam(PARAM_LANGUAGE, "Xoo") + .hasParam(TEXT_QUERY, "john") + .hasParam(SELECTED, "all") + .hasParam(PAGE, 5) + .hasParam(PAGE_SIZE, 50) + .andNoOtherParam(); + } } |