Skip to content

Commit

Permalink
Merge pull request #976 from alphagov/fix-organogram-csp-error
Browse files Browse the repository at this point in the history
Fix organogram CSP error
  • Loading branch information
richardTowers authored Aug 10, 2021
2 parents 6401b59 + 3c5475e commit 99b0bfc
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/controllers/previews_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class PreviewsController < ApplicationController
def show
append_content_security_policy_directives(
connect_src: %w[s3-eu-west-1.amazonaws.com],
connect_src: ["s3-eu-west-1.amazonaws.com", ENV["CKAN_DOMAIN"]].compact,
)

@dataset = Dataset.get_by_uuid(uuid: params[:dataset_uuid])
Expand Down
2 changes: 1 addition & 1 deletion bin/setup-docker-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# source this script before running tests in docker ckan to set the correct env vars
export RAILS_ENV=test
export ES_INDEX=datasets-test
export CKAN_REDIRECTION_URL=testdomain
export CKAN_DOMAIN=testdomain

# install chrome for tests
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
Expand Down
2 changes: 0 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,4 @@
# config.action_cable.disable_request_forgery_protection = true

config.zendesk = nil

config.ckan_redirection_url = ENV["CKAN_REDIRECTION_URL"]
end
2 changes: 0 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,4 @@
# config.active_record.database_selector = { delay: 2.seconds }
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session

config.ckan_redirection_url = ENV["CKAN_REDIRECTION_URL"]
end
8 changes: 4 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

get "/sites/default/files/*organogram_path", to: redirect("https://s3-eu-west-1.amazonaws.com/datagovuk-#{Rails.env}-ckan-organogram/legacy/%{organogram_path}"), format: false

if ENV["CKAN_REDIRECTION_URL"].present?
get "dataset/edit/:legacy_name", to: redirect(domain: ENV["CKAN_REDIRECTION_URL"], subdomain: "", path: "/dataset/edit/%{legacy_name}")
if ENV["CKAN_DOMAIN"].present?
get "dataset/edit/:legacy_name", to: redirect(domain: ENV["CKAN_DOMAIN"], subdomain: "", path: "/dataset/edit/%{legacy_name}")
end

get "dataset/:uuid", to: "datasets#show", uuid: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
Expand Down Expand Up @@ -55,9 +55,9 @@
get "acknowledge", to: "messages#acknowledge"

# Route everything else to CKAN
if ENV["CKAN_REDIRECTION_URL"].present?
if ENV["CKAN_DOMAIN"].present?
match "*path",
to: redirect(domain: ENV["CKAN_REDIRECTION_URL"], subdomain: "", path: "/%{path}"),
to: redirect(domain: ENV["CKAN_DOMAIN"], subdomain: "", path: "/%{path}"),
via: :all,
constraints: { path: /(?!#{Regexp.quote(Rails.application.config.assets.prefix[1..-1])}).+/ }
end
Expand Down
2 changes: 1 addition & 1 deletion production-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ applications:
env:
RAILS_ENV: production
RACK_ENV: production
CKAN_REDIRECTION_URL: ckan.publishing.service.gov.uk
CKAN_DOMAIN: ckan.publishing.service.gov.uk
GOVUK_APP_DOMAIN: www.gov.uk
GOVUK_WEBSITE_ROOT: https://www.gov.uk
services:
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
require "spec_helper"
ENV["RAILS_ENV"] ||= "test"
ENV["CKAN_REDIRECTION_URL"] ||= "testdomain"
ENV["CKAN_DOMAIN"] ||= "testdomain"
require File.expand_path("../config/environment", __dir__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
Expand Down
2 changes: 1 addition & 1 deletion staging-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ applications:
env:
RAILS_ENV: staging
RACK_ENV: staging
CKAN_REDIRECTION_URL: ckan.staging.publishing.service.gov.uk
CKAN_DOMAIN: ckan.staging.publishing.service.gov.uk
GOVUK_APP_DOMAIN: www.gov.uk
GOVUK_WEBSITE_ROOT: https://www.gov.uk
services:
Expand Down

0 comments on commit 99b0bfc

Please sign in to comment.