use of org.sonarqube.ws.WsPermissions.WsGroupsResponse in project sonarqube by SonarSource.
the class TemplateGroupsActionTest method search_by_permission.
@Test
public void search_by_permission() throws Exception {
PermissionTemplateDto template = addTemplateToDefaultOrganization();
GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group1.getId()));
addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getId(), group1.getId()));
GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group-2-name");
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group2.getId()));
GroupDto group3 = db.users().insertGroup(db.getDefaultOrganization(), "group-3-name");
// Anyone
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getId(), group3.getId()));
commit();
loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_PERMISSION, USER).setParam(PARAM_TEMPLATE_ID, template.getUuid()).execute().getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone", "group-1-name");
assertThat(response.getGroups(0).getPermissionsList()).containsOnly("user");
assertThat(response.getGroups(1).getPermissionsList()).containsOnly("user", "codeviewer");
}
use of org.sonarqube.ws.WsPermissions.WsGroupsResponse in project sonarqube by SonarSource.
the class TemplateGroupsActionTest method search_with_pagination.
@Test
public void search_with_pagination() throws Exception {
OrganizationDto defaultOrg = db.getDefaultOrganization();
PermissionTemplateDto template = addTemplateToDefaultOrganization();
GroupDto group1 = db.users().insertGroup(defaultOrg, "group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group1.getId()));
GroupDto group2 = db.users().insertGroup(defaultOrg, "group-2-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group2.getId()));
commit();
loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_PERMISSION, USER).setParam(PARAM_TEMPLATE_NAME, template.getName()).setParam(PAGE, "2").setParam(PAGE_SIZE, "1").execute().getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("group-2-name");
}
use of org.sonarqube.ws.WsPermissions.WsGroupsResponse in project sonarqube by SonarSource.
the class TemplateGroupsActionTest method search_by_template_name.
@Test
public void search_by_template_name() throws Exception {
OrganizationDto defaultOrg = db.getDefaultOrganization();
GroupDto group1 = db.users().insertGroup(defaultOrg, "group-1-name");
GroupDto group2 = db.users().insertGroup(defaultOrg, "group-2-name");
GroupDto group3 = db.users().insertGroup(defaultOrg, "group-3-name");
PermissionTemplateDto template = addTemplateToDefaultOrganization();
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group1.getId()));
addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group2.getId()));
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getId(), group1.getId()));
commit();
loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_NAME, template.getName()).execute().getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone", "group-1-name", "group-2-name");
}
use of org.sonarqube.ws.WsPermissions.WsGroupsResponse in project sonarqube by SonarSource.
the class TemplateGroupsActionTest method search_with_text_query.
@Test
public void search_with_text_query() throws Exception {
OrganizationDto defaultOrg = db.getDefaultOrganization();
PermissionTemplateDto template = addTemplateToDefaultOrganization();
GroupDto group1 = db.users().insertGroup(defaultOrg, "group-1-name");
addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group1.getId()));
GroupDto group2 = db.users().insertGroup(defaultOrg, "group-2-name");
GroupDto group3 = db.users().insertGroup(defaultOrg, "group-3");
commit();
loginAsAdmin(db.getDefaultOrganization());
InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_NAME, template.getName()).setParam(TEXT_QUERY, "-nam").execute().getInputStream();
WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
assertThat(response.getGroupsList()).extracting("name").containsExactly("group-1-name", "group-2-name");
}
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