Search in sources :

Example 1 with EnvironmentPipelineModel

use of com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel in project gocd by gocd.

the class EnvironmentConfigServiceTest method getAllLocalPipelinesForUser_shouldReturnOnlyLocalPipelines.

@Test
public void getAllLocalPipelinesForUser_shouldReturnOnlyLocalPipelines() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    Username user = new Username(new CaseInsensitiveString("user"));
    when(mockGoConfigService.getAllLocalPipelineConfigs()).thenReturn(asList(pipelineConfig("foo"), pipelineConfig("bar"), pipelineConfig("baz")));
    when(securityService.hasViewPermissionForPipeline(user, "foo")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "bar")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "baz")).thenReturn(false);
    environmentConfigService.sync(environmentsConfig("foo-env", "foo"));
    List<EnvironmentPipelineModel> pipelines = environmentConfigService.getAllLocalPipelinesForUser(user);
    assertThat(pipelines.size(), is(2));
    assertThat(pipelines, is(asList(new EnvironmentPipelineModel("bar"), new EnvironmentPipelineModel("foo", "foo-env"))));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) EnvironmentPipelineModel(com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel) Test(org.junit.Test)

Example 2 with EnvironmentPipelineModel

use of com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel in project gocd by gocd.

the class EnvironmentConfigServiceTest method getAllRemotePipelinesForUserInEnvironment_shouldReturnOnlyRemotelyAssignedPipelinesWhichUserHasPermsToView.

@Test
public void getAllRemotePipelinesForUserInEnvironment_shouldReturnOnlyRemotelyAssignedPipelinesWhichUserHasPermsToView() throws NoSuchEnvironmentException {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    Username user = new Username(new CaseInsensitiveString("user"));
    when(mockGoConfigService.getAllPipelineConfigs()).thenReturn(asList(pipelineConfig("foo"), pipelineConfig("bar"), pipelineConfig("baz")));
    when(securityService.hasViewPermissionForPipeline(user, "foo")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "bar")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "baz")).thenReturn(false);
    EnvironmentsConfig environmentConfigs = environmentsConfig("foo-env", "foo");
    EnvironmentConfig fooEnv = environmentConfigs.named(new CaseInsensitiveString("foo-env"));
    fooEnv.setOrigins(new RepoConfigOrigin());
    environmentConfigService.sync(environmentConfigs);
    List<EnvironmentPipelineModel> pipelines = environmentConfigService.getAllRemotePipelinesForUserInEnvironment(user, fooEnv);
    assertThat(pipelines.size(), is(1));
    assertThat(pipelines, is(asList(new EnvironmentPipelineModel("foo", "foo-env"))));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) EnvironmentPipelineModel(com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.Test)

Example 3 with EnvironmentPipelineModel

use of com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel in project gocd by gocd.

the class EnvironmentConfigServiceTest method getAllLocalPipelinesForUser_shouldReturnAllPipelinesToWhichAlongWithTheEnvironmentsToWhichTheyBelong.

@Test
public void getAllLocalPipelinesForUser_shouldReturnAllPipelinesToWhichAlongWithTheEnvironmentsToWhichTheyBelong() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    Username user = new Username(new CaseInsensitiveString("user"));
    when(mockGoConfigService.getAllLocalPipelineConfigs()).thenReturn(asList(pipelineConfig("foo"), pipelineConfig("bar"), pipelineConfig("baz")));
    when(securityService.hasViewPermissionForPipeline(user, "foo")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "bar")).thenReturn(true);
    when(securityService.hasViewPermissionForPipeline(user, "baz")).thenReturn(false);
    environmentConfigService.sync(environmentsConfig("foo-env", "foo"));
    List<EnvironmentPipelineModel> pipelines = environmentConfigService.getAllLocalPipelinesForUser(user);
    assertThat(pipelines.size(), is(2));
    assertThat(pipelines, is(asList(new EnvironmentPipelineModel("bar"), new EnvironmentPipelineModel("foo", "foo-env"))));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) EnvironmentPipelineModel(com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel) Test(org.junit.Test)

Example 4 with EnvironmentPipelineModel

use of com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel in project gocd by gocd.

the class EnvironmentConfigService method getAllRemotePipelinesForUserInEnvironment.

public List<EnvironmentPipelineModel> getAllRemotePipelinesForUserInEnvironment(Username user, EnvironmentConfig environment) {
    List<EnvironmentPipelineModel> pipelines = new ArrayList<>();
    for (EnvironmentPipelineConfig pipelineConfig : environment.getRemotePipelines()) {
        String pipelineName = CaseInsensitiveString.str(pipelineConfig.getName());
        if (securityService.hasViewPermissionForPipeline(user, pipelineName)) {
            pipelines.add(new EnvironmentPipelineModel(pipelineName, CaseInsensitiveString.str(environment.name())));
        }
    }
    Collections.sort(pipelines);
    return pipelines;
}
Also used : EnvironmentPipelineModel(com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel)

Example 5 with EnvironmentPipelineModel

use of com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel in project gocd by gocd.

the class EnvironmentConfigService method getAllPipelinesForUser.

private List<EnvironmentPipelineModel> getAllPipelinesForUser(Username user, List<PipelineConfig> pipelineConfigs) {
    List<EnvironmentPipelineModel> pipelines = new ArrayList<>();
    for (PipelineConfig pipelineConfig : pipelineConfigs) {
        String pipelineName = CaseInsensitiveString.str(pipelineConfig.name());
        if (securityService.hasViewPermissionForPipeline(user, pipelineName)) {
            EnvironmentConfig environment = environments.findEnvironmentForPipeline(new CaseInsensitiveString(pipelineName));
            if (environment != null) {
                pipelines.add(new EnvironmentPipelineModel(pipelineName, CaseInsensitiveString.str(environment.name())));
            } else {
                pipelines.add(new EnvironmentPipelineModel(pipelineName));
            }
        }
    }
    Collections.sort(pipelines);
    return pipelines;
}
Also used : EnvironmentPipelineModel(com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel)

Aggregations

EnvironmentPipelineModel (com.thoughtworks.go.presentation.environment.EnvironmentPipelineModel)5 Username (com.thoughtworks.go.server.domain.Username)3 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)3 Test (org.junit.Test)3 MergeEnvironmentConfig (com.thoughtworks.go.config.merge.MergeEnvironmentConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1