Search in sources :

Example 1 with AgentPoolProjectsConnection

use of jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection in project teamcity-rest by JetBrains.

the class AbstractAgentPoolResolver method projects.

@NotNull
public AgentPoolProjectsConnection projects(@NotNull AbstractAgentPool pool, @NotNull ProjectsFilter filter, @NotNull DataFetchingEnvironment env) {
    jetbrains.buildServer.serverSide.agentPools.AgentPool realPool = pool.getRealPool();
    Collection<String> projectIds = realPool.getProjectIds();
    Stream<SProject> projects = myProjectManager.findProjects(projectIds).stream();
    if (filter.getArchived() != null) {
        projects = projects.filter(p -> p.isArchived() == filter.getArchived());
    }
    Integer excludedProjectsCount = null;
    if (env.getSelectionSet().contains("excludedCount")) {
        AuthorityHolder authHolder = mySecurityContext.getAuthorityHolder();
        excludedProjectsCount = (int) projectIds.stream().filter(projectId -> !authHolder.isPermissionGrantedForProject(projectId, Permission.VIEW_PROJECT)).count();
    }
    return new AgentPoolProjectsConnection(projects.collect(Collectors.toList()), excludedProjectsCount, PaginationArguments.everything());
}
Also used : AgentPool(jetbrains.buildServer.serverSide.agentPools.AgentPool) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) CloudClientEx(jetbrains.buildServer.clouds.CloudClientEx) AbstractAgentPool(jetbrains.buildServer.server.graphql.model.agentPool.AbstractAgentPool) CloudProfile(jetbrains.buildServer.clouds.CloudProfile) AuthorityHolder(jetbrains.buildServer.serverSide.auth.AuthorityHolder) AgentPoolProjectsConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection) PaginationArguments(jetbrains.buildServer.server.graphql.model.connections.PaginationArguments) ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) AgentPool(jetbrains.buildServer.serverSide.agentPools.AgentPool) CloudImage(jetbrains.buildServer.clouds.CloudImage) SAgentType(jetbrains.buildServer.serverSide.agentTypes.SAgentType) AgentTypeKey(jetbrains.buildServer.serverSide.agentTypes.AgentTypeKey) AgentPoolAgentsConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolAgentsConnection) AgentTypeFinder(jetbrains.buildServer.serverSide.agentTypes.AgentTypeFinder) CloudManager(jetbrains.buildServer.clouds.server.CloudManager) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) Collection(java.util.Collection) AgentPoolPermissions(jetbrains.buildServer.server.graphql.model.agentPool.AgentPoolPermissions) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) ProjectsFilter(jetbrains.buildServer.server.graphql.model.filter.ProjectsFilter) Permission(jetbrains.buildServer.serverSide.auth.Permission) AgentPoolCloudImagesConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolCloudImagesConnection) Pair(com.intellij.openapi.util.Pair) AuthUtil(jetbrains.buildServer.serverSide.auth.AuthUtil) NotNull(org.jetbrains.annotations.NotNull) AgentPoolProjectsConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection) AuthorityHolder(jetbrains.buildServer.serverSide.auth.AuthorityHolder) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with AgentPoolProjectsConnection

use of jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection in project teamcity-rest by JetBrains.

the class AbstractAgentPoolResolverTest method basicProjectsConnection.

public void basicProjectsConnection() throws Throwable {
    jetbrains.buildServer.serverSide.agentPools.AgentPool realPool = myFixture.getAgentPoolManager().createNewAgentPool("testAgentPool");
    Set<String> allProjectIds = new HashSet<>();
    Set<String> visibleProjectNames = new HashSet<>();
    MockAuthorityHolder mockUser = new MockAuthorityHolder();
    Permissions viewProjectPermissions = new Permissions(Permission.VIEW_PROJECT);
    for (int i = 0; i < 5; i++) {
        ProjectEx project = createProject("visibleProject" + i);
        mockUser.projectPerms.put(project.getProjectId(), viewProjectPermissions);
        allProjectIds.add(project.getProjectId());
        visibleProjectNames.add(project.getName());
    }
    List<ProjectEx> invisibleProjects = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        ProjectEx project = createProject("invisibleProject" + i);
        allProjectIds.add(project.getProjectId());
        invisibleProjects.add(project);
    }
    myFixture.getAgentPoolManager().associateProjectsWithPool(realPool.getAgentPoolId(), allProjectIds);
    Mock fieldSelectionSetMock = mock(DataFetchingFieldSelectionSet.class);
    fieldSelectionSetMock.stubs().method("contains").with(eq("excludedCount")).will(returnValue(true));
    myDataFetchingEnvironment.setSelectionSet((DataFetchingFieldSelectionSet) fieldSelectionSetMock.proxy());
    AgentPoolProjectsConnection connection = myFixture.getSecurityContext().runAs(mockUser, () -> myResolver.projects(new AgentPool(realPool), new ProjectsFilter(), myDataFetchingEnvironment));
    connection.getEdges().getData().forEach(edge -> {
        String name = edge.getNode().getData().getName();
        assertTrue("Project '" + name + "' is visible, but shouldn't be.", visibleProjectNames.contains(name));
    });
    assertEquals(visibleProjectNames.size(), connection.getCount());
    assertEquals(new Integer(invisibleProjects.size()), connection.getExcludedCount());
}
Also used : ProjectsFilter(jetbrains.buildServer.server.graphql.model.filter.ProjectsFilter) AgentPoolProjectsConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection) AgentPool(jetbrains.buildServer.server.graphql.model.agentPool.AgentPool) Mock(org.jmock.Mock) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Permissions(jetbrains.buildServer.serverSide.auth.Permissions) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) MockAuthorityHolder(jetbrains.buildServer.serverSide.impl.MockAuthorityHolder)

Aggregations

AgentPoolProjectsConnection (jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection)2 ProjectsFilter (jetbrains.buildServer.server.graphql.model.filter.ProjectsFilter)2 Pair (com.intellij.openapi.util.Pair)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 BooleanSupplier (java.util.function.BooleanSupplier)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 CloudClientEx (jetbrains.buildServer.clouds.CloudClientEx)1 CloudImage (jetbrains.buildServer.clouds.CloudImage)1 CloudProfile (jetbrains.buildServer.clouds.CloudProfile)1 CloudManager (jetbrains.buildServer.clouds.server.CloudManager)1 AbstractAgentPool (jetbrains.buildServer.server.graphql.model.agentPool.AbstractAgentPool)1 AgentPool (jetbrains.buildServer.server.graphql.model.agentPool.AgentPool)1 AgentPoolPermissions (jetbrains.buildServer.server.graphql.model.agentPool.AgentPoolPermissions)1 PaginationArguments (jetbrains.buildServer.server.graphql.model.connections.PaginationArguments)1 AgentPoolAgentsConnection (jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolAgentsConnection)1 AgentPoolCloudImagesConnection (jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolCloudImagesConnection)1