use of org.sonarqube.ws.WsPermissions.WsGroupsResponse in project sonarqube by SonarSource.
the class TemplateGroupsActionTest method search_with_text_query_return_all_groups_even_when_no_permission_set.
@Test
public void search_with_text_query_return_all_groups_even_when_no_permission_set() throws Exception {
OrganizationDto defaultOrg = db.getDefaultOrganization();
PermissionTemplateDto template = addTemplateToDefaultOrganization();
db.users().insertGroup(defaultOrg, "group-1-name");
db.users().insertGroup(defaultOrg, "group-2-name");
db.users().insertGroup(defaultOrg, "group-3-name");
commit();
loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_ID, template.getUuid()).setParam(TEXT_QUERY, "-name").execute().getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("group-1-name", "group-2-name", "group-3-name");
assertThat(response.getGroups(0).getPermissionsList()).isEmpty();
assertThat(response.getGroups(1).getPermissionsList()).isEmpty();
assertThat(response.getGroups(2).getPermissionsList()).isEmpty();
}
use of org.sonarqube.ws.WsPermissions.WsGroupsResponse in project sonarqube by SonarSource.
the class TemplateGroupsActionTest method return_all_permissions_of_matching_groups.
@Test
public void return_all_permissions_of_matching_groups() throws Exception {
PermissionTemplateDto template = addTemplateToDefaultOrganization();
GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getId(), group1.getId()));
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group1.getId()));
GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group-2-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group2.getId()));
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group2.getId()));
GroupDto group3 = db.users().insertGroup(db.getDefaultOrganization(), "group-3-name");
// Anyone
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getId(), null));
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getId(), group3.getId()));
commit();
loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_ID, template.getUuid()).execute().getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone", "group-1-name", "group-2-name");
assertThat(response.getGroups(0).getPermissionsList()).containsOnly("user", "issueadmin");
assertThat(response.getGroups(1).getPermissionsList()).containsOnly("codeviewer", "admin");
assertThat(response.getGroups(2).getPermissionsList()).containsOnly("user", "admin");
}
use of org.sonarqube.ws.WsPermissions.WsGroupsResponse in project sonarqube by SonarSource.
the class GroupsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto org = support.findOrganization(dbSession, request.param(PARAM_ORGANIZATION));
Optional<ProjectId> projectId = support.findProjectId(dbSession, request);
checkProjectAdmin(userSession, org.getUuid(), projectId);
PermissionQuery query = buildPermissionQuery(request, projectId);
// TODO validatePermission(groupsRequest.getPermission(), wsProjectRef);
List<GroupDto> groups = findGroups(dbSession, org, query);
int total = dbClient.groupPermissionDao().countGroupsByQuery(dbSession, org.getUuid(), query);
List<GroupPermissionDto> groupsWithPermission = findGroupPermissions(dbSession, org, groups, projectId);
Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total);
WsGroupsResponse groupsResponse = buildResponse(groups, groupsWithPermission, paging);
writeProtobuf(groupsResponse, request, response);
}
}
Aggregations