diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-06-20 08:04:39 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-06-20 08:04:39 +0100 |
commit | 9d71b5f3012e244200fa59d118394fdb8982c752 (patch) | |
tree | 6d55b7cd6b428b6941b61a08f8c24ed90f0b6287 | |
parent | 873ea570cc429b378eb33c8de90570a10414264c (diff) | |
parent | d8e5d5715021f80737518622b38448cfa8b10b0b (diff) |
Merge branch 'issues/commercial/1060-highway-flytipping-to-tfb'
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Buckinghamshire.pm | 21 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 2 | ||||
-rw-r--r-- | t/cobrand/bucks.t | 52 | ||||
-rw-r--r-- | templates/web/base/admin/contact-form.html | 2 | ||||
-rw-r--r-- | templates/web/fixmystreet.com/reports/summary.html | 6 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/admin.js | 2 |
6 files changed, 79 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm index a5e45d5a9..9b4445460 100644 --- a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm +++ b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm @@ -51,6 +51,8 @@ sub pin_colour { return 'yellow'; } +sub admin_user_domain { 'buckscc.gov.uk' } + sub contact_email { my $self = shift; return join( '@', 'fixmystreetbs', 'email.buckscc.gov.uk' ); @@ -87,6 +89,23 @@ sub open311_config { $row->set_extra_fields(@$extra); } +# This provides a similar functionality to open311_config, but for email. +sub munge_sendreport_params { + my ($self, $row, $vars, $hdrs) = @_; + + return unless $row->category eq 'Flytipping'; + + # Reports made via FMS.com or the app probably won't have a site code + # value because we don't display the adopted highways layer on those + # frontends. Instead we'll look up the closest asset from the WFS + # service at the point we're sending the report by email. + my $site_code = $row->get_extra_field_value('site_code') || $self->lookup_site_code($row, 10); + if ($site_code) { + my $e = join('', 'internaltfb', '@', $self->admin_user_domain); + push @{$hdrs->{To}}, [ $e, 'TfB' ]; + } +} + sub map_type { 'Buckinghamshire' } sub default_map_zoom { 3 } @@ -321,8 +340,8 @@ sub categories_restriction { sub lookup_site_code { my $self = shift; my $row = shift; + my $buffer = shift || 200; # metres - my $buffer = 200; # metres my ($x, $y) = $row->local_coords; my ($w, $s, $e, $n) = ($x-$buffer, $y-$buffer, $x+$buffer, $y+$buffer); diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 583aaaa08..079f8ba68 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -72,6 +72,8 @@ sub send { my ($verbose, $nomail) = CronFns::options(); my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new(); + $cobrand = $cobrand->call_hook(get_body_handler_for_problem => $row) || $cobrand; + my $params = { To => $self->to, }; diff --git a/t/cobrand/bucks.t b/t/cobrand/bucks.t new file mode 100644 index 000000000..1dee8b47e --- /dev/null +++ b/t/cobrand/bucks.t @@ -0,0 +1,52 @@ +use Test::MockModule; +use FixMyStreet::TestMech; +use FixMyStreet::Script::Reports; + +my $mech = FixMyStreet::TestMech->new; + +my $body = $mech->create_body_ok(2217, 'Buckinghamshire'); +$mech->create_contact_ok(body_id => $body->id, category => 'Flytipping', email => "flytipping\@example.org"); + +my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Buckinghamshire'); +$cobrand->mock('lookup_site_code', sub { + my ($self, $row, $buffer) = @_; + return "Road ID" if $row->latitude == 51.812244; +}); + +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'buckinghamshire', 'fixmystreet' ], + MAPIT_URL => 'http://mapit.uk/', +}, sub { + +subtest 'cobrand displays council name' => sub { + ok $mech->host("buckinghamshire.fixmystreet.com"), "change host to bucks"; + $mech->get_ok('/'); + $mech->content_contains('Buckinghamshire'); +}; + +$mech->create_problems_for_body(1, $body->id, 'On Road', { + category => 'Flytipping', cobrand => 'fixmystreet', + latitude => 51.812244, longitude => -0.827363, +}); + +subtest 'flytipping on road sent to extra email' => sub { + FixMyStreet::Script::Reports::send(); + my $email = $mech->get_email; + my $tfb = join('', 'internaltfb', '@', 'buckscc.gov.uk'); + is $email->header('To'), '"Buckinghamshire" <flytipping@example.org>, "TfB" <' . $tfb . '>'; +}; + +$mech->create_problems_for_body(1, $body->id, 'Off Road', { + category => 'Flytipping', cobrand => 'fixmystreet', + latitude => 51.813173, longitude => -0.826741, +}); +subtest 'flytipping on road sent to extra email' => sub { + $mech->clear_emails_ok; + FixMyStreet::Script::Reports::send(); + my $email = $mech->get_email; + is $email->header('To'), '"Buckinghamshire" <flytipping@example.org>'; +}; + +}; + +done_testing(); diff --git a/templates/web/base/admin/contact-form.html b/templates/web/base/admin/contact-form.html index 24021ebf3..b34ca3377 100644 --- a/templates/web/base/admin/contact-form.html +++ b/templates/web/base/admin/contact-form.html @@ -27,7 +27,7 @@ [% loc("The <strong>email address</strong> is the destination to which reports about this category will be sent. Other categories for this body may have the same email address.") %] </p> - [% IF (body.send_method AND body.send_method != 'Email') OR body.can_be_devolved %] + [% IF (body.send_method AND body.send_method.match('Email')) OR body.can_be_devolved %] <p> [% loc("If you're using <strong>a send method that is not email</strong>, enter the service ID (Open311) or equivalent identifier here.") %] </p> diff --git a/templates/web/fixmystreet.com/reports/summary.html b/templates/web/fixmystreet.com/reports/summary.html index 1b48d68b4..96d326ce7 100644 --- a/templates/web/fixmystreet.com/reports/summary.html +++ b/templates/web/fixmystreet.com/reports/summary.html @@ -12,7 +12,7 @@ <h1>[% loc('Dashboard') %] – [% body.name %]</h1> </div> -[% IF body.send_method == 'Email' OR body.send_method == '' %] +[% IF body.send_method.match('Email') OR body.send_method == '' %] <div class="dashboard-row"> <div class="dashboard-item dashboard-item--12"> <div class="healthcheck-unit healthcheck-unit--good"> @@ -171,7 +171,7 @@ </div> </div> -[% IF body.send_method == 'Email' OR body.send_method == '' %] +[% IF body.send_method.match('Email') OR body.send_method == '' %] <div class="dashboard-row dashboard-row--yellow"> <div class="dashboard-item dashboard-item--12 dashboard-fms-case-studies"> <h2 style="margin-bottom: 1em">How FixMyStreet Pro helps other councils</h2> @@ -206,7 +206,7 @@ <p> [% tprintf( loc('Reports are currently not being sent to %s.'), body.name ) %] </p> - [% ELSIF body.send_method != 'Email' AND body.send_method != '' %] + [% ELSIF NOT body.send_method.match('Email') AND body.send_method != '' %] <p> [% tprintf( loc('Reports to %s are currently sent directly into backend services.'), body.name) %] </p> diff --git a/web/cobrands/fixmystreet/admin.js b/web/cobrands/fixmystreet/admin.js index 5c0378ad2..3066ee614 100644 --- a/web/cobrands/fixmystreet/admin.js +++ b/web/cobrands/fixmystreet/admin.js @@ -10,7 +10,7 @@ $(function(){ var show_open311 = false; if ($form.find('[name=endpoint]').val()) { show_open311 = true; // always show the form if there is an endpoint value - } else if (send_method && !send_method.match(/^(email|noop|refused)$/i)) { + } else if (send_method && !send_method.match(/email|^noop$|^refused$/i)) { show_open311 = true; } if (show_open311) { |