]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9140 support public/private projects in GroupPermissionMapper
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 20 Apr 2017 07:56:28 +0000 (09:56 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 27 Apr 2017 12:25:54 +0000 (14:25 +0200)
no change required, this mapper provides SQL request to CRUD table GROUP_ROLES

server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java

index a7a6e545d487b51332050966ea6fbef843bb22bd..b2ab5ef4a9ebd04d109b5932b43459615a184882 100644 (file)
@@ -5,23 +5,38 @@
 
   <select id="groupsCountByProjectIdAndPermission" parameterType="map"
           resultType="org.sonar.db.permission.CountPerProjectPermission">
-    SELECT count(1) as count, permission, componentId
-    FROM
-    (SELECT g.name as name, group_role.role as permission, group_role.resource_id as componentId
-    FROM groups g
-    INNER JOIN group_roles group_role ON group_role.group_id=g.id
-    UNION
-    -- Add Anyone group permission
-    SELECT #{anyoneGroup} as name, group_role.role as permission, group_role.resource_id as componentId
-    FROM group_roles group_role
-    where group_role.group_id IS NULL
+    SELECT
+      count(1) as count,
+      permission,
+      componentId
+    FROM (
+      SELECT
+        g.name as name,
+        group_role.role as permission,
+        group_role.resource_id as componentId
+      FROM
+        groups g
+      INNER JOIN group_roles group_role ON
+        group_role.group_id=g.id
+      UNION
+      -- Add Anyone group permission
+      SELECT
+        #{anyoneGroup} as name,
+        group_role.role as permission,
+        group_role.resource_id as componentId
+      FROM
+        group_roles group_role
+      where
+        group_role.group_id IS NULL
     ) groups
     where
       groups.componentId in
       <foreach collection="componentIds" open="(" close=")" item="id" separator=",">
         #{id,jdbcType=BIGINT}
       </foreach>
-    GROUP BY groups.permission, groups.componentId
+    GROUP BY
+      groups.permission,
+      groups.componentId
   </select>
 
   <select id="selectGroupNamesByQuery" parameterType="map" resultType="string">
index 9c7dfc4d288debb65e81379f815a796d34c4f2da..5310bad293d67abeb52ceb9e179a4dd457e28b25 100644 (file)
@@ -39,8 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 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;
-import static org.sonar.db.component.ComponentTesting.newProjectCopy;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
+import static org.sonar.db.component.ComponentTesting.newProjectCopy;
 import static org.sonar.db.component.ComponentTesting.newView;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
 import static org.sonar.test.JsonAssert.assertJson;
@@ -67,6 +67,58 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
     return new SearchProjectPermissionsAction(db.getDbClient(), userSession, i18n, rootResourceTypes, dataLoader, wsSupport);
   }
 
+  @Test
+  public void search_project_permissions_counts_0_users_and_0_groups_on_public_project_without_any_specified_permission_in_DB() {
+    ComponentDto project = db.components().insertPublicProject();
+
+    String result = newRequest().execute().getInput();
+
+    assertJson(result)
+      .ignoreFields("permissions")
+      .isSimilarTo("{" +
+        "  \"paging\": {" +
+        "    \"pageIndex\": 1," +
+        "    \"pageSize\": 25," +
+        "    \"total\": 1" +
+        "  }," +
+        "  \"projects\": [" +
+        "    {" +
+        "      \"id\": \"" + project.uuid() + "\"," +
+        "      \"key\": \"" + project.key() + "\"," +
+        "      \"name\": \"" + project.name() + "\"," +
+        "      \"qualifier\": \"TRK\"," +
+        "      \"permissions\": []" +
+        "    }" +
+        "  ]" +
+        "}");
+  }
+
+  @Test
+  public void search_project_permissions_counts_0_users_and_0_groups_on_private_project_without_any_specified_permission_in_DB() {
+    ComponentDto project = db.components().insertPrivateProject();
+
+    String result = newRequest().execute().getInput();
+
+    assertJson(result)
+      .ignoreFields("permissions")
+      .isSimilarTo("{" +
+        "  \"paging\": {" +
+        "    \"pageIndex\": 1," +
+        "    \"pageSize\": 25," +
+        "    \"total\": 1" +
+        "  }," +
+        "  \"projects\": [" +
+        "    {" +
+        "      \"id\": \"" + project.uuid() + "\"," +
+        "      \"key\": \"" + project.key() + "\"," +
+        "      \"name\": \"" + project.name() + "\"," +
+        "      \"qualifier\": \"TRK\"," +
+        "      \"permissions\": []" +
+        "    }" +
+        "  ]" +
+        "}");
+  }
+
   @Test
   public void search_project_permissions() throws Exception {
     UserDto user1 = db.users().insertUser();