Search in sources :

Example 1 with AllowedViewers

use of com.thoughtworks.go.domain.cctray.viewers.AllowedViewers in project gocd by gocd.

the class CcTrayJobStatusChangeHandlerTest method shouldReuseViewersListFromExistingStatusWhenCreatingNewStatus.

@Test
public void shouldReuseViewersListFromExistingStatusWhenCreatingNewStatus() throws Exception {
    Viewers viewers = new AllowedViewers(s("viewer1", "viewer2"));
    ProjectStatus oldStatusInCache = new ProjectStatus(projectNameFor("job1"), "OldActivity", "OldStatus", "OldLabel", new Date(), webUrlFor("job1"));
    oldStatusInCache.updateViewers(viewers);
    when(cache.get(projectNameFor("job1"))).thenReturn(oldStatusInCache);
    CcTrayJobStatusChangeHandler handler = new CcTrayJobStatusChangeHandler(cache);
    ProjectStatus newStatus = handler.statusFor(JobInstanceMother.building("job1"), new HashSet<>());
    assertThat(newStatus.viewers(), is(viewers));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) AllowedViewers(com.thoughtworks.go.domain.cctray.viewers.AllowedViewers) Viewers(com.thoughtworks.go.domain.cctray.viewers.Viewers) Date(java.util.Date) AllowedViewers(com.thoughtworks.go.domain.cctray.viewers.AllowedViewers) Test(org.junit.Test)

Example 2 with AllowedViewers

use of com.thoughtworks.go.domain.cctray.viewers.AllowedViewers in project gocd by gocd.

the class CcTrayViewAuthority method groupsAndTheirViewers.

public Map<String, Viewers> groupsAndTheirViewers() {
    final Map<String, Viewers> pipelinesAndViewers = new HashMap<>();
    SecurityConfig security = goConfigService.security();
    final Map<String, Collection<String>> rolesToUsers = rolesToUsers(security);
    final Set<String> superAdmins = namesOf(security.adminsConfig(), rolesToUsers);
    goConfigService.groups().accept(new PipelineGroupVisitor() {

        @Override
        public void visit(PipelineConfigs pipelineConfigs) {
            if (!pipelineConfigs.hasAuthorizationDefined()) {
                pipelinesAndViewers.put(pipelineConfigs.getGroup(), Everyone.INSTANCE);
                return;
            }
            Set<String> pipelineGroupAdmins = namesOf(pipelineConfigs.getAuthorization().getAdminsConfig(), rolesToUsers);
            Set<String> pipelineGroupViewers = namesOf(pipelineConfigs.getAuthorization().getViewConfig(), rolesToUsers);
            Set<String> viewers = new HashSet<>();
            viewers.addAll(superAdmins);
            viewers.addAll(pipelineGroupAdmins);
            viewers.addAll(pipelineGroupViewers);
            pipelinesAndViewers.put(pipelineConfigs.getGroup(), new AllowedViewers(viewers));
        }
    });
    return pipelinesAndViewers;
}
Also used : AllowedViewers(com.thoughtworks.go.domain.cctray.viewers.AllowedViewers) Viewers(com.thoughtworks.go.domain.cctray.viewers.Viewers) PipelineGroupVisitor(com.thoughtworks.go.domain.PipelineGroupVisitor) AllowedViewers(com.thoughtworks.go.domain.cctray.viewers.AllowedViewers)

Example 3 with AllowedViewers

use of com.thoughtworks.go.domain.cctray.viewers.AllowedViewers in project gocd by gocd.

the class ProjectStatusTest method shouldNotBeViewableByAnyoneTillViewersAreUpdated.

@Test
public void shouldNotBeViewableByAnyoneTillViewersAreUpdated() throws Exception {
    ProjectStatus status = new ProjectStatus("name", "activity", "web-url");
    assertThat(status.canBeViewedBy("abc"), is(false));
    assertThat(status.canBeViewedBy("def"), is(false));
    status.updateViewers(new AllowedViewers(s("abc", "ghi")));
    assertThat(status.canBeViewedBy("abc"), is(true));
    assertThat(status.canBeViewedBy("def"), is(false));
    assertThat(status.canBeViewedBy("ghi"), is(true));
}
Also used : AllowedViewers(com.thoughtworks.go.domain.cctray.viewers.AllowedViewers) Test(org.junit.Test)

Aggregations

AllowedViewers (com.thoughtworks.go.domain.cctray.viewers.AllowedViewers)3 Viewers (com.thoughtworks.go.domain.cctray.viewers.Viewers)2 Test (org.junit.Test)2 PipelineGroupVisitor (com.thoughtworks.go.domain.PipelineGroupVisitor)1 ProjectStatus (com.thoughtworks.go.domain.activity.ProjectStatus)1 Date (java.util.Date)1