<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">
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;
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();