From ffd619eff86cc391c826bfc9b2df98ab51d54ff5 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 21 Sep 2017 14:09:04 +0200 Subject: [PATCH] SONAR-1330 Create stub ws to allow edition of qprofile to users/groups --- .../qualityprofile/ws/AddGroupAction.java | 62 +++++++++++++++ .../qualityprofile/ws/AddUserAction.java | 78 +++++++++++++++++++ .../qualityprofile/ws/QProfilesWsModule.java | 10 ++- .../qualityprofile/ws/RemoveGroupAction.java | 62 +++++++++++++++ .../qualityprofile/ws/RemoveUserAction.java | 78 +++++++++++++++++++ .../qualityprofile/ws/SearchAction.java | 6 ++ .../qualityprofile/ws/SearchGroupsAction.java | 76 ++++++++++++++++++ .../qualityprofile/ws/SearchUsersAction.java | 76 ++++++++++++++++++ .../qualityprofile/ws/search-example.json | 33 ++++++-- .../ws/search_groups-example.json | 19 +++++ .../ws/search_users-example.json | 19 +++++ .../ws/QProfilesWsModuleTest.java | 2 +- .../ws/SearchGroupsActionTest.java | 60 ++++++++++++++ .../ws/SearchUsersActionTest.java | 60 ++++++++++++++ .../QualityProfileWsParameters.java | 14 +++- .../main/protobuf/ws-qualityprofiles.proto | 10 +++ 16 files changed, 654 insertions(+), 11 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddUserAction.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveGroupAction.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveUserAction.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java create mode 100644 server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_groups-example.json create mode 100644 server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_users-example.json create mode 100644 server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchGroupsActionTest.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchUsersActionTest.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java new file mode 100644 index 00000000000..7251b36acde --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java @@ -0,0 +1,62 @@ +/* + * 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.
" + + "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 + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddUserAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddUserAction.java new file mode 100644 index 00000000000..ca0ed070ecd --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddUserAction.java @@ -0,0 +1,78 @@ +/* + * 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.
" + + "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 + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java index f3362d94a61..6f5aa204f81 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java @@ -25,8 +25,9 @@ public class QProfilesWsModule extends Module { @Override protected void configureModule() { add( - QProfileWsSupport.class, AddProjectAction.class, + AddGroupAction.class, + AddUserAction.class, BackupAction.class, ActivateRulesAction.class, DeactivateRulesAction.class, @@ -42,16 +43,21 @@ public class QProfilesWsModule extends Module { 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 - ); + ); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveGroupAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveGroupAction.java new file mode 100644 index 00000000000..2df9637a2db --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveGroupAction.java @@ -0,0 +1,62 @@ +/* + * 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.
" + + "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 + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveUserAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveUserAction.java new file mode 100644 index 00000000000..4efdccaf9c8 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveUserAction.java @@ -0,0 +1,78 @@ +/* + * 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.
" + + "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 + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java index b192a68d883..6d4a594d26f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java @@ -238,6 +238,7 @@ public class SearchAction implements QProfileWsAction { Map 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(); @@ -261,6 +262,11 @@ public class SearchAction implements QProfileWsAction { 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(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java new file mode 100644 index 00000000000..0803b39e2b8 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java @@ -0,0 +1,76 @@ +/* + * 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.
" + + "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()); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java new file mode 100644 index 00000000000..4accbeb4091 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java @@ -0,0 +1,76 @@ +/* + * 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.
" + + "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()); + } +} diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search-example.json index 07ff1f2b8aa..70698410621 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search-example.json @@ -11,7 +11,12 @@ "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", @@ -28,7 +33,12 @@ "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", @@ -41,7 +51,12 @@ "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", @@ -53,7 +68,15 @@ "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 + } } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_groups-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_groups-example.json new file mode 100644 index 00000000000..084dfd4bb4e --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_groups-example.json @@ -0,0 +1,19 @@ +{ + "groups": [ + { + "name": "users", + "description": "Users", + "selected": true + }, + { + "name": "administrators", + "description": "Administrators", + "selected": false + } + ], + "paging": { + "pageSize": 100, + "total": 2, + "pageIndex": 1 + } +} diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_users-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_users-example.json new file mode 100644 index 00000000000..2eb7a636830 --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_users-example.json @@ -0,0 +1,19 @@ +{ + "users": [ + { + "login": "admin", + "name": "Administrator", + "selected": true + }, + { + "login": "george.orwell", + "name": "George Orwell", + "selected": false + } + ], + "paging": { + "pageSize": 100, + "total": 2, + "pageIndex": 1 + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java index 1764e6cafcc..d16a500bae3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java @@ -29,6 +29,6 @@ public class QProfilesWsModuleTest { 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); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchGroupsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchGroupsActionTest.java new file mode 100644 index 00000000000..fa2dfe68bc7 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchGroupsActionTest.java @@ -0,0 +1,60 @@ +/* + * 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); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchUsersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchUsersActionTest.java new file mode 100644 index 00000000000..7b28d74bdf6 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchUsersActionTest.java @@ -0,0 +1,60 @@ +/* + * 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); + } +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java index f4314b7a8d0..59053530c71 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java @@ -28,9 +28,10 @@ public class QualityProfileWsParameters { 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"; @@ -38,15 +39,22 @@ public class QualityProfileWsParameters { 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"; @@ -56,6 +64,7 @@ public class QualityProfileWsParameters { 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"; @@ -64,7 +73,6 @@ public class QualityProfileWsParameters { 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 diff --git a/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto b/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto index 3e19aaf63a7..a02f33fe395 100644 --- a/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto +++ b/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto @@ -27,6 +27,7 @@ option optimize_for = SPEED; // WS api/qualityprofiles/search message SearchWsResponse { repeated QualityProfile profiles = 1; + optional Actions actions = 2; message QualityProfile { optional string key = 1; @@ -45,6 +46,14 @@ message SearchWsResponse { 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; } } @@ -128,3 +137,4 @@ message ShowResponse { optional int64 missingRuleCount = 3; } } + -- 2.39.5