Search in sources :

Example 21 with Permissions

use of com.thoughtworks.go.config.security.Permissions in project gocd by gocd.

the class GoDashboardCurrentStateLoader method pipelineFor.

public GoDashboardPipeline pipelineFor(PipelineConfig pipelineConfig, PipelineConfigs groupConfig) {
    List<String> pipelineNames = CaseInsensitiveString.toStringList(Collections.singletonList(pipelineConfig.getName()));
    PipelineInstanceModels pipelineHistoryForDashboard = loadHistoryForPipelines(pipelineNames);
    syncHistoryForDashboard(pipelineHistoryForDashboard, pipelineConfig.name());
    Permissions permissions = permissionsAuthority.permissionsForPipeline(pipelineConfig.name());
    return createGoDashboardPipeline(pipelineConfig, permissions, pipelineHistoryForDashboard, groupConfig);
}
Also used : PipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels) PipelineInstanceModels.createPipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels) Permissions(com.thoughtworks.go.config.security.Permissions)

Example 22 with Permissions

use of com.thoughtworks.go.config.security.Permissions in project gocd by gocd.

the class CcTrayConfigChangeHandlerTest method shouldUpdateViewPermissionsForEveryProjectBasedOnViewPermissionsOfTheGroup.

@Test
public void shouldUpdateViewPermissionsForEveryProjectBasedOnViewPermissionsOfTheGroup() throws Exception {
    PluginRoleConfig admin = new PluginRoleConfig("admin", "ldap");
    pluginRoleUsersStore.assignRole("user4", admin);
    Permissions pipeline1Permissions = new Permissions(viewers("user1", "user2"), NoOne.INSTANCE, NoOne.INSTANCE, NoOnePermission.INSTANCE);
    Permissions pipeline2Permissions = new Permissions(new AllowedUsers(s("user3"), Collections.singleton(admin)), NoOne.INSTANCE, NoOne.INSTANCE, NoOnePermission.INSTANCE);
    when(pipelinePermissionsAuthority.pipelinesAndTheirPermissions()).thenReturn(m(new CaseInsensitiveString("pipeline1"), pipeline1Permissions, new CaseInsensitiveString("pipeline2"), pipeline2Permissions));
    CruiseConfig config = GoConfigMother.defaultCruiseConfig();
    goConfigMother.addPipelineWithGroup(config, "group2", "pipeline2", "stage2", "job2");
    goConfigMother.addPipelineWithGroup(config, "group1", "pipeline1", "stage1", "job1");
    handler.call(config);
    verify(cache).replaceAllEntriesInCacheWith(statusesCaptor.capture());
    List<ProjectStatus> statuses = statusesCaptor.getValue();
    assertThat(statuses.size(), is(4));
    assertThat(statuses.get(0).name(), is("pipeline1 :: stage1"));
    assertThat(statuses.get(0).canBeViewedBy("user1"), is(true));
    assertThat(statuses.get(0).canBeViewedBy("user2"), is(true));
    assertThat(statuses.get(0).canBeViewedBy("user3"), is(false));
    assertThat(statuses.get(0).canBeViewedBy("user4"), is(false));
    assertThat(statuses.get(1).name(), is("pipeline1 :: stage1 :: job1"));
    assertThat(statuses.get(1).canBeViewedBy("user1"), is(true));
    assertThat(statuses.get(1).canBeViewedBy("user2"), is(true));
    assertThat(statuses.get(1).canBeViewedBy("user3"), is(false));
    assertThat(statuses.get(1).canBeViewedBy("user4"), is(false));
    assertThat(statuses.get(2).name(), is("pipeline2 :: stage2"));
    assertThat(statuses.get(2).canBeViewedBy("user1"), is(false));
    assertThat(statuses.get(2).canBeViewedBy("user2"), is(false));
    assertThat(statuses.get(2).canBeViewedBy("user3"), is(true));
    assertThat(statuses.get(2).canBeViewedBy("user4"), is(true));
    assertThat(statuses.get(3).name(), is("pipeline2 :: stage2 :: job2"));
    assertThat(statuses.get(3).canBeViewedBy("user1"), is(false));
    assertThat(statuses.get(3).canBeViewedBy("user2"), is(false));
    assertThat(statuses.get(3).canBeViewedBy("user3"), is(true));
    assertThat(statuses.get(3).canBeViewedBy("user4"), is(true));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) AllowedUsers(com.thoughtworks.go.config.security.users.AllowedUsers) Permissions(com.thoughtworks.go.config.security.Permissions) Test(org.junit.jupiter.api.Test)

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