]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1330 Create stub ws to allow edition of qprofile to users/groups
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 21 Sep 2017 12:09:04 +0000 (14:09 +0200)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Mon, 2 Oct 2017 15:18:15 +0000 (17:18 +0200)
16 files changed:
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddGroupAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddUserAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveGroupAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveUserAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchGroupsAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchUsersAction.java [new file with mode: 0644]
server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search-example.json
server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_groups-example.json [new file with mode: 0644]
server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/search_users-example.json [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchGroupsActionTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchUsersActionTest.java [new file with mode: 0644]
sonar-ws/src/main/java/org/sonarqube/ws/client/qualityprofile/QualityProfileWsParameters.java
sonar-ws/src/main/protobuf/ws-qualityprofiles.proto

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 (file)
index 0000000..7251b36
--- /dev/null
@@ -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.<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
+  }
+}
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 (file)
index 0000000..ca0ed07
--- /dev/null
@@ -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.<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
+  }
+}
index f3362d94a6187226ea59c43705d18345c8a26740..6f5aa204f8159759bd9d09ca8c01a504a9d1df06 100644 (file)
@@ -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 (file)
index 0000000..2df9637
--- /dev/null
@@ -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.<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
+  }
+}
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 (file)
index 0000000..4efdcca
--- /dev/null
@@ -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.<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
+  }
+}
index b192a68d8839a6fb9cf6713ccb83e0dbe396bd6d..6d4a594d26f79c3c82cdb695c991fe5dcb2c5333 100644 (file)
@@ -238,6 +238,7 @@ public class SearchAction implements QProfileWsAction {
     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();
@@ -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 (file)
index 0000000..0803b39
--- /dev/null
@@ -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.<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());
+  }
+}
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 (file)
index 0000000..4accbeb
--- /dev/null
@@ -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.<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());
+  }
+}
index 07ff1f2b8aae9cbd495a7fe9d8f9c02841c82361..706984106218a40abff66611135c6fc00fa61bc5 100644 (file)
       "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
+  }
 }
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 (file)
index 0000000..084dfd4
--- /dev/null
@@ -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 (file)
index 0000000..2eb7a63
--- /dev/null
@@ -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
+  }
+}
index 1764e6cafcce5bfc9dc41e189b433234ad1e175a..d16a500bae334e814d2c6fe7f3dafa92c000e417 100644 (file)
@@ -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 (file)
index 0000000..fa2dfe6
--- /dev/null
@@ -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 (file)
index 0000000..7b28d74
--- /dev/null
@@ -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);
+  }
+}
index f4314b7a8d0115e8763d2e56681f3009e6868b0a..59053530c716300d3b6e94342671972128e2dc3e 100644 (file)
@@ -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
index 3e19aaf63a7c2481abdd31688c902721734558f6..a02f33fe395c5e28f46eda66c69ed2ec877630ae 100644 (file)
@@ -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;
   }
 }
+