Search in sources :

Example 1 with Permission

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);
    }
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) PermissionTemplate(org.sonarqube.ws.WsPermissions.PermissionTemplate) Permission(org.sonarqube.ws.WsPermissions.Permission)

Example 2 with Permission

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();
}
Also used : WsSearchGlobalPermissionsResponse(org.sonarqube.ws.WsPermissions.WsSearchGlobalPermissionsResponse) OrganizationPermission(org.sonar.db.permission.OrganizationPermission) Permission(org.sonarqube.ws.WsPermissions.Permission) PermissionQuery(org.sonar.db.permission.PermissionQuery)

Example 3 with Permission

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();
}
Also used : Project(org.sonarqube.ws.WsPermissions.SearchProjectPermissionsWsResponse.Project) SearchProjectPermissionsWsResponse(org.sonarqube.ws.WsPermissions.SearchProjectPermissionsWsResponse) Paging(org.sonar.api.utils.Paging) Permission(org.sonarqube.ws.WsPermissions.Permission) ComponentDto(org.sonar.db.component.ComponentDto)

Example 4 with Permission

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));
}
Also used : SearchTemplatesWsResponse(org.sonarqube.ws.WsPermissions.SearchTemplatesWsResponse) AddGroupToTemplateWsRequest(org.sonarqube.ws.client.permission.AddGroupToTemplateWsRequest) SearchTemplatesWsRequest(org.sonarqube.ws.client.permission.SearchTemplatesWsRequest) AddUserToTemplateWsRequest(org.sonarqube.ws.client.permission.AddUserToTemplateWsRequest) CreateTemplateWsRequest(org.sonarqube.ws.client.permission.CreateTemplateWsRequest) Permission(org.sonarqube.ws.WsPermissions.Permission) WsPermissions(org.sonarqube.ws.WsPermissions) RemoveGroupFromTemplateWsRequest(org.sonarqube.ws.client.permission.RemoveGroupFromTemplateWsRequest) RemoveUserFromTemplateWsRequest(org.sonarqube.ws.client.permission.RemoveUserFromTemplateWsRequest) Test(org.junit.Test)

Aggregations

Permission (org.sonarqube.ws.WsPermissions.Permission)4 Test (org.junit.Test)1 Paging (org.sonar.api.utils.Paging)1 ComponentDto (org.sonar.db.component.ComponentDto)1 OrganizationPermission (org.sonar.db.permission.OrganizationPermission)1 PermissionQuery (org.sonar.db.permission.PermissionQuery)1 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)1 WsPermissions (org.sonarqube.ws.WsPermissions)1 PermissionTemplate (org.sonarqube.ws.WsPermissions.PermissionTemplate)1 SearchProjectPermissionsWsResponse (org.sonarqube.ws.WsPermissions.SearchProjectPermissionsWsResponse)1 Project (org.sonarqube.ws.WsPermissions.SearchProjectPermissionsWsResponse.Project)1 SearchTemplatesWsResponse (org.sonarqube.ws.WsPermissions.SearchTemplatesWsResponse)1 WsSearchGlobalPermissionsResponse (org.sonarqube.ws.WsPermissions.WsSearchGlobalPermissionsResponse)1 AddGroupToTemplateWsRequest (org.sonarqube.ws.client.permission.AddGroupToTemplateWsRequest)1 AddUserToTemplateWsRequest (org.sonarqube.ws.client.permission.AddUserToTemplateWsRequest)1 CreateTemplateWsRequest (org.sonarqube.ws.client.permission.CreateTemplateWsRequest)1 RemoveGroupFromTemplateWsRequest (org.sonarqube.ws.client.permission.RemoveGroupFromTemplateWsRequest)1 RemoveUserFromTemplateWsRequest (org.sonarqube.ws.client.permission.RemoveUserFromTemplateWsRequest)1 SearchTemplatesWsRequest (org.sonarqube.ws.client.permission.SearchTemplatesWsRequest)1