From 7e47d1b996746533cdc9815711b6deef5f88070c Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Thu, 16 Mar 2017 19:20:19 +0100 Subject: [PATCH] SONAR-8894 Define WS api/organizations/search_members --- .../component/ws/SearchProjectsAction.java | 1 + .../ws/OrganizationsWsModule.java | 1 + .../organization/ws/SearchMembersAction.java | 52 +++++++++++++++++++ .../ws/search_members-example.json | 2 + .../ws/OrganizationsWsModuleTest.java | 2 +- .../ws/SearchMembersActionTest.java | 45 ++++++++++++++++ 6 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchMembersAction.java create mode 100644 server/sonar-server/src/main/resources/org/sonar/server/organization/ws/search_members-example.json create mode 100644 server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchMembersActionTest.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index 688dc8d0550..2fba735fdf9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -115,6 +115,7 @@ public class SearchProjectsAction implements ComponentsWsAction { action.createParam(PARAM_ORGANIZATION) .setDescription("the organization to search projects in") .setRequired(false) + .setInternal(true) .setSince("6.3"); action.createParam(Param.FACETS) .setDescription("Comma-separated list of the facets to be computed. No facet is computed by default.") diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/OrganizationsWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/OrganizationsWsModule.java index 8180fab03b2..e521c412d13 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/OrganizationsWsModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/OrganizationsWsModule.java @@ -35,6 +35,7 @@ public class OrganizationsWsModule extends Module { EnableSupportAction.class, RemoveMemberAction.class, SearchAction.class, + SearchMembersAction.class, SearchMyOrganizationsAction.class, UpdateAction.class); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchMembersAction.java b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchMembersAction.java new file mode 100644 index 00000000000..764ce85ca83 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/SearchMembersAction.java @@ -0,0 +1,52 @@ +/* + * 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.sonar.server.organization.ws; + +import org.sonar.api.server.ws.Request; +import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; + +import static org.sonar.server.es.SearchOptions.MAX_LIMIT; + +public class SearchMembersAction implements OrganizationsWsAction { + @Override + public void define(WebService.NewController context) { + WebService.NewAction action = context.createAction("search_members") + .setResponseExample(getClass().getResource("search_members-example.json")) + .setSince("6.4") + .setInternal(true) + .setHandler(this); + + action.addSelectionModeParam(); + action.addSearchQuery("freddy", "names", "logins"); + action.addPagingParams(50, MAX_LIMIT); + + action.createParam("organization") + .setDescription("Organization key") + .setInternal(true) + .setRequired(false); + } + + @Override + public void handle(Request request, Response response) throws Exception { + // TODO + } +} diff --git a/server/sonar-server/src/main/resources/org/sonar/server/organization/ws/search_members-example.json b/server/sonar-server/src/main/resources/org/sonar/server/organization/ws/search_members-example.json new file mode 100644 index 00000000000..2c63c085104 --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/organization/ws/search_members-example.json @@ -0,0 +1,2 @@ +{ +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/OrganizationsWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/OrganizationsWsModuleTest.java index 89dc3e1b070..9e12ededad7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/OrganizationsWsModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/OrganizationsWsModuleTest.java @@ -33,7 +33,7 @@ public class OrganizationsWsModuleTest { ComponentContainer container = new ComponentContainer(); underTest.configure(container); assertThat(container.getPicoContainer().getComponentAdapters()) - .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 10); + .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 11); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchMembersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchMembersActionTest.java new file mode 100644 index 00000000000..0a79b637275 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/SearchMembersActionTest.java @@ -0,0 +1,45 @@ +/* + * 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.sonar.server.organization.ws; + +import org.junit.Test; +import org.sonar.api.server.ws.WebService; +import org.sonar.server.ws.WsActionTester; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SearchMembersActionTest { + + private WsActionTester ws = new WsActionTester(new SearchMembersAction()); + + @Test + public void definition() { + WebService.Action action = ws.getDef(); + + assertThat(action.key()).isEqualTo("search_members"); + assertThat(action.params()).extracting(WebService.Param::key) + .containsOnly("q", "selected", "p", "ps", "organization"); + assertThat(action.responseExampleAsString()).isNotEmpty(); + assertThat(action.since()).isEqualTo("6.4"); + assertThat(action.isInternal()).isTrue(); + assertThat(action.isPost()).isFalse(); + } +} -- 2.39.5