use of jetbrains.buildServer.server.graphql.model.filter.ProjectsFilter 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());
}
use of jetbrains.buildServer.server.graphql.model.filter.ProjectsFilter 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());
}
Aggregations