--- /dev/null
+/*
+ * 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.qualityprofile.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.core.util.Uuids.UUID_EXAMPLE_01;
+import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ADD_GROUP;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_GROUP;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
+
+public class AddGroupAction implements QProfileWsAction {
+
+ @Override
+ public void define(WebService.NewController context) {
+ WebService.NewAction action = context
+ .createAction(ACTION_ADD_GROUP)
+ .setDescription("Allow a group to edit a Quality Profile.<br>" +
+ "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.")
+ .setHandler(this)
+ .setPost(true)
+ .setInternal(true)
+ .setSince("6.6");
+
+ action.createParam(PARAM_PROFILE)
+ .setDescription("Quality Profile key.")
+ .setRequired(true)
+ .setExampleValue(UUID_EXAMPLE_01);
+
+ action.createParam(PARAM_GROUP)
+ .setDescription("Group name")
+ .setRequired(true)
+ .setExampleValue("sonar-administrators");
+
+ createOrganizationParam(action);
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ // TODO
+ }
+}
--- /dev/null
+/*
+ * 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.qualityprofile.ws;
+
+import java.util.Arrays;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Languages;
+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.core.util.stream.MoreCollectors.toSet;
+import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_ADD_USER;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LOGIN;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE;
+
+public class AddUserAction implements QProfileWsAction {
+
+ private final Languages languages;
+
+ public AddUserAction(Languages languages) {
+ this.languages = languages;
+ }
+
+ @Override
+ public void define(WebService.NewController context) {
+ WebService.NewAction action = context
+ .createAction(ACTION_ADD_USER)
+ .setDescription("Allow a user to edit a Quality Profile.<br>" +
+ "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.")
+ .setHandler(this)
+ .setPost(true)
+ .setInternal(true)
+ .setSince("6.6");
+
+ action.createParam(PARAM_QUALITY_PROFILE)
+ .setDescription("Quality Profile name")
+ .setRequired(true)
+ .setExampleValue("Recommended quality profile");
+
+ action
+ .createParam(PARAM_LANGUAGE)
+ .setDescription("Quality profile language")
+ .setRequired(true)
+ .setPossibleValues(Arrays.stream(languages.all()).map(Language::getKey).collect(toSet()));
+
+ action.createParam(PARAM_LOGIN)
+ .setDescription("User login")
+ .setRequired(true)
+ .setExampleValue("john.doe");
+
+ createOrganizationParam(action);
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ // TODO
+ }
+}
@Override
protected void configureModule() {
add(
- QProfileWsSupport.class,
AddProjectAction.class,
+ AddGroupAction.class,
+ AddUserAction.class,
BackupAction.class,
ActivateRulesAction.class,
DeactivateRulesAction.class,
ImportersAction.class,
InheritanceAction.class,
QProfilesWs.class,
+ QProfileWsSupport.class,
ProjectsAction.class,
RenameAction.class,
RemoveProjectAction.class,
+ RemoveGroupAction.class,
+ RemoveUserAction.class,
RestoreAction.class,
RestoreBuiltInAction.class,
ActivateRuleAction.class,
DeactivateRuleAction.class,
SearchAction.class,
+ SearchGroupsAction.class,
+ SearchUsersAction.class,
SetDefaultAction.class,
ShowAction.class
- );
+ );
}
}
--- /dev/null
+/*
+ * 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.qualityprofile.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.core.util.Uuids.UUID_EXAMPLE_01;
+import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_REMOVE_GROUP;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_GROUP;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
+
+public class RemoveGroupAction implements QProfileWsAction {
+
+ @Override
+ public void define(WebService.NewController context) {
+ WebService.NewAction action = context
+ .createAction(ACTION_REMOVE_GROUP)
+ .setDescription("Remove the ability from a group to edit a Quality Profile.<br>" +
+ "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.")
+ .setHandler(this)
+ .setPost(true)
+ .setInternal(true)
+ .setSince("6.6");
+
+ action.createParam(PARAM_PROFILE)
+ .setDescription("Quality Profile key.")
+ .setRequired(true)
+ .setExampleValue(UUID_EXAMPLE_01);
+
+ action.createParam(PARAM_GROUP)
+ .setDescription("Group name")
+ .setRequired(true)
+ .setExampleValue("sonar-administrators");
+
+ createOrganizationParam(action);
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ // TODO
+ }
+}
--- /dev/null
+/*
+ * 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.qualityprofile.ws;
+
+import java.util.Arrays;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Languages;
+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.core.util.stream.MoreCollectors.toSet;
+import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_REMOVE_USER;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LOGIN;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE;
+
+public class RemoveUserAction implements QProfileWsAction {
+
+ private final Languages languages;
+
+ public RemoveUserAction(Languages languages) {
+ this.languages = languages;
+ }
+
+ @Override
+ public void define(WebService.NewController context) {
+ WebService.NewAction action = context
+ .createAction(ACTION_REMOVE_USER)
+ .setDescription("Remove the ability from a user to edit a Quality Profile.<br>" +
+ "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.")
+ .setHandler(this)
+ .setPost(true)
+ .setInternal(true)
+ .setSince("6.6");
+
+ action.createParam(PARAM_QUALITY_PROFILE)
+ .setDescription("Quality Profile name")
+ .setRequired(true)
+ .setExampleValue("Recommended quality profile");
+
+ action
+ .createParam(PARAM_LANGUAGE)
+ .setDescription("Quality profile language")
+ .setRequired(true)
+ .setPossibleValues(Arrays.stream(languages.all()).map(Language::getKey).collect(toSet()));
+
+ action.createParam(PARAM_LOGIN)
+ .setDescription("User login")
+ .setRequired(true)
+ .setExampleValue("john.doe");
+
+ createOrganizationParam(action);
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ // TODO
+ }
+}
Map<String, QProfileDto> profilesByKey = profiles.stream().collect(Collectors.toMap(QProfileDto::getKee, identity()));
SearchWsResponse.Builder response = SearchWsResponse.newBuilder();
+ response.setActions(SearchWsResponse.Actions.newBuilder().setCreate(true));
for (QProfileDto profile : profiles) {
QualityProfile.Builder profileBuilder = response.addProfilesBuilder();
writeParentFields(profileBuilder, profile, profilesByKey);
profileBuilder.setIsInherited(profile.getParentKee() != null);
profileBuilder.setIsBuiltIn(profile.isBuiltIn());
+
+ profileBuilder.setActions(SearchWsResponse.Actions.newBuilder()
+ .setEdit(true)
+ .setSetAsDefault(false)
+ .setCopy(false));
}
return response.build();
--- /dev/null
+/*
+ * 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.qualityprofile.ws;
+
+import java.util.Arrays;
+import org.apache.commons.io.IOUtils;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Languages;
+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.core.util.stream.MoreCollectors.toSet;
+import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SEARCH_GROUPS;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE;
+
+public class SearchGroupsAction implements QProfileWsAction {
+
+ private final Languages languages;
+
+ public SearchGroupsAction(Languages languages) {
+ this.languages = languages;
+ }
+
+ @Override
+ public void define(WebService.NewController context) {
+ WebService.NewAction action = context
+ .createAction(ACTION_SEARCH_GROUPS)
+ .setDescription("List the groups that are allowed to edit a Quality Profile.<br>" +
+ "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.")
+ .setHandler(this)
+ .setInternal(true)
+ .addSelectionModeParam()
+ .addSearchQuery("sonar", "group names")
+ .addPagingParams(25)
+ .setResponseExample(getClass().getResource("search_groups-example.json"))
+ .setSince("6.6");
+
+ action.createParam(PARAM_QUALITY_PROFILE)
+ .setDescription("Quality Profile name")
+ .setRequired(true)
+ .setExampleValue("Recommended quality profile");
+
+ action
+ .createParam(PARAM_LANGUAGE)
+ .setDescription("Quality profile language")
+ .setRequired(true)
+ .setPossibleValues(Arrays.stream(languages.all()).map(Language::getKey).collect(toSet()));
+
+ createOrganizationParam(action);
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ IOUtils.write(IOUtils.toString(getClass().getResource("search_groups-example.json")), response.stream().output());
+ }
+}
--- /dev/null
+/*
+ * 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.qualityprofile.ws;
+
+import java.util.Arrays;
+import org.apache.commons.io.IOUtils;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Languages;
+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.core.util.stream.MoreCollectors.toSet;
+import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SEARCH_USERS;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE;
+
+public class SearchUsersAction implements QProfileWsAction {
+
+ private final Languages languages;
+
+ public SearchUsersAction(Languages languages) {
+ this.languages = languages;
+ }
+
+ @Override
+ public void define(WebService.NewController context) {
+ WebService.NewAction action = context
+ .createAction(ACTION_SEARCH_USERS)
+ .setDescription("List the users that are allowed to edit a Quality Profile.<br>" +
+ "Requires the 'Administer Quality Profiles' permission or the ability to edit the quality profile.")
+ .setHandler(this)
+ .setInternal(true)
+ .addSearchQuery("freddy", "names", "logins")
+ .addSelectionModeParam()
+ .addPagingParams(25)
+ .setResponseExample(getClass().getResource("search_users-example.json"))
+ .setSince("6.6");
+
+ action.createParam(PARAM_QUALITY_PROFILE)
+ .setDescription("Quality Profile name")
+ .setRequired(true)
+ .setExampleValue("Recommended quality profile");
+
+ action
+ .createParam(PARAM_LANGUAGE)
+ .setDescription("Quality profile language")
+ .setRequired(true)
+ .setPossibleValues(Arrays.stream(languages.all()).map(Language::getKey).collect(toSet()));
+
+ createOrganizationParam(action);
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ IOUtils.write(IOUtils.toString(getClass().getResource("search_users-example.json")), response.stream().output());
+ }
+}
"activeDeprecatedRuleCount": 0,
"isDefault": true,
"ruleUpdatedAt": "2016-12-22T19:10:03+0100",
- "lastUsed": "2016-12-01T19:10:03+0100"
+ "lastUsed": "2016-12-01T19:10:03+0100",
+ "actions": {
+ "edit": true,
+ "setAsDefault": false,
+ "copy": false
+ }
},
{
"key": "AU-TpxcA-iU5OvuD2FL1",
"projectCount": 7,
"ruleUpdatedAt": "2016-12-20T19:10:03+0100",
"lastUsed": "2016-12-21T16:10:03+0100",
- "userUpdatedAt": "2016-06-28T21:57:01+0200"
+ "userUpdatedAt": "2016-06-28T21:57:01+0200",
+ "actions": {
+ "edit": true,
+ "setAsDefault": false,
+ "copy": false
+ }
},
{
"key": "iU5OvuD2FLz",
"activeRuleCount": 9,
"activeDeprecatedRuleCount": 2,
"ruleUpdatedAt": "2016-12-22T19:10:03+0100",
- "userUpdatedAt": "2016-06-29T21:57:01+0200"
+ "userUpdatedAt": "2016-06-29T21:57:01+0200",
+ "actions": {
+ "edit": true,
+ "setAsDefault": false,
+ "copy": false
+ }
},
{
"key": "AU-TpxcB-iU5OvuD2FL7",
"activeRuleCount": 2,
"activeDeprecatedRuleCount": 0,
"isDefault": true,
- "ruleUpdatedAt": "2014-12-22T19:10:03+0100"
+ "ruleUpdatedAt": "2014-12-22T19:10:03+0100",
+ "actions": {
+ "edit": true,
+ "setAsDefault": false,
+ "copy": false
+ }
}
- ]
+ ],
+ "actions": {
+ "create": true
+ }
}
--- /dev/null
+{
+ "groups": [
+ {
+ "name": "users",
+ "description": "Users",
+ "selected": true
+ },
+ {
+ "name": "administrators",
+ "description": "Administrators",
+ "selected": false
+ }
+ ],
+ "paging": {
+ "pageSize": 100,
+ "total": 2,
+ "pageIndex": 1
+ }
+}
--- /dev/null
+{
+ "users": [
+ {
+ "login": "admin",
+ "name": "Administrator",
+ "selected": true
+ },
+ {
+ "login": "george.orwell",
+ "name": "George Orwell",
+ "selected": false
+ }
+ ],
+ "paging": {
+ "pageSize": 100,
+ "total": 2,
+ "pageIndex": 1
+ }
+}
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new QProfilesWsModule().configure(container);
- assertThat(container.size()).isEqualTo(27 + 2);
+ assertThat(container.size()).isEqualTo(33 + 2);
}
}
--- /dev/null
+/*
+ * 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.qualityprofile.ws;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.resources.Languages;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.language.LanguageTesting;
+import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.test.JsonAssert.assertJson;
+import static org.sonarqube.ws.MediaTypes.JSON;
+
+public class SearchGroupsActionTest {
+
+ private static final String XOO = "xoo";
+ private static final Languages LANGUAGES = LanguageTesting.newLanguages(XOO);
+
+ @Rule
+ public UserSessionRule userSession = UserSessionRule.standalone();
+
+ private WsActionTester ws = new WsActionTester(new SearchGroupsAction(LANGUAGES));
+
+ @Test
+ public void test_definition() {
+ WebService.Action def = ws.getDef();
+ assertThat(def.key()).isEqualTo("search_groups");
+ assertThat(def.isPost()).isFalse();
+ assertThat(def.isInternal()).isTrue();
+ assertThat(def.params()).extracting(WebService.Param::key)
+ .containsExactlyInAnyOrder("organization", "qualityProfile", "language", "selected", "q", "p", "ps");
+ }
+
+ @Test
+ public void test_example() {
+ String result = ws.newRequest().setMediaType(JSON).execute().getInput();
+
+ assertJson(ws.getDef().responseExampleAsString()).isSimilarTo(result);
+ }
+}
--- /dev/null
+/*
+ * 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.qualityprofile.ws;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.resources.Languages;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.language.LanguageTesting;
+import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.test.JsonAssert.assertJson;
+import static org.sonarqube.ws.MediaTypes.JSON;
+
+public class SearchUsersActionTest {
+
+ private static final String XOO = "xoo";
+ private static final Languages LANGUAGES = LanguageTesting.newLanguages(XOO);
+
+ @Rule
+ public UserSessionRule userSession = UserSessionRule.standalone();
+
+ private WsActionTester ws = new WsActionTester(new SearchUsersAction(LANGUAGES));
+
+ @Test
+ public void test_definition() {
+ WebService.Action def = ws.getDef();
+ assertThat(def.key()).isEqualTo("search_users");
+ assertThat(def.isPost()).isFalse();
+ assertThat(def.isInternal()).isTrue();
+ assertThat(def.params()).extracting(WebService.Param::key)
+ .containsExactlyInAnyOrder("organization", "qualityProfile", "language", "selected", "q", "p", "ps");
+ }
+
+ @Test
+ public void test_example() {
+ String result = ws.newRequest().setMediaType(JSON).execute().getInput();
+
+ assertJson(ws.getDef().responseExampleAsString()).isSimilarTo(result);
+ }
+}
String PARAM_BACKUP = "backup";
}
public static final String ACTION_ACTIVATE_RULE = "activate_rule";
-
public static final String ACTION_ACTIVATE_RULES = "activate_rules";
public static final String ACTION_ADD_PROJECT = "add_project";
+ public static final String ACTION_ADD_GROUP = "add_group";
+ public static final String ACTION_ADD_USER = "add_user";
public static final String ACTION_CHANGE_PARENT = "change_parent";
public static final String ACTION_COPY = "copy";
public static final String ACTION_CREATE = "create";
public static final String ACTION_DEACTIVATE_RULES = "deactivate_rules";
public static final String ACTION_DELETE = "delete";
public static final String ACTION_REMOVE_PROJECT = "remove_project";
+ public static final String ACTION_REMOVE_GROUP = "remove_group";
+ public static final String ACTION_REMOVE_USER = "remove_user";
public static final String ACTION_RESTORE = "restore";
public static final String ACTION_SEARCH = "search";
+ public static final String ACTION_SEARCH_USERS = "search_users";
+ public static final String ACTION_SEARCH_GROUPS = "search_groups";
public static final String ACTION_SHOW = "show";
public static final String ACTION_SET_DEFAULT = "set_default";
- public static final String PARAM_DEFAULTS = "defaults";
+ public static final String PARAM_COMPARE_TO_SONAR_WAY = "compareToSonarWay";
+ public static final String PARAM_DEFAULTS = "defaults";
public static final String PARAM_FROM_KEY = "fromKey";
+ public static final String PARAM_GROUP = "group";
public static final String PARAM_ORGANIZATION = "organization";
public static final String PARAM_LANGUAGE = "language";
+ public static final String PARAM_LOGIN = "login";
public static final String PARAM_NAME = "name";
public static final String PARAM_PARAMS = "params";
public static final String PARAM_PARENT_KEY = "parentKey";
public static final String PARAM_PROJECT = "project";
public static final String PARAM_PROJECT_KEY = "projectKey";
public static final String PARAM_PROJECT_UUID = "projectUuid";
+ public static final String PARAM_QUERY = "q";
public static final String PARAM_RESET = "reset";
public static final String PARAM_RULE = "rule";
public static final String PARAM_SEVERITY = "severity";
public static final String PARAM_TARGET_SEVERITY = "targetSeverity";
public static final String PARAM_TO = "to";
public static final String PARAM_TO_NAME = "toName";
- public static final String PARAM_COMPARE_TO_SONAR_WAY = "compareToSonarWay";
private QualityProfileWsParameters() {
// Only static stuff
// WS api/qualityprofiles/search
message SearchWsResponse {
repeated QualityProfile profiles = 1;
+ optional Actions actions = 2;
message QualityProfile {
optional string key = 1;
optional string userUpdatedAt = 14;
optional string organization = 15;
optional bool isBuiltIn = 16;
+ optional Actions actions = 17;
+ }
+
+ message Actions {
+ optional bool create = 1;
+ optional bool edit = 2;
+ optional bool setAsDefault = 3;
+ optional bool copy = 4;
}
}
optional int64 missingRuleCount = 3;
}
}
+