Search in sources :

Example 6 with CombinedPluginInfo

use of com.thoughtworks.go.plugin.domain.common.CombinedPluginInfo in project gocd by gocd.

the class PluginImagesControllerDelegate method show.

public byte[] show(Request request, Response response) throws IOException {
    String pluginId = request.params("plugin_id");
    String hash = request.params("hash");
    CombinedPluginInfo pluginInfo = pluginInfoFinder.pluginInfoFor(pluginId);
    if (pluginInfo == null) {
        throw halt(404, "");
    }
    Image image = pluginInfo.getImage();
    if (image == null || !image.getHash().equals(hash)) {
        throw halt(404, "");
    }
    response.raw().setHeader("Cache-Control", "max-age=31557600, public");
    if (fresh(request, image.getHash())) {
        notModified(response);
        return new byte[0];
    }
    response.status(200);
    response.header("Content-Type", image.getContentType());
    this.setEtagHeader(response, image.getHash());
    if (request.requestMethod().equals("head")) {
        return new byte[0];
    } else {
        return image.getDataAsBytes();
    }
}
Also used : Image(com.thoughtworks.go.plugin.domain.common.Image) CombinedPluginInfo(com.thoughtworks.go.plugin.domain.common.CombinedPluginInfo)

Example 7 with CombinedPluginInfo

use of com.thoughtworks.go.plugin.domain.common.CombinedPluginInfo in project gocd by gocd.

the class InitialContextProviderTest method shouldNotShowAnalyticsDashboardWhenUserIsNotAdmin.

@Test
public void shouldNotShowAnalyticsDashboardWhenUserIsNotAdmin() {
    Map<String, Object> modelMap = new HashMap<>();
    when(securityService.isUserAdmin(any(Username.class))).thenReturn(false);
    CombinedPluginInfo combinedPluginInfo = new CombinedPluginInfo(analyticsPluginInfo());
    when(pluginInfoFinder.allPluginInfos(PluginConstants.ANALYTICS_EXTENSION)).thenReturn(Collections.singletonList(combinedPluginInfo));
    VelocityContext velocityContext = initialContextProvider.getVelocityContext(modelMap, dummySparkController.getClass(), "viewName");
    assertThat(velocityContext.internalGet("showAnalyticsDashboard")).isEqualTo(false);
}
Also used : HashMap(java.util.HashMap) Username(com.thoughtworks.go.server.domain.Username) VelocityContext(org.apache.velocity.VelocityContext) CombinedPluginInfo(com.thoughtworks.go.plugin.domain.common.CombinedPluginInfo) Test(org.junit.jupiter.api.Test)

Example 8 with CombinedPluginInfo

use of com.thoughtworks.go.plugin.domain.common.CombinedPluginInfo in project gocd by gocd.

the class InitialContextProviderTest method shouldNotShowAnalyticsDashboardPluginIsNotPresent.

@Test
public void shouldNotShowAnalyticsDashboardPluginIsNotPresent() {
    Map<String, Object> modelMap = new HashMap<>();
    when(securityService.isUserAdmin(any(Username.class))).thenReturn(true);
    when(pluginInfoFinder.allPluginInfos(PluginConstants.ANALYTICS_EXTENSION)).thenReturn(Collections.singletonList(new CombinedPluginInfo()));
    VelocityContext velocityContext = initialContextProvider.getVelocityContext(modelMap, dummySparkController.getClass(), "viewName");
    assertThat(velocityContext.internalGet("showAnalyticsDashboard")).isEqualTo(false);
}
Also used : HashMap(java.util.HashMap) Username(com.thoughtworks.go.server.domain.Username) VelocityContext(org.apache.velocity.VelocityContext) CombinedPluginInfo(com.thoughtworks.go.plugin.domain.common.CombinedPluginInfo) Test(org.junit.jupiter.api.Test)

Aggregations

CombinedPluginInfo (com.thoughtworks.go.plugin.domain.common.CombinedPluginInfo)8 Username (com.thoughtworks.go.server.domain.Username)3 HashMap (java.util.HashMap)3 VelocityContext (org.apache.velocity.VelocityContext)3 Test (org.junit.jupiter.api.Test)3 PluginInfo (com.thoughtworks.go.plugin.domain.common.PluginInfo)2 Test (org.junit.Test)2 AnalyticsMetadataStore (com.thoughtworks.go.plugin.access.analytics.AnalyticsMetadataStore)1 ArtifactMetadataStore (com.thoughtworks.go.plugin.access.artifact.ArtifactMetadataStore)1 AuthorizationMetadataStore (com.thoughtworks.go.plugin.access.authorization.AuthorizationMetadataStore)1 MetadataStore (com.thoughtworks.go.plugin.access.common.MetadataStore)1 ConfigRepoMetadataStore (com.thoughtworks.go.plugin.access.configrepo.ConfigRepoMetadataStore)1 ElasticAgentMetadataStore (com.thoughtworks.go.plugin.access.elastic.ElasticAgentMetadataStore)1 NotificationMetadataStore (com.thoughtworks.go.plugin.access.notification.NotificationMetadataStore)1 PackageMaterialMetadataStore (com.thoughtworks.go.plugin.access.packagematerial.PackageMaterialMetadataStore)1 PluggableTaskMetadataStore (com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskMetadataStore)1 NewSCMMetadataStore (com.thoughtworks.go.plugin.access.scm.NewSCMMetadataStore)1 AnalyticsPluginInfo (com.thoughtworks.go.plugin.domain.analytics.AnalyticsPluginInfo)1 Capabilities (com.thoughtworks.go.plugin.domain.analytics.Capabilities)1 SupportedAnalytics (com.thoughtworks.go.plugin.domain.analytics.SupportedAnalytics)1