Search in sources :

Example 1 with SearchTemplatesWsRequest

use of org.sonarqube.ws.client.permission.SearchTemplatesWsRequest in project sonarqube by SonarSource.

the class FavoriteTest method addProjectCreatorPermission.

private void addProjectCreatorPermission() {
    WsPermissions.SearchTemplatesWsResponse permissionTemplates = adminWsClient.permissions().searchTemplates(new SearchTemplatesWsRequest());
    assertThat(permissionTemplates.getDefaultTemplatesCount()).isEqualTo(1);
    adminWsClient.permissions().addProjectCreatorToTemplate(AddProjectCreatorToTemplateWsRequest.builder().setTemplateId(permissionTemplates.getDefaultTemplates(0).getTemplateId()).setPermission("admin").build());
}
Also used : SearchTemplatesWsRequest(org.sonarqube.ws.client.permission.SearchTemplatesWsRequest) WsPermissions(org.sonarqube.ws.WsPermissions)

Example 2 with SearchTemplatesWsRequest

use of org.sonarqube.ws.client.permission.SearchTemplatesWsRequest in project sonarqube by SonarSource.

the class FavoriteTest method removeProjectCreatorPermission.

private void removeProjectCreatorPermission() {
    WsPermissions.SearchTemplatesWsResponse permissionTemplates = adminWsClient.permissions().searchTemplates(new SearchTemplatesWsRequest());
    assertThat(permissionTemplates.getDefaultTemplatesCount()).isEqualTo(1);
    adminWsClient.permissions().removeProjectCreatorFromTemplate(RemoveProjectCreatorFromTemplateWsRequest.builder().setTemplateId(permissionTemplates.getDefaultTemplates(0).getTemplateId()).setPermission("admin").build());
}
Also used : SearchTemplatesWsRequest(org.sonarqube.ws.client.permission.SearchTemplatesWsRequest) WsPermissions(org.sonarqube.ws.WsPermissions)

Example 3 with SearchTemplatesWsRequest

use of org.sonarqube.ws.client.permission.SearchTemplatesWsRequest 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)

Example 4 with SearchTemplatesWsRequest

use of org.sonarqube.ws.client.permission.SearchTemplatesWsRequest in project sonarqube by SonarSource.

the class SearchTemplatesAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        OrganizationDto org = support.findOrganization(dbSession, wsRequest.param(PARAM_ORGANIZATION));
        SearchTemplatesWsRequest request = new SearchTemplatesWsRequest().setOrganizationUuid(org.getUuid()).setQuery(wsRequest.param(Param.TEXT_QUERY));
        checkGlobalAdmin(userSession, request.getOrganizationUuid());
        SearchTemplatesWsResponse searchTemplatesWsResponse = buildResponse(dataLoader.load(dbSession, request));
        writeProtobuf(searchTemplatesWsResponse, wsRequest, wsResponse);
    }
}
Also used : DbSession(org.sonar.db.DbSession) SearchTemplatesWsResponse(org.sonarqube.ws.WsPermissions.SearchTemplatesWsResponse) SearchTemplatesWsRequest(org.sonarqube.ws.client.permission.SearchTemplatesWsRequest) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Aggregations

SearchTemplatesWsRequest (org.sonarqube.ws.client.permission.SearchTemplatesWsRequest)4 WsPermissions (org.sonarqube.ws.WsPermissions)3 SearchTemplatesWsResponse (org.sonarqube.ws.WsPermissions.SearchTemplatesWsResponse)2 Test (org.junit.Test)1 DbSession (org.sonar.db.DbSession)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 Permission (org.sonarqube.ws.WsPermissions.Permission)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