Search in sources :

Example 1 with Permissions

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));
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) Username(com.thoughtworks.go.server.domain.Username) AllowedUsers(com.thoughtworks.go.config.security.users.AllowedUsers) Permissions(com.thoughtworks.go.config.security.Permissions) Test(org.junit.Test)

Example 2 with Permissions

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;
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) ArrayList(java.util.ArrayList) Permissions(com.thoughtworks.go.config.security.Permissions) Users(com.thoughtworks.go.config.security.users.Users) PipelineGroupVisitor(com.thoughtworks.go.domain.PipelineGroupVisitor)

Example 3 with Permissions

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);
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) ArrayList(java.util.ArrayList) Permissions(com.thoughtworks.go.config.security.Permissions) Users(com.thoughtworks.go.config.security.users.Users)

Example 4 with Permissions

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;
}
Also used : Permissions(com.thoughtworks.go.config.security.Permissions)

Example 5 with Permissions

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;
}
Also used : java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) PipelineModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineModel) Autowired(org.springframework.beans.factory.annotation.Autowired) NoOnePermission(com.thoughtworks.go.config.security.permissions.NoOnePermission) SchedulingCheckerService(com.thoughtworks.go.server.service.SchedulingCheckerService) PipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels) PipelineUnlockApiService(com.thoughtworks.go.server.service.PipelineUnlockApiService) PipelineInstanceModel.createPreparingToSchedule(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel.createPreparingToSchedule) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) PipelineInstanceModel.createEmptyPipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel.createEmptyPipelineInstanceModel) PipelinePauseService(com.thoughtworks.go.server.service.PipelinePauseService) PipelineDao(com.thoughtworks.go.server.dao.PipelineDao) PipelineInstanceModels.createPipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels) PipelineLockService(com.thoughtworks.go.server.service.PipelineLockService) Logger(org.slf4j.Logger) PipelinePauseInfo(com.thoughtworks.go.domain.PipelinePauseInfo) com.thoughtworks.go.config(com.thoughtworks.go.config) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) TriggerMonitor(com.thoughtworks.go.server.scheduling.TriggerMonitor) Sets(com.google.common.collect.Sets) GoConfigPipelinePermissionsAuthority(com.thoughtworks.go.config.security.GoConfigPipelinePermissionsAuthority) Permissions(com.thoughtworks.go.config.security.Permissions) Component(org.springframework.stereotype.Component) CaseInsensitiveString.str(com.thoughtworks.go.config.CaseInsensitiveString.str) BuildCause.createWithEmptyModifications(com.thoughtworks.go.domain.buildcause.BuildCause.createWithEmptyModifications) PipelineGroupVisitor(com.thoughtworks.go.domain.PipelineGroupVisitor) NoOne(com.thoughtworks.go.config.security.users.NoOne) Permissions(com.thoughtworks.go.config.security.Permissions)

Aggregations

Permissions (com.thoughtworks.go.config.security.Permissions)22 Test (org.junit.jupiter.api.Test)16 AllowedUsers (com.thoughtworks.go.config.security.users.AllowedUsers)9 Username (com.thoughtworks.go.server.domain.Username)8 PipelineModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineModel)5 ProjectStatus (com.thoughtworks.go.domain.activity.ProjectStatus)4 PipelineInstanceModels.createPipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels)3 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)2 Users (com.thoughtworks.go.config.security.users.Users)2 PipelineGroupVisitor (com.thoughtworks.go.domain.PipelineGroupVisitor)2 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)2 ArrayList (java.util.ArrayList)2 Sets (com.google.common.collect.Sets)1 com.thoughtworks.go.config (com.thoughtworks.go.config)1 CaseInsensitiveString.str (com.thoughtworks.go.config.CaseInsensitiveString.str)1 GoConfigPipelinePermissionsAuthority (com.thoughtworks.go.config.security.GoConfigPipelinePermissionsAuthority)1 NoOnePermission (com.thoughtworks.go.config.security.permissions.NoOnePermission)1 NoOne (com.thoughtworks.go.config.security.users.NoOne)1 PipelinePauseInfo (com.thoughtworks.go.domain.PipelinePauseInfo)1 BuildCause.createWithEmptyModifications (com.thoughtworks.go.domain.buildcause.BuildCause.createWithEmptyModifications)1