]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13436 Update Web API docs - user_groups
authorJacek <jacek.poreda@sonarsource.com>
Wed, 20 May 2020 08:58:21 +0000 (10:58 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 25 May 2020 20:05:24 +0000 (20:05 +0000)
17 files changed:
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/AddUserAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/CreateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/DeleteAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/RemoveUserAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/UsersAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/usergroups/ws/create-example.json
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/usergroups/ws/search-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java

index 045d18127951e829752738e79aa6219b78c23dc1..83cbe45e974128dec3d3534d1798ef4376abc63e 100644 (file)
@@ -64,7 +64,8 @@ public class AddUserAction implements UserGroupsWsAction {
       .setHandler(this)
       .setPost(true)
       .setSince("5.2")
-      .setChangelog(new Change("6.4", "It's no longer possible to add a user to the default group"));
+      .setChangelog(
+        new Change("8.4", "Parameter 'id' is deprecated. Format changes from integer to string. Use 'name' instead."));
 
     defineGroupWsParameters(action);
     defineLoginWsParameter(action);
index 29ffb885c39989df24a88fb0d5db9484717541e1..2992f6aa001eb4211086eddfde9c976cb25ec022 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.usergroups.ws;
 
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService.NewAction;
@@ -64,7 +65,9 @@ public class CreateAction implements UserGroupsWsAction {
       .setHandler(this)
       .setPost(true)
       .setResponseExample(getClass().getResource("create-example.json"))
-      .setSince("5.2");
+      .setSince("5.2")
+      .setChangelog(
+        new Change("8.4", "Field 'id' format in the response changes from integer to string."));
 
     action.createParam(PARAM_ORGANIZATION_KEY)
       .setDescription("Key of organization. If unset then default organization is used.")
index a892c57e898047f57fe6c8d30b0e8b6b71ac78e3..d8577d44cd20006f3f90a484d5da1ff197a41607 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.usergroups.ws;
 
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
@@ -56,7 +57,9 @@ public class DeleteAction implements UserGroupsWsAction {
         PARAM_GROUP_ID, PARAM_GROUP_NAME))
       .setHandler(this)
       .setSince("5.2")
-      .setPost(true);
+      .setPost(true)
+      .setChangelog(
+        new Change("8.4", "Parameter 'id' is deprecated. Format changes from integer to string. Use 'name' instead."));
 
     defineGroupWsParameters(action);
   }
index b25a09ac055a125bfd682398708637edd81067ae..64437873f3dda88eaa1a6d220595224c427960d5 100644 (file)
@@ -36,6 +36,7 @@ import org.sonarqube.ws.UserGroups;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Optional.ofNullable;
+import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
 import static org.sonar.server.exceptions.BadRequestException.checkRequest;
 import static org.sonar.server.exceptions.NotFoundException.checkFound;
 import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional;
@@ -162,9 +163,9 @@ public class GroupWsSupport {
 
   private static void defineGroupIdWsParameter(WebService.NewAction action) {
     action.createParam(PARAM_GROUP_ID)
-      .setDeprecatedSince("8.3")
-      .setDescription("Group id")
-      .setExampleValue("42");
+      .setDescription("Group id, use 'name' instead")
+      .setDeprecatedSince("8.4")
+      .setExampleValue(UUID_EXAMPLE_01);
   }
 
   private static void defineGroupNameWsParameter(WebService.NewAction action) {
index 8ccc9e6b268f55737f77655842dc5f1b786894a5..4b4d7d19f8e440f4bc24109b797fdb3b3f1c7535 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.usergroups.ws;
 
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService.NewAction;
@@ -60,7 +61,9 @@ public class RemoveUserAction implements UserGroupsWsAction {
         PARAM_GROUP_ID, PARAM_GROUP_NAME))
       .setHandler(this)
       .setPost(true)
-      .setSince("5.2");
+      .setSince("5.2")
+      .setChangelog(
+        new Change("8.4", "Parameter 'id' is deprecated. Format changes from integer to string. Use 'name' instead."));
 
     defineGroupWsParameters(action);
     defineLoginWsParameter(action);
index dc456bfff52b9894a51395f33d1574783d0c8d0e..4a2b5cb15f886376dd11c5eedfa92d7bc0b3b94e 100644 (file)
@@ -45,7 +45,6 @@ import static org.apache.commons.lang.StringUtils.defaultIfBlank;
 import static org.sonar.api.utils.Paging.forPageIndex;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
-import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_ID;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_ORGANIZATION_KEY;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 import static org.sonarqube.ws.UserGroups.Group;
@@ -82,9 +81,9 @@ public class SearchAction implements UserGroupsWsAction {
       .addPagingParams(100, MAX_LIMIT)
       .addSearchQuery("sonar-users", "names")
       .setChangelog(
+        new Change("8.4", "Field 'id' in the response is deprecated. Format changes from integer to string."),
         new Change("6.4", "Paging response fields moved to a Paging object"),
-        new Change("6.4", "'default' response field has been added"),
-        new Change("8.3", "field " + PARAM_GROUP_ID + "in the response is deprecated"));
+        new Change("6.4", "'default' response field has been added"));
 
     action.createParam(PARAM_ORGANIZATION_KEY)
       .setDescription("Key of organization. If not set then groups are searched in default organization.")
index 29902c15cd64d69f9e0e0456ef5f3eca1d2cbbab..6fc48fcf1b354ad63393c463c6310fff4733932b 100644 (file)
@@ -36,6 +36,7 @@ import org.sonarqube.ws.UserGroups;
 
 import static java.lang.String.format;
 import static org.sonar.api.user.UserGroupValidation.GROUP_NAME_MAX_LENGTH;
+import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 import static org.sonar.server.exceptions.NotFoundException.checkFound;
 import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional;
@@ -67,11 +68,13 @@ public class UpdateAction implements UserGroupsWsAction {
       .setPost(true)
       .setResponseExample(getClass().getResource("update.example.json"))
       .setSince("5.2")
-      .setChangelog(new Change("6.4", "The default group is no longer editable"));
+      .setChangelog(
+        new Change("8.4", "Parameter 'id' format changes from integer to string"),
+        new Change("6.4", "The default group is no longer editable"));
 
     action.createParam(PARAM_GROUP_ID)
       .setDescription("Identifier of the group.")
-      .setExampleValue("42")
+      .setExampleValue(UUID_EXAMPLE_01)
       .setRequired(true);
 
     action.createParam(PARAM_GROUP_NAME)
index 51d59895ecabcd99987dff4002606308b649b362..f8e0756bb79b5fb39575e11f49225b93cada23f6 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.usergroups.ws;
 
 import java.util.List;
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService.NewAction;
@@ -65,7 +66,9 @@ public class UsersAction implements UserGroupsWsAction {
       .setResponseExample(getClass().getResource("users-example.json"))
       .addSelectionModeParam()
       .addSearchQuery("freddy", "names", "logins")
-      .addPagingParams(25);
+      .addPagingParams(25)
+      .setChangelog(
+        new Change("8.4", "Parameter 'id' is deprecated. Format changes from integer to string. Use 'name' instead."));
 
     defineGroupWsParameters(action);
   }
index 909f1491ab62fbdf35b72dba3c7c4fb9abb5d7e4..2a27668836374748c1c7cfde9002fc2cdcee36a8 100644 (file)
@@ -1,6 +1,6 @@
 {
   "group": {
-    "id": "42",
+    "id": "AU-Tpxb--iU5OvuD2FLy",
     "organization": "my-org",
     "name": "some-product-bu",
     "description": "Business Unit for Some Awesome Product",
index 3749028681fff217ceb08e8e919f97260459940f..f165d2a76ee6cb920a32a9e792a44f87f3ea7266 100644 (file)
@@ -6,14 +6,14 @@
   },
   "groups": [
     {
-      "id": 3,
+      "id": "AU-Tpxb--iU5OvuD2FLy",
       "name": "users",
       "description": "Users",
       "membersCount": 17,
       "default": true
     },
     {
-      "id": 4,
+      "id": "AU-Tpxb--iU5OvuD2FLz",
       "name": "administrators",
       "description": "Administrators",
       "membersCount": 2,
index bfba587dd9b91f7015b96e0855d3db9f366ab2c6..d8a3f3117758b8ca05e9d3eca44ef3b88a5215e6 100644 (file)
@@ -23,6 +23,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
+import org.sonar.api.server.ws.Change;
+import org.sonar.api.server.ws.WebService.Action;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.user.GroupDto;
@@ -39,6 +41,7 @@ import org.sonar.server.ws.WsActionTester;
 
 import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.security.DefaultGroups.ANYONE;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_NAME;
@@ -57,6 +60,17 @@ public class AddUserActionTest {
   private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
   private WsActionTester ws = new WsActionTester(new AddUserAction(db.getDbClient(), userSession, newGroupWsSupport()));
 
+  @Test
+  public void verify_definition() {
+    Action wsDef = ws.getDef();
+
+    assertThat(wsDef.isInternal()).isEqualTo(false);
+    assertThat(wsDef.since()).isEqualTo("5.2");
+    assertThat(wsDef.isPost()).isEqualTo(true);
+    assertThat(wsDef.changelog()).extracting(Change::getVersion, Change::getDescription).containsOnly(
+      tuple("8.4", "Parameter 'id' is deprecated. Format changes from integer to string. Use 'name' instead."));
+  }
+
   @Test
   public void add_user_to_group_referenced_by_its_id() {
     insertDefaultGroupOnDefaultOrganization();
index 43e58a54fb616a48e9abbb78686f775255e657ae..4d170c779276cc1920c857f06b9b70d5e0e310d5 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.commons.lang.StringUtils;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.core.util.SequenceUuidFactory;
@@ -38,6 +39,7 @@ import org.sonar.server.usergroups.DefaultGroupFinder;
 import org.sonar.server.ws.WsActionTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 
 public class CreateActionTest {
@@ -61,6 +63,8 @@ public class CreateActionTest {
     assertThat(action.isPost()).isTrue();
     assertThat(action.responseExampleAsString()).isNotEmpty();
     assertThat(action.params()).hasSize(3);
+    assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsOnly(
+      tuple("8.4", "Field 'id' format in the response changes from integer to string."));
   }
 
   @Test
index 90cec02053a5b8add54a3a5b9ac09fd2cdff23ee..338877bd6f0a5a311baeb8c7312b2310632c9aa1 100644 (file)
@@ -23,6 +23,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
+import org.sonar.api.server.ws.Change;
+import org.sonar.api.server.ws.WebService.Action;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDbTester;
@@ -43,6 +45,7 @@ import org.sonar.server.ws.TestResponse;
 import org.sonar.server.ws.WsActionTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_ID;
@@ -62,6 +65,17 @@ public class DeleteActionTest {
   private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
   private WsActionTester ws = new WsActionTester(new DeleteAction(db.getDbClient(), userSession, newGroupWsSupport()));
 
+  @Test
+  public void verify_definition() {
+    Action wsDef = ws.getDef();
+
+    assertThat(wsDef.isInternal()).isEqualTo(false);
+    assertThat(wsDef.since()).isEqualTo("5.2");
+    assertThat(wsDef.isPost()).isEqualTo(true);
+    assertThat(wsDef.changelog()).extracting(Change::getVersion, Change::getDescription).containsOnly(
+      tuple("8.4", "Parameter 'id' is deprecated. Format changes from integer to string. Use 'name' instead."));
+  }
+
   @Test
   public void response_has_no_content() {
     addAdmin(db.getDefaultOrganization());
index fc9a952fe4bbd02b535a596dd1b6705fba6449ab..2f5ccc883fc9bf0aeb8ca786ba2b9ba7ccfa5c41 100644 (file)
@@ -23,6 +23,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
+import org.sonar.api.server.ws.Change;
+import org.sonar.api.server.ws.WebService.Action;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
@@ -40,6 +42,7 @@ import org.sonar.server.ws.WsActionTester;
 
 import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_NAME;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_LOGIN;
@@ -58,6 +61,17 @@ public class RemoveUserActionTest {
   private WsActionTester ws = new WsActionTester(
     new RemoveUserAction(db.getDbClient(), userSession, new GroupWsSupport(db.getDbClient(), defaultOrganizationProvider, new DefaultGroupFinder(db.getDbClient()))));
 
+  @Test
+  public void verify_definition() {
+    Action wsDef = ws.getDef();
+
+    assertThat(wsDef.isInternal()).isEqualTo(false);
+    assertThat(wsDef.since()).isEqualTo("5.2");
+    assertThat(wsDef.isPost()).isEqualTo(true);
+    assertThat(wsDef.changelog()).extracting(Change::getVersion, Change::getDescription).containsOnly(
+      tuple("8.4", "Parameter 'id' is deprecated. Format changes from integer to string. Use 'name' instead."));
+  }
+
   @Test
   public void does_nothing_if_user_is_not_in_group() {
     // keep an administrator
index 6c280aebeef794d059b861e29048fdaa5083ba54..504125cdefc8625d3bd3d1013e496fa416eb3fa5 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.usergroups.ws;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
@@ -64,7 +65,6 @@ public class SearchActionTest {
 
   private WsActionTester ws = new WsActionTester(new SearchAction(db.getDbClient(), userSession, newGroupWsSupport(), new DefaultGroupFinder(db.getDbClient())));
 
-
   @Test
   public void define_search_action() {
     WebService.Action action = ws.getDef();
@@ -72,6 +72,10 @@ public class SearchActionTest {
     assertThat(action.key()).isEqualTo("search");
     assertThat(action.responseExampleAsString()).isNotEmpty();
     assertThat(action.params()).hasSize(5);
+    assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsOnly(
+      tuple("8.4", "Field 'id' in the response is deprecated. Format changes from integer to string."),
+      tuple("6.4", "Paging response fields moved to a Paging object"),
+      tuple("6.4", "'default' response field has been added"));
   }
 
   @Test
index d13692ce1ff40222505bf6b5b0b6a34d23ea3c6d..ef6d51481b9b5871c3ebf815b5e5e9533ed7bb41 100644 (file)
@@ -22,6 +22,8 @@ package org.sonar.server.usergroups.ws;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.sonar.api.server.ws.Change;
+import org.sonar.api.server.ws.WebService.Action;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
@@ -36,6 +38,8 @@ import org.sonar.server.usergroups.DefaultGroupFinder;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 import static org.sonar.test.JsonAssert.assertJson;
 
@@ -52,6 +56,18 @@ public class UpdateActionTest {
   private WsActionTester ws = new WsActionTester(
     new UpdateAction(db.getDbClient(), userSession, new GroupWsSupport(db.getDbClient(), defaultOrganizationProvider, new DefaultGroupFinder(db.getDbClient()))));
 
+  @Test
+  public void verify_definition() {
+    Action wsDef = ws.getDef();
+
+    assertThat(wsDef.isInternal()).isEqualTo(false);
+    assertThat(wsDef.since()).isEqualTo("5.2");
+    assertThat(wsDef.isPost()).isEqualTo(true);
+    assertThat(wsDef.changelog()).extracting(Change::getVersion, Change::getDescription).containsOnly(
+      tuple("8.4", "Parameter 'id' format changes from integer to string"),
+      tuple("6.4", "The default group is no longer editable"));
+  }
+
   @Test
   public void update_both_name_and_description() {
     insertDefaultGroupOnDefaultOrganization();
index cfce3877ed38ffc8eb9d134276bce6888f0a590d..554a1ba45fb9876394d2530495b54a43f110c6f6 100644 (file)
@@ -22,6 +22,8 @@ package org.sonar.server.usergroups.ws;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.sonar.api.server.ws.Change;
+import org.sonar.api.server.ws.WebService.Action;
 import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.server.ws.WebService.SelectionMode;
 import org.sonar.api.utils.System2;
@@ -38,6 +40,7 @@ import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 import static org.sonar.db.user.UserTesting.newUserDto;
 import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_GROUP_ID;
@@ -55,6 +58,17 @@ public class UsersActionTest {
   private WsActionTester ws = new WsActionTester(
     new UsersAction(db.getDbClient(), userSession, new GroupWsSupport(db.getDbClient(), defaultOrganizationProvider, new DefaultGroupFinder(db.getDbClient()))));
 
+  @Test
+  public void verify_definition() {
+    Action wsDef = ws.getDef();
+
+    assertThat(wsDef.isInternal()).isEqualTo(false);
+    assertThat(wsDef.since()).isEqualTo("5.2");
+    assertThat(wsDef.isPost()).isEqualTo(false);
+    assertThat(wsDef.changelog()).extracting(Change::getVersion, Change::getDescription).containsOnly(
+      tuple("8.4", "Parameter 'id' is deprecated. Format changes from integer to string. Use 'name' instead."));
+  }
+
   @Test
   public void fail_if_unknown_group_uuid() {
     loginAsAdminOnDefaultOrganization();