use of org.sonarqube.ws.WsPermissions.Permission in project sonarqube by SonarSource.
the class SearchTemplatesAction method buildTemplatesResponse.
private static void buildTemplatesResponse(WsPermissions.SearchTemplatesWsResponse.Builder response, SearchTemplatesData data) {
Permission.Builder permissionResponse = Permission.newBuilder();
PermissionTemplate.Builder templateBuilder = PermissionTemplate.newBuilder();
for (PermissionTemplateDto templateDto : data.templates()) {
templateBuilder.clear().setId(templateDto.getUuid()).setName(templateDto.getName()).setCreatedAt(formatDateTime(templateDto.getCreatedAt())).setUpdatedAt(formatDateTime(templateDto.getUpdatedAt()));
setNullable(templateDto.getKeyPattern(), templateBuilder::setProjectKeyPattern);
setNullable(templateDto.getDescription(), templateBuilder::setDescription);
for (String permission : ProjectPermissions.ALL) {
templateBuilder.addPermissions(permissionResponse.clear().setKey(permission).setUsersCount(data.userCount(templateDto.getId(), permission)).setGroupsCount(data.groupCount(templateDto.getId(), permission)).setWithProjectCreator(data.withProjectCreator(templateDto.getId(), permission)));
}
response.addPermissionTemplates(templateBuilder);
}
}
use of org.sonarqube.ws.WsPermissions.Permission in project sonarqube by SonarSource.
the class SearchGlobalPermissionsAction method buildResponse.
private WsSearchGlobalPermissionsResponse buildResponse(DbSession dbSession, OrganizationDto org) {
WsSearchGlobalPermissionsResponse.Builder response = WsSearchGlobalPermissionsResponse.newBuilder();
Permission.Builder permission = newBuilder();
OrganizationPermission.all().map(OrganizationPermission::getKey).forEach(permissionKey -> {
PermissionQuery query = permissionQuery(permissionKey);
response.addPermissions(permission.clear().setKey(permissionKey).setName(i18nName(permissionKey)).setDescription(i18nDescriptionMessage(permissionKey)).setUsersCount(countUsers(dbSession, org, query)).setGroupsCount(countGroups(dbSession, org, permissionKey)));
});
return response.build();
}
use of org.sonarqube.ws.WsPermissions.Permission in project sonarqube by SonarSource.
the class SearchProjectPermissionsAction method buildResponse.
private SearchProjectPermissionsWsResponse buildResponse(SearchProjectPermissionsData data) {
SearchProjectPermissionsWsResponse.Builder response = SearchProjectPermissionsWsResponse.newBuilder();
Permission.Builder permissionResponse = Permission.newBuilder();
Project.Builder rootComponentBuilder = Project.newBuilder();
for (ComponentDto rootComponent : data.rootComponents()) {
rootComponentBuilder.clear().setId(rootComponent.uuid()).setKey(rootComponent.key()).setQualifier(rootComponent.qualifier()).setName(rootComponent.name());
for (String permission : data.permissions(rootComponent.getId())) {
rootComponentBuilder.addPermissions(permissionResponse.clear().setKey(permission).setUsersCount(data.userCount(rootComponent.getId(), permission)).setGroupsCount(data.groupCount(rootComponent.getId(), permission)));
}
response.addProjects(rootComponentBuilder);
}
for (String permissionKey : ProjectPermissions.ALL) {
response.addPermissions(permissionResponse.clear().setKey(permissionKey).setName(i18nName(permissionKey)).setDescription(i18nDescriptionMessage(permissionKey)));
}
Paging paging = data.paging();
response.setPaging(Common.Paging.newBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()).setTotal(paging.total()));
return response.build();
}
use of org.sonarqube.ws.WsPermissions.Permission in project sonarqube by SonarSource.
the class PermissionSearchTest method template_permission_web_services.
@Test
public void template_permission_web_services() {
WsPermissions.CreateTemplateWsResponse createTemplateWsResponse = permissionsWsClient.createTemplate(new CreateTemplateWsRequest().setName("my-new-template").setDescription("template-used-in-tests"));
assertThat(createTemplateWsResponse.getPermissionTemplate().getName()).isEqualTo("my-new-template");
permissionsWsClient.addUserToTemplate(new AddUserToTemplateWsRequest().setPermission("admin").setTemplateName("my-new-template").setLogin(LOGIN));
permissionsWsClient.addGroupToTemplate(new AddGroupToTemplateWsRequest().setPermission("admin").setTemplateName("my-new-template").setGroupName(GROUP_NAME));
permissionsWsClient.addProjectCreatorToTemplate(AddProjectCreatorToTemplateWsRequest.builder().setPermission("admin").setTemplateName("my-new-template").build());
SearchTemplatesWsResponse searchTemplatesWsResponse = permissionsWsClient.searchTemplates(new SearchTemplatesWsRequest().setQuery("my-new-template"));
assertThat(searchTemplatesWsResponse.getPermissionTemplates(0).getName()).isEqualTo("my-new-template");
assertThat(searchTemplatesWsResponse.getPermissionTemplates(0).getPermissions(0).getKey()).isEqualTo("admin");
assertThat(searchTemplatesWsResponse.getPermissionTemplates(0).getPermissions(0).getUsersCount()).isEqualTo(1);
assertThat(searchTemplatesWsResponse.getPermissionTemplates(0).getPermissions(0).getGroupsCount()).isEqualTo(1);
assertThat(searchTemplatesWsResponse.getPermissionTemplates(0).getPermissions(0).getWithProjectCreator()).isTrue();
permissionsWsClient.removeGroupFromTemplate(new RemoveGroupFromTemplateWsRequest().setPermission("admin").setTemplateName("my-new-template").setGroupName(GROUP_NAME));
permissionsWsClient.removeUserFromTemplate(new RemoveUserFromTemplateWsRequest().setPermission("admin").setTemplateName("my-new-template").setLogin(LOGIN));
permissionsWsClient.removeProjectCreatorFromTemplate(RemoveProjectCreatorFromTemplateWsRequest.builder().setPermission("admin").setTemplateName("my-new-template").build());
SearchTemplatesWsResponse clearedSearchTemplatesWsResponse = permissionsWsClient.searchTemplates(new SearchTemplatesWsRequest().setQuery("my-new-template"));
assertThat(clearedSearchTemplatesWsResponse.getPermissionTemplates(0).getPermissionsList()).extracting(Permission::getUsersCount, Permission::getGroupsCount, Permission::getWithProjectCreator).hasSize(5).containsOnly(tuple(0, 0, false));
}
Aggregations