From fd97c61fcfea0c6f9dd3746b34048e9ddf27c4dd Mon Sep 17 00:00:00 2001
From: Dave Arter
Date: Mon, 15 Jan 2018 17:44:27 +0000
Subject: Display report extra fields on inspect form
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This commit restores display of report extra fields on the inspect form,
previously missing because of a typo. Also improves the compactness of
the form by hiding ‘notice’ extras and any extra guidance attached to
each field.
---
CHANGELOG.md | 1 +
templates/web/base/report/_inspect.html | 4 ++--
templates/web/base/report/new/category_extras_fields.html | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 330b578c6..fa87a2fdf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@
- Change text on /reports to match lower down (fix translation).
- Ensure all reports graph can't dip downward. #1956
- Fix error sending `requires_inspection` reports. #1961
+ - Restore display of extra fields on inspector form. #1994
- Admin improvements:
- Admin can anonymize/hide all a user's reports. #1942 #1943
- Admin can log a user out. #1975
diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html
index eb2564157..1893826de 100644
--- a/templates/web/base/report/_inspect.html
+++ b/templates/web/base/report/_inspect.html
@@ -65,9 +65,9 @@
data-defect-types='[% category_defect_types.$cat_name %]'
data-templates='[% templates_by_category.$cat_name %]'>
[% IF cat_name == problem.category %]
- [% INCLUDE 'report/new/category_extras_fields.html' metas=category_extras.$category %]
+ [% INCLUDE 'report/new/category_extras_fields.html' metas=category_extras.$cat_name hide_notices=1 %]
[% ELSE %]
- [% INCLUDE 'report/new/category_extras_fields.html' metas=category_extras.$category report_meta='' %]
+ [% INCLUDE 'report/new/category_extras_fields.html' report_meta='' metas=category_extras.$cat_name hide_notices=1 %]
[% END %]
[% END %]
diff --git a/templates/web/base/report/new/category_extras_fields.html b/templates/web/base/report/new/category_extras_fields.html
index 9c2731730..5cbdcc524 100644
--- a/templates/web/base/report/new/category_extras_fields.html
+++ b/templates/web/base/report/new/category_extras_fields.html
@@ -5,7 +5,7 @@
- [% ELSE %]
+ [% ELSIF meta.variable != 'false' || NOT hide_notices %]
[% IF field_errors.$meta_name %]
--
cgit v1.2.3
From 27027ad882f5e1ddb8f2445e3b63972524ba82aa Mon Sep 17 00:00:00 2001
From: Dave Arter
Date: Thu, 8 Feb 2018 15:48:36 +0000
Subject: Improvements to report_sent_confirmation_email function
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- Send ‘report sent’ emails from cobrand’s contact address
- Don’t send email when report is made using contribute-as-other and
report_sent_confirmation_email is active.
---
perllib/FixMyStreet/App/Controller/Report/New.pm | 9 +++++----
perllib/FixMyStreet/Script/Reports.pm | 4 ++--
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index eff45013f..f9e07dd41 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -1398,10 +1398,11 @@ sub redirect_or_confirm_creation : Private {
if ( $report->confirmed ) {
# Subscribe problem reporter to email updates
$c->forward( 'create_reporter_alert' );
- if ($c->stash->{contributing_as_another_user} && $report->user->email) {
- $c->send_email( 'other-reported.txt', {
- to => [ [ $report->user->email, $report->name ] ],
- } );
+ if ($c->stash->{contributing_as_another_user} && $report->user->email
+ && !$c->cobrand->report_sent_confirmation_email) {
+ $c->send_email( 'other-reported.txt', {
+ to => [ [ $report->user->email, $report->name ] ],
+ } );
}
# If the user has shortlist permission, and either we're not on a
# council cobrand or the just-created problem is owned by the cobrand
diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm
index d6a614651..8e4a4aec1 100644
--- a/perllib/FixMyStreet/Script/Reports.pm
+++ b/perllib/FixMyStreet/Script/Reports.pm
@@ -306,9 +306,9 @@ sub _send_report_sent_email {
$h,
{
To => $row->user->email,
- From => [ FixMyStreet->config('CONTACT_EMAIL'), $cobrand->contact_name ],
+ From => [ $cobrand->contact_email, $cobrand->contact_name ],
},
- FixMyStreet->config('CONTACT_EMAIL'),
+ $cobrand->contact_email,
$nomail,
$cobrand,
$row->lang,
--
cgit v1.2.3
From 7ec0d3f67766764967a8bb92099c582f8bd6aaf5 Mon Sep 17 00:00:00 2001
From: Dave Arter
Date: Wed, 24 Jan 2018 18:01:56 +0000
Subject: Cobrands can pass `components` to Google Geocoder.
This allows more fine grained control over the geocoder search, e.g. to
specify the administrative area or town. See the geocoder api docs:
https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering
---
CHANGELOG.md | 2 ++
perllib/FixMyStreet/Geocode/Google.pm | 16 ++++++++++++----
t/Mock/GoogleGeocoder.pm | 36 +++++++++++++++++++++++++++++++++++
t/geocode/google.t | 22 +++++++++++++++++++++
4 files changed, 72 insertions(+), 4 deletions(-)
create mode 100644 t/Mock/GoogleGeocoder.pm
create mode 100644 t/geocode/google.t
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa87a2fdf..628bac41b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,8 @@
- Admin can log a user out. #1975
- Admin can remove a user's account details. #1944
- Superusers can have optional two-factor authentication. #1973
+ - Development improvements:
+ - 'components' parameter can be passed to Google geocoder. #1994
- UK:
- Lazy load images in the footer.
diff --git a/perllib/FixMyStreet/Geocode/Google.pm b/perllib/FixMyStreet/Geocode/Google.pm
index e64d02c4c..162101953 100644
--- a/perllib/FixMyStreet/Geocode/Google.pm
+++ b/perllib/FixMyStreet/Geocode/Google.pm
@@ -8,6 +8,7 @@ package FixMyStreet::Geocode::Google;
use strict;
use Utils;
+use URI::Escape;
# string STRING CONTEXT
# Looks up on Google Maps API, and caches, a user-inputted location.
@@ -19,11 +20,13 @@ sub string {
my $params = $c->cobrand->disambiguate_location($s);
+ my $components = "";
+
# For some reason adding gl=uk is no longer sufficient to make google
- # think we are in the UK for some locations so we explictly add UK to
- # the address.
- if ($c->cobrand->country eq 'GB' && $s !~ /, *UK/ && $s !~ /united *kingdom$/) {
- $s .= ', UK';
+ # think we are in the UK for some locations so we explicitly tell Google
+ # the country.
+ if ($c->cobrand->country eq 'GB') {
+ $components = "country:GB";
}
$s = FixMyStreet::Geocode::escape($s);
@@ -37,8 +40,13 @@ sub string {
} elsif ($params->{country}) {
$url .= '®ion=' . $params->{country};
}
+ if ($params->{components}) {
+ $components .= ($components ? '|' : '') . URI::Escape::uri_escape_utf8($params->{components});
+ }
$url .= '&language=' . $params->{lang} if $params->{lang};
+ $url .= '&components=' . $components if $components;
+
my $args = 'key=' . FixMyStreet->config('GOOGLE_MAPS_API_KEY');
my $js = FixMyStreet::Geocode::cache('google', $url, $args, qr/"status"\s*:\s*"(OVER_QUERY_LIMIT|REQUEST_DENIED|INVALID_REQUEST|UNKNOWN_ERROR)"/);
if (!$js) {
diff --git a/t/Mock/GoogleGeocoder.pm b/t/Mock/GoogleGeocoder.pm
new file mode 100644
index 000000000..fd741c00e
--- /dev/null
+++ b/t/Mock/GoogleGeocoder.pm
@@ -0,0 +1,36 @@
+package t::Mock::GoogleGeocoder;
+
+use JSON::MaybeXS;
+use Web::Simple;
+use LWP::Protocol::PSGI;
+
+has json => (
+ is => 'lazy',
+ default => sub {
+ JSON->new->utf8->pretty->allow_blessed->convert_blessed;
+ },
+);
+
+sub dispatch_request {
+ my $self = shift;
+
+ sub (GET + /maps/api/geocode/json + ?*) {
+ my ($self, $args) = @_;
+ my $response = {};
+ if ($args->{address} =~ /result/) {
+ $response->{status} = 'OK';
+ push @{$response->{results}}, { formatted_address => 'High Street, Old Town, City of Edinburgh, Scotland', geometry => { location => { lng => -3.1858425, lat => 55.9504009 } } };
+ }
+ if ($args->{address} eq 'two results') {
+ push @{$response->{results}}, { geometry => { location => { lat => "55.8596449", "lng" => "-4.240377" } }, formatted_address => "High Street, Collegelands, Merchant City, Glasgow, Scotland" };
+ }
+ my $json = mySociety::Locale::in_gb_locale {
+ $self->json->encode($response);
+ };
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ },
+}
+
+LWP::Protocol::PSGI->register(t::Mock::GoogleGeocoder->to_psgi_app, host => 'maps.googleapis.com');
+
+__PACKAGE__->run_if_script;
diff --git a/t/geocode/google.t b/t/geocode/google.t
new file mode 100644
index 000000000..ee3c15ea8
--- /dev/null
+++ b/t/geocode/google.t
@@ -0,0 +1,22 @@
+package FixMyStreet::Cobrand::Tester;
+use parent 'FixMyStreet::Cobrand::Default';
+sub country { 'GB' }
+sub disambiguate_location { { components => 'country:IE' } }
+
+package main;
+
+use FixMyStreet::Test;
+use FixMyStreet::Geocode::Google;
+use Catalyst::Test 'FixMyStreet::App';
+use t::Mock::GoogleGeocoder;
+
+my $c = ctx_request('/');
+my $r = FixMyStreet::Geocode::Google::string("one result", $c);
+ok $r->{latitude};
+ok $r->{longitude};
+
+$c->stash->{cobrand} = FixMyStreet::Cobrand::Tester->new;
+$r = FixMyStreet::Geocode::Google::string("two results", $c);
+is scalar @{$r->{error}}, 2;
+
+done_testing;
--
cgit v1.2.3