]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13436 Update Web API docs - permissions
authorJacek <jacek.poreda@sonarsource.com>
Wed, 20 May 2020 08:21:55 +0000 (10:21 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 25 May 2020 20:05:24 +0000 (20:05 +0000)
12 files changed:
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/GroupsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/WsParameters.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/AddGroupToTemplateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/permission/ws/groups-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/AddGroupToTemplateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateActionTest.java

index a34f2cb3647b46514c3ae41c4c10eced00470cdf..8674803b1808fc7302d60d91c6a3af003595a182 100644 (file)
@@ -21,13 +21,14 @@ package org.sonar.server.permission.ws;
 
 import com.google.common.collect.ImmutableList;
 import java.util.Optional;
+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;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.server.permission.GroupUuidOrAnyone;
 import org.sonar.server.permission.GroupPermissionChange;
+import org.sonar.server.permission.GroupUuidOrAnyone;
 import org.sonar.server.permission.PermissionChange;
 import org.sonar.server.permission.PermissionService;
 import org.sonar.server.permission.PermissionUpdater;
@@ -74,6 +75,8 @@ public class AddGroupAction implements PermissionsWsAction {
         "<li>'Administer' rights on the specified project</li>" +
         "</ul>")
       .setSince("5.2")
+      .setChangelog(
+        new Change("8.4", "Parameter 'groupId' is deprecated. Format changes from integer to string. Use 'name' instead."))
       .setPost(true)
       .setHandler(this);
 
index 94f5abb11504d860bcddd159434558b1b471e868..28e2aed31ebaa107f94cd2340bf0b93d00f1cfe3 100644 (file)
@@ -84,6 +84,7 @@ public class GroupsAction implements PermissionsWsAction {
         "</ul>")
       .addPagingParams(DEFAULT_PAGE_SIZE, RESULTS_MAX_SIZE)
       .setChangelog(
+        new Change("8.4", "Field 'id' in the response is deprecated. Format changes from integer to string."),
         new Change("7.4", "The response list is returning all groups even those without permissions, the groups with permission are at the top of the list."))
       .setResponseExample(Resources.getResource(getClass(), "groups-example.json"))
       .setHandler(this);
index 94518082ae9aa86ad978caa7204be5a73bc8059d..d246880b480bce348e795b003debd5a6649dfaf6 100644 (file)
 package org.sonar.server.permission.ws;
 
 import java.util.Optional;
+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;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.server.permission.GroupUuidOrAnyone;
 import org.sonar.server.permission.GroupPermissionChange;
+import org.sonar.server.permission.GroupUuidOrAnyone;
 import org.sonar.server.permission.PermissionChange;
 import org.sonar.server.permission.PermissionService;
 import org.sonar.server.permission.PermissionUpdater;
@@ -75,6 +76,8 @@ public class RemoveGroupAction implements PermissionsWsAction {
         "</ul>")
       .setSince("5.2")
       .setPost(true)
+      .setChangelog(
+        new Change("8.4", "Parameter 'groupId' is deprecated. Format changes from integer to string. Use 'groupName' instead."))
       .setHandler(this);
 
     wsParameters.createPermissionParameter(action);
index 08e0ba28bd68574eb414cff53bcab0d9d7b37dfc..bc086b6b3b135ca874ead5edae12094673650aa7 100644 (file)
@@ -22,9 +22,9 @@ package org.sonar.server.permission.ws;
 import com.google.common.base.Joiner;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.util.Uuids;
 import org.sonar.server.permission.PermissionService;
 
+import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
 import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_DESCRIPTION;
 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
@@ -49,16 +49,16 @@ public class WsParameters {
     this.permissionService = permissionService;
     String allProjectsPermissionsOnOneLine = Joiner.on(", ").join(permissionService.getAllProjectPermissions());
     permissionParamDescription = String.format("Permission" +
-        "<ul>" +
-        "<li>Possible values for global permissions: %s</li>" +
-        "<li>Possible values for project permissions %s</li>" +
-        "</ul>",
+      "<ul>" +
+      "<li>Possible values for global permissions: %s</li>" +
+      "<li>Possible values for project permissions %s</li>" +
+      "</ul>",
       GlobalPermissions.ALL_ON_ONE_LINE,
       allProjectsPermissionsOnOneLine);
     projectPermissionParamDescription = String.format("Permission" +
-        "<ul>" +
-        "<li>Possible values for project permissions %s</li>" +
-        "</ul>",
+      "<ul>" +
+      "<li>Possible values for project permissions %s</li>" +
+      "</ul>",
       allProjectsPermissionsOnOneLine);
   }
 
@@ -94,8 +94,9 @@ public class WsParameters {
 
   public static void createGroupIdParameter(WebService.NewAction action) {
     action.createParam(PARAM_GROUP_ID)
-      .setDescription("Group id")
-      .setExampleValue("42");
+      .setDescription("Group id, use 'name' param instead")
+      .setDeprecatedSince("8.4")
+      .setExampleValue(UUID_EXAMPLE_01);
   }
 
   public static void createProjectParameters(WebService.NewAction action) {
@@ -121,7 +122,7 @@ public class WsParameters {
   public static void createTemplateParameters(WebService.NewAction action) {
     action.createParam(PARAM_TEMPLATE_ID)
       .setDescription("Template id")
-      .setExampleValue(Uuids.UUID_EXAMPLE_01);
+      .setExampleValue(UUID_EXAMPLE_01);
     createOrganizationParameter(action);
     action.createParam(PARAM_TEMPLATE_NAME)
       .setDescription("Template name")
index 19394220cfa1d19581bd153e8792e88fbd567743..281363f34b651df5923c867fb856e076eb5f6df7 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.permission.ws.template;
 
+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;
@@ -63,6 +64,8 @@ public class AddGroupToTemplateAction implements PermissionsWsAction {
       .setDescription("Add a group to a permission template.<br /> " +
         "The group id or group name must be provided. <br />" +
         "Requires the following permission: 'Administer System'.")
+      .setChangelog(
+        new Change("8.4", "Parameter 'groupId' is deprecated. Format changes from integer to string. Use 'groupName' instead."))
       .setHandler(this);
 
     createTemplateParameters(action);
index 3556ebd26184e4270944122b9b98e78afe7138f8..cd9cb7a84241a78fd5758cc1971bcd863b67c35f 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.permission.ws.template;
 
+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;
@@ -60,6 +61,8 @@ public class RemoveGroupFromTemplateAction implements PermissionsWsAction {
       .setDescription("Remove a group from a permission template.<br /> " +
         "The group id or group name must be provided. <br />" +
         "Requires the following permission: 'Administer System'.")
+      .setChangelog(
+        new Change("8.4", "Parameter 'groupId' is deprecated. Format changes from integer to string. Use 'groupName' instead."))
       .setHandler(this);
 
     createTemplateParameters(action);
index 4d85eb8b44a40dde6dde68515991001d4da71963..9a67c7fa65fcfffbceaad3e1e20b0a15280bb2cf 100644 (file)
       "permissions": []
     },
     {
-      "id": "1",
+      "id": "AU-Tpxb--iU5OvuD2FLy",
       "name": "sonar-administrators",
       "description": "System administrators",
       "permissions": []
     },
     {
-      "id": "2",
+      "id": "AU-Tpxb--iU5OvuD2FLz",
       "name": "sonar-users",
       "description": "Any new users created will automatically join this group",
       "permissions": []
index 143e4977e86d4afc4661355d283400ed9aebf4e6..d6dcd139466a455f6645e155b99dda4ca172e530 100644 (file)
@@ -22,6 +22,8 @@ package org.sonar.server.permission.ws;
 import org.junit.Test;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.ResourceTypes;
+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.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
@@ -38,6 +40,7 @@ import org.sonar.server.permission.PermissionServiceImpl;
 import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.web.UserRole.CODEVIEWER;
 import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
 import static org.sonar.api.web.UserRole.USER;
@@ -71,6 +74,17 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
     return new AddGroupAction(db.getDbClient(), userSession, newPermissionUpdater(), newPermissionWsSupport(), wsParameters, permissionService);
   }
 
+  @Test
+  public void verify_definition() {
+    Action wsDef = wsTester.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 'groupId' is deprecated. Format changes from integer to string. Use 'name' instead."));
+  }
+
   @Test
   public void add_permission_to_group_referenced_by_its_name() {
     GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
index e601e8eff7ef6c2c909a5b71e9d4644b7d92aaf9..f54082e94b15e21c95a93429b8bd50488d6b65b8 100644 (file)
@@ -24,6 +24,8 @@ import org.junit.Test;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.security.DefaultGroups;
+import org.sonar.api.server.ws.Change;
+import org.sonar.api.server.ws.WebService.Action;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.component.ResourceTypesRule;
@@ -38,6 +40,7 @@ import org.sonar.server.permission.PermissionServiceImpl;
 
 import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.server.ws.WebService.Param.PAGE;
 import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
 import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
@@ -83,6 +86,18 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> {
     db.commit();
   }
 
+  @Test
+  public void verify_definition() {
+    Action wsDef = wsTester.getDef();
+
+    assertThat(wsDef.isInternal()).isEqualTo(true);
+    assertThat(wsDef.since()).isEqualTo("5.2");
+    assertThat(wsDef.isPost()).isEqualTo(false);
+    assertThat(wsDef.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder(
+      tuple("8.4", "Field 'id' in the response is deprecated. Format changes from integer to string."),
+      tuple("7.4", "The response list is returning all groups even those without permissions, the groups with permission are at the top of the list."));
+  }
+
   @Test
   public void search_for_groups_with_one_permission() {
     loginAsAdmin(db.getDefaultOrganization());
@@ -91,35 +106,35 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> {
       .setParam(PARAM_PERMISSION, SCAN.getKey())
       .execute()
       .getInput();
-      assertJson(json).isSimilarTo("{\n" +
-        "  \"paging\": {\n" +
-        "    \"pageIndex\": 1,\n" +
-        "    \"pageSize\": 20,\n" +
-        "    \"total\": 3\n" +
-        "  },\n" +
-        "  \"groups\": [\n" +
-        "    {\n" +
-        "      \"name\": \"Anyone\",\n" +
-        "      \"permissions\": [\n" +
-        "        \"scan\"\n" +
-        "      ]\n" +
-        "    },\n" +
-        "    {\n" +
-        "      \"name\": \"group-1-name\",\n" +
-        "      \"description\": \"" + group1.getDescription() + "\",\n" +
-        "      \"permissions\": [\n" +
-        "        \"scan\"\n" +
-        "      ]\n" +
-        "    },\n" +
-        "    {\n" +
-        "      \"name\": \"group-2-name\",\n" +
-        "      \"description\": \"" + group2.getDescription() + "\",\n" +
-        "      \"permissions\": [\n" +
-        "        \"scan\"\n" +
-        "      ]\n" +
-        "    }\n" +
-        "  ]\n" +
-        "}\n");
+    assertJson(json).isSimilarTo("{\n" +
+      "  \"paging\": {\n" +
+      "    \"pageIndex\": 1,\n" +
+      "    \"pageSize\": 20,\n" +
+      "    \"total\": 3\n" +
+      "  },\n" +
+      "  \"groups\": [\n" +
+      "    {\n" +
+      "      \"name\": \"Anyone\",\n" +
+      "      \"permissions\": [\n" +
+      "        \"scan\"\n" +
+      "      ]\n" +
+      "    },\n" +
+      "    {\n" +
+      "      \"name\": \"group-1-name\",\n" +
+      "      \"description\": \"" + group1.getDescription() + "\",\n" +
+      "      \"permissions\": [\n" +
+      "        \"scan\"\n" +
+      "      ]\n" +
+      "    },\n" +
+      "    {\n" +
+      "      \"name\": \"group-2-name\",\n" +
+      "      \"description\": \"" + group2.getDescription() + "\",\n" +
+      "      \"permissions\": [\n" +
+      "        \"scan\"\n" +
+      "      ]\n" +
+      "    }\n" +
+      "  ]\n" +
+      "}\n");
   }
 
   @Test
index 4f33c807f3d1d76bc18575e6f2e6e8aeeb95b7b5..c0bf8168b6104e9cf66270d5b8bdc26c54245616 100644 (file)
@@ -23,6 +23,8 @@ import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.ResourceTypes;
+import org.sonar.api.server.ws.Change;
+import org.sonar.api.server.ws.WebService.Action;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.util.Uuids;
 import org.sonar.db.component.ComponentDto;
@@ -39,6 +41,7 @@ import org.sonar.server.permission.PermissionServiceImpl;
 
 import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.web.UserRole.ADMIN;
 import static org.sonar.api.web.UserRole.CODEVIEWER;
 import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
@@ -75,6 +78,17 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio
     return new RemoveGroupAction(db.getDbClient(), userSession, newPermissionUpdater(), newPermissionWsSupport(), wsParameters, permissionService);
   }
 
+  @Test
+  public void verify_definition() {
+    Action wsDef = wsTester.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 'groupId' is deprecated. Format changes from integer to string. Use 'groupName' instead."));
+  }
+
   @Test
   public void remove_permission_using_group_name() {
     db.users().insertPermissionOnGroup(aGroup, ADMINISTER);
index 3af76e20ec79d9afc1f0f6faeb2d04d4a80aa185..d35903d3749a9573a36f9ebdb974a461ccd64ef6 100644 (file)
@@ -25,6 +25,8 @@ import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.ResourceTypes;
+import org.sonar.api.server.ws.Change;
+import org.sonar.api.server.ws.WebService.Action;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.component.ResourceTypesRule;
@@ -41,6 +43,7 @@ import org.sonar.server.permission.ws.WsParameters;
 import org.sonar.server.ws.TestRequest;
 
 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.api.web.UserRole.ADMIN;
 import static org.sonar.api.web.UserRole.CODEVIEWER;
@@ -70,6 +73,17 @@ public class AddGroupToTemplateActionTest extends BasePermissionWsTest<AddGroupT
     group = db.users().insertGroup(db.getDefaultOrganization(), "group-name");
   }
 
+  @Test
+  public void verify_definition() {
+    Action wsDef = wsTester.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 'groupId' is deprecated. Format changes from integer to string. Use 'groupName' instead."));
+  }
+
   @Test
   public void add_group_to_template() {
     loginAsAdmin(db.getDefaultOrganization());
index a58014937a17d5b3cc7d3a4b563b5f61eed1142d..c0394bc5e174daba1778f19209a21f0473ff5e7c 100644 (file)
@@ -25,6 +25,8 @@ import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.ResourceTypes;
+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.component.ResourceTypesRule;
 import org.sonar.db.permission.PermissionQuery;
@@ -41,6 +43,7 @@ import org.sonar.server.permission.ws.WsParameters;
 import org.sonar.server.ws.TestRequest;
 
 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.api.web.UserRole.CODEVIEWER;
 import static org.sonar.db.permission.OrganizationPermission.SCAN;
@@ -74,6 +77,17 @@ public class RemoveGroupFromTemplateActionTest extends BasePermissionWsTest<Remo
     addGroupToTemplate(template, group.getUuid(), PERMISSION);
   }
 
+  @Test
+  public void verify_definition() {
+    Action wsDef = wsTester.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 'groupId' is deprecated. Format changes from integer to string. Use 'groupName' instead."));
+  }
+
   @Test
   public void remove_group_from_template() {
     newRequest(group.getName(), template.getUuid(), PERMISSION);