use of com.thoughtworks.go.config.security.Permissions in project gocd by gocd.
the class GoDashboardServiceTest method allPipelineGroupsForDashboard_shouldRetrievePipelineGroupsBasedOnUsersPipelineSelections.
@Test
public void allPipelineGroupsForDashboard_shouldRetrievePipelineGroupsBasedOnUsersPipelineSelections() throws Exception {
PipelineSelections pipelineSelections = mock(PipelineSelections.class);
configMother.addPipelineWithGroup(config, "group1", "pipeline1", "stage1A", "job1A1");
GoDashboardPipeline pipeline1 = pipeline("pipeline1", "group1", new Permissions(new AllowedUsers(Collections.singleton("user1"), Collections.emptySet()), NoOne.INSTANCE, NoOne.INSTANCE, NoOne.INSTANCE));
configMother.addPipelineWithGroup(config, "group2", "pipeline2", "stage1A", "job1A1");
GoDashboardPipeline pipeline2 = pipeline("pipeline2", "group2", new Permissions(NoOne.INSTANCE, NoOne.INSTANCE, NoOne.INSTANCE, NoOne.INSTANCE));
addPipelinesToCache(pipeline1, pipeline2);
when(pipelineSelections.includesPipeline(any(PipelineConfig.class))).thenReturn(true);
List<GoDashboardPipelineGroup> pipelineGroups = allPipelineGroupsForDashboard(pipelineSelections, new Username("user1"));
assertThat(pipelineGroups.size(), is(1));
assertThat(pipelineGroups.get(0).allPipelineNames(), contains("pipeline1"));
assertThat(pipelineGroups.get(0).allPipelines(), contains(pipeline1));
}
use of com.thoughtworks.go.config.security.Permissions in project gocd by gocd.
the class CcTrayConfigChangeHandler method findAllProjectStatusesForStagesAndJobsIn.
private List<ProjectStatus> findAllProjectStatusesForStagesAndJobsIn(CruiseConfig config) {
final List<ProjectStatus> projectStatuses = new ArrayList<>();
final Map<CaseInsensitiveString, Permissions> pipelinesAndTheirPermissions = pipelinePermissionsAuthority.pipelinesAndTheirPermissions();
config.accept(new PipelineGroupVisitor() {
@Override
public void visit(PipelineConfigs group) {
for (PipelineConfig pipelineConfig : group) {
Users usersWithViewPermissionsForPipeline = usersWithViewPermissionsFor(pipelineConfig, pipelinesAndTheirPermissions);
updateProjectStatusForPipeline(usersWithViewPermissionsForPipeline, pipelineConfig, projectStatuses);
}
}
});
return projectStatuses;
}
use of com.thoughtworks.go.config.security.Permissions in project gocd by gocd.
the class CcTrayConfigChangeHandler method call.
public void call(PipelineConfig pipelineConfig) {
ArrayList<ProjectStatus> projectStatuses = new ArrayList<>();
final Permissions permissions = pipelinePermissionsAuthority.permissionsForPipeline(pipelineConfig.name());
Users usersWithViewPermissionsOfThisPipeline = viewersOrNoOne(permissions);
updateProjectStatusForPipeline(usersWithViewPermissionsOfThisPipeline, pipelineConfig, projectStatuses);
cache.putAll(projectStatuses);
}
use of com.thoughtworks.go.config.security.Permissions in project gocd by gocd.
the class GoDashboardService method dashboardPipelineGroupFor.
private GoDashboardPipelineGroup dashboardPipelineGroupFor(PipelineConfigs pipelineGroup, DashboardFilter filter, Username user, GoDashboardPipelines allPipelines) {
Permissions groupPermissions = resolvePermissionsForPipelineGroup(pipelineGroup, allPipelines);
GoDashboardPipelineGroup goDashboardPipelineGroup = new GoDashboardPipelineGroup(pipelineGroup.getGroup(), groupPermissions, !pipelineGroup.isEmpty());
if (goDashboardPipelineGroup.hasPermissions() && goDashboardPipelineGroup.canBeViewedBy(user)) {
pipelineGroup.accept(pipelineConfig -> {
CaseInsensitiveString pipelineName = pipelineConfig.name();
GoDashboardPipeline pipeline = allPipelines.find(pipelineName);
if (pipeline != null && filter.isPipelineVisible(pipelineName)) {
goDashboardPipelineGroup.addPipeline(pipeline);
}
});
}
return goDashboardPipelineGroup;
}
use of com.thoughtworks.go.config.security.Permissions in project gocd by gocd.
the class GoDashboardCurrentStateLoader method allPipelines.
public List<GoDashboardPipeline> allPipelines(CruiseConfig config) {
List<CaseInsensitiveString> allPipelineNames = config.getAllPipelineNames();
HashSet<CaseInsensitiveString> currentPipelineNames = new HashSet<>(allPipelineNames);
Collection<CaseInsensitiveString> pipelinesToRemove = Sets.difference(lastKnownPipelineNames, currentPipelineNames);
Collection<CaseInsensitiveString> pipelinesToAdd = Sets.difference(currentPipelineNames, lastKnownPipelineNames);
if (!pipelinesToAdd.isEmpty()) {
historyForDashboard.addAll(loadHistoryForPipelines(new ArrayList<>(CaseInsensitiveString.toStringList(pipelinesToAdd))));
}
for (CaseInsensitiveString pipelineNameToRemove : new ArrayList<>(pipelinesToRemove)) {
clearEntryFor(pipelineNameToRemove);
}
lastKnownPipelineNames = currentPipelineNames;
LOGGER.debug("Loading permissions from authority");
final Map<CaseInsensitiveString, Permissions> pipelinesAndTheirPermissions = permissionsAuthority.pipelinesAndTheirPermissions();
final List<GoDashboardPipeline> pipelines = new ArrayList<>(1024);
LOGGER.debug("Populating dashboard pipelines");
config.accept((PipelineGroupVisitor) group -> group.accept(pipelineConfig -> {
long start = System.currentTimeMillis();
Permissions permissions = permissionsFor(pipelineConfig, pipelinesAndTheirPermissions);
pipelines.add(createGoDashboardPipeline(pipelineConfig, permissions, historyForDashboard, group));
LOGGER.debug("It took {}ms to process pipeline {}", (System.currentTimeMillis() - start), pipelineConfig.getName());
}));
LOGGER.debug("Done populating dashboard pipelines");
this.everLoadedCurrentState = true;
return pipelines;
}
Aggregations