From 88933aa8df0f748dce8188cde99b6199ae070864 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 1 Jul 2016 13:35:17 +0100 Subject: Make sure map JS works through an admin proxy. Tidy up use of absolute URLs when in the admin. Have the 404 handler spot static files in admin as a fallback. --- conf/general.yml-example | 4 ++-- perllib/FixMyStreet/App/Controller/Root.pm | 7 +++++++ perllib/FixMyStreet/App/View/Web.pm | 3 ++- perllib/FixMyStreet/Cobrand/Default.pm | 5 ++++- perllib/FixMyStreet/Cobrand/FiksGataMi.pm | 4 ---- perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 4 ---- perllib/FixMyStreet/Cobrand/FixaMinGata.pm | 4 ---- t/app/controller/admin.t | 2 +- templates/web/base/admin/header.html | 3 ++- templates/web/base/admin/report_edit.html | 2 +- templates/web/base/common_header_tags.html | 24 ++++++++++++---------- templates/web/base/header.html | 11 +++++----- templates/web/base/maps/noscript_map.html | 17 +++++++-------- templates/web/base/maps/openlayers.html | 2 +- templates/web/bristol/header_extra.html | 2 +- templates/web/bromley/header_extra.html | 2 +- templates/web/eastsussex/header.html.template | 8 ++++---- templates/web/fiksgatami/header.html | 10 ++++----- .../web/fixmystreet-uk-councils/header_extra.html | 2 +- templates/web/fixmystreet.com/about/council.html | 22 ++++++++++---------- templates/web/fixmystreet.com/header_extra.html | 6 +++--- templates/web/hart/header.html | 10 ++++----- templates/web/oxfordshire/header.html | 10 ++++----- templates/web/warwickshire/header.html | 20 +++++++++--------- templates/web/zurich/header.html | 12 +++++------ web/cobrands/fiksgatami/_colours.scss | 2 +- web/cobrands/fixamingata/_colours.scss | 3 ++- web/cobrands/fixamingata/base.scss | 4 +--- web/cobrands/fixamingata/layout.scss | 2 -- web/cobrands/sass/_base.scss | 4 ++-- web/cobrands/sass/_layout.scss | 6 +++--- 31 files changed, 104 insertions(+), 113 deletions(-) diff --git a/conf/general.yml-example b/conf/general.yml-example index 749b9e716..aa8d431be 100644 --- a/conf/general.yml-example +++ b/conf/general.yml-example @@ -155,8 +155,8 @@ ALLOWED_COBRANDS: - cobrand2: 'hostname_substring2' - cobrand3 -# This is only used in "offensive report" emails to provide a link directly to -# the admin interface. If wanted, set to the full URL of your admin interface. +# This is used in e.g. "offensive report" emails to provide a link directly to +# the admin interface. Defaults to BASE_URL with "/admin" on the end. ADMIN_BASE_URL: '' # How many items are returned in the GeoRSS feeds by default diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm index 16f4aa491..88f480137 100644 --- a/perllib/FixMyStreet/App/Controller/Root.pm +++ b/perllib/FixMyStreet/App/Controller/Root.pm @@ -82,6 +82,13 @@ Display a 404 (not found) or 410 (gone) page. Pass in an optional error message sub page_error_404_not_found : Private { my ( $self, $c, $error_msg ) = @_; + + # Try getting static content that might be given under an admin proxy. + # First the special generated JavaScript file + $c->go('/js/translation_strings', [ $1 ], []) if $c->req->path =~ m{^admin/js/translation_strings\.(.*?)\.js$}; + # Then a generic static file + $c->serve_static_file("web/$1") && return if $c->req->path =~ m{^admin/(.*)}; + $c->stash->{template} = 'errors/page_error_404_not_found.html'; $c->stash->{error_msg} = $error_msg; $c->response->status(404); diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index a92021f0c..d43d3af7e 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -176,7 +176,8 @@ sub version { $version_hash{$file} = ( stat( $path ) )[9]; } $version_hash{$file} ||= ''; - return "$file?$version_hash{$file}"; + my $admin = $self->template->context->stash->{admin} ? FixMyStreet->config('ADMIN_BASE_URL') : ''; + return "$admin$file?$version_hash{$file}"; } sub decode { diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 76d73d96e..5c7ce10c4 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -133,7 +133,10 @@ Base URL for the admin interface. =cut -sub admin_base_url { FixMyStreet->config('ADMIN_BASE_URL') || '' } +sub admin_base_url { + my $self = shift; + return FixMyStreet->config('ADMIN_BASE_URL') || $self->base_url . "/admin"; +} =head2 base_url diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm index 7b175f371..ba26b7a2c 100644 --- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm +++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm @@ -32,10 +32,6 @@ sub area_types { [ 'NKO', 'NFY', 'NRA' ]; } -sub admin_base_url { - return 'http://www.fiksgatami.no/admin'; -} - sub geocode_postcode { my ( $self, $s ) = @_; diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index 61011a414..b321a21c4 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -23,10 +23,6 @@ sub restriction { return {}; } -sub admin_base_url { - return 'https://secure.mysociety.org/admin/bci'; -} - sub title_list { my $self = shift; my $areas = shift; diff --git a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm index e6e54926f..9ffbf00b8 100644 --- a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm +++ b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm @@ -33,10 +33,6 @@ sub area_types { [ 'KOM' ]; } -sub admin_base_url { - return 'http://www.fixamingata.se/admin/'; -} - # If lat/lon are present in the URL, OpenLayers will use that to centre the map. # Need to specify a zoom to stop it defaulting to null/0. sub uri { diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index f8f280d63..007948299 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -1232,7 +1232,7 @@ subtest "Check admin_base_url" => sub { my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($report->cobrand)->new(); is ($report->admin_url($cobrand), - (sprintf 'https://secure.mysociety.org/admin/bci/report_edit/%d', $report_id), + (sprintf 'http://www.example.org/admin/report_edit/%d', $report_id), 'get_admin_url OK'); }; diff --git a/templates/web/base/admin/header.html b/templates/web/base/admin/header.html index ddaa4aa44..517b984e3 100644 --- a/templates/web/base/admin/header.html +++ b/templates/web/base/admin/header.html @@ -1,6 +1,7 @@ [% SET bodyclass = bodyclass || 'fullwidthpage'; - INCLUDE 'header.html' admin = 1, bodyclass = bodyclass _ ' admin'; + SET admin = 1; + INCLUDE 'header.html' bodyclass = bodyclass _ ' admin'; %]