aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/Cobrand/EmptyHomes.pm6
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm9
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm152
-rw-r--r--perllib/FixMyStreet/SendReport/NI.pm37
-rw-r--r--t/app/model/problem.t19
-rw-r--r--t/open311/endpoint/warwick.t1
-rw-r--r--templates/web/base/report/new/councils_text_all.html10
7 files changed, 89 insertions, 145 deletions
diff --git a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
index b87a1cf24..5052d91a7 100644
--- a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
+++ b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
@@ -13,6 +13,12 @@ sub path_to_web_templates {
return [ FixMyStreet->path_to( 'templates/web', $self->moniker )->stringify ];
}
+sub _fallback_body_sender {
+ my ( $self, $body, $category ) = @_;
+
+ return { method => 'EmptyHomes' };
+};
+
=item
Return the base url for this cobranded site
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm
index 33d3b4253..cd64de9c6 100644
--- a/perllib/FixMyStreet/Cobrand/UK.pm
+++ b/perllib/FixMyStreet/Cobrand/UK.pm
@@ -26,15 +26,6 @@ sub disambiguate_location {
};
}
-sub _fallback_body_sender {
- my ( $self, $body, $category ) = @_;
-
- my $first_area = $body->body_areas->first->area_id;
- my $area_info = mySociety::MaPit::call('area', $first_area);
- return { method => 'NI' } if $area_info->{type} eq 'LGD';
- return { method => 'Email' };
-}
-
sub process_extras {
my $self = shift;
my $ctx = shift;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index cc0cc5242..7a50a3146 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -302,118 +302,106 @@ sub send_reports {
if ( $cobrand->allow_anonymous_reports &&
$row->user->email eq $cobrand->anonymous_account->{'email'}
) {
- $h{anonymous_report} = 1;
- $h{user_details} = _('This report was submitted anonymously');
- } else {
- $h{user_details} = sprintf(_('Name: %s'), $row->name) . "\n\n";
- $h{user_details} .= sprintf(_('Email: %s'), $row->user->email) . "\n\n";
- }
+ $h{anonymous_report} = 1;
+ $h{user_details} = _('This report was submitted anonymously');
+ } else {
+ $h{user_details} = sprintf(_('Name: %s'), $row->name) . "\n\n";
+ $h{user_details} .= sprintf(_('Email: %s'), $row->user->email) . "\n\n";
+ }
+
+ $h{easting_northing} = '';
if ($cobrand->can('process_additional_metadata_for_email')) {
$cobrand->process_additional_metadata_for_email($row, \%h);
}
+ # XXX Needs locks!
+ # XXX Only copes with at most one missing body
+ my ($bodies, $missing) = $row->bodies_str =~ /^([\d,]+)(?:\|(\d+))?/;
+ my @bodies = split(/,/, $bodies);
+ $bodies = FixMyStreet::App->model("DB::Body")->search(
+ { id => \@bodies },
+ { order_by => 'name' },
+ );
+ $missing = FixMyStreet::App->model("DB::Body")->find($missing) if $missing;
+
+ my @dear;
my %reporters = ();
- my ( $sender_count );
- if ($site eq 'emptyhomes') {
-
- my $body = $row->bodies_str;
- $body = FixMyStreet::App->model("DB::Body")->find($body);
- my $sender = "FixMyStreet::SendReport::EmptyHomes";
- $reporters{ $sender } = $sender->new() unless $reporters{$sender};
- $reporters{ $sender }->add_body( $body );
- $sender_count = 1;
+ while (my $body = $bodies->next) {
+ my $sender_info = $cobrand->get_body_sender( $body, $row->category );
+ my $sender = "FixMyStreet::SendReport::" . $sender_info->{method};
- } else {
-
- # XXX Needs locks!
- # XXX Only copes with at most one missing body
- my ($bodies, $missing) = $row->bodies_str =~ /^([\d,]+)(?:\|(\d+))?/;
- my @bodies = split(/,/, $bodies);
- $bodies = FixMyStreet::App->model("DB::Body")->search(
- { id => \@bodies },
- { order_by => 'name' },
- );
- $missing = FixMyStreet::App->model("DB::Body")->find($missing) if $missing;
- my @dear;
-
- while (my $body = $bodies->next) {
- my $sender_info = $cobrand->get_body_sender( $body, $row->category );
- my $sender = "FixMyStreet::SendReport::" . $sender_info->{method};
-
- if ( ! exists $senders->{ $sender } ) {
- warn "No such sender [ $sender ] for body $body->name ( $body->id )";
- next;
- }
- $reporters{ $sender } ||= $sender->new();
-
- if ( $reporters{ $sender }->should_skip( $row ) ) {
- debug_print("skipped by sender " . $sender_info->{method} . " (might be due to previous failed attempts?)", $row->id) if $debug_mode;
- } else {
- debug_print("OK, adding recipient body " . $body->id . ":" . $body->name . ", " . $body->send_method, $row->id) if $debug_mode;
- push @dear, $body->name;
- $reporters{ $sender }->add_body( $body, $sender_info->{config} );
- }
+ if ( ! exists $senders->{ $sender } ) {
+ warn "No such sender [ $sender ] for body $body->name ( $body->id )";
+ next;
}
+ $reporters{ $sender } ||= $sender->new();
- if ($h{category} eq _('Other')) {
- $h{category_footer} = _('this type of local problem');
- $h{category_line} = '';
+ if ( $reporters{ $sender }->should_skip( $row ) ) {
+ debug_print("skipped by sender " . $sender_info->{method} . " (might be due to previous failed attempts?)", $row->id) if $debug_mode;
} else {
- $h{category_footer} = "'" . $h{category} . "'";
- $h{category_line} = sprintf(_("Category: %s"), $h{category}) . "\n\n";
+ debug_print("OK, adding recipient body " . $body->id . ":" . $body->name . ", " . $body->send_method, $row->id) if $debug_mode;
+ push @dear, $body->name;
+ $reporters{ $sender }->add_body( $body, $sender_info->{config} );
}
- if ( $row->subcategory ) {
- $h{subcategory_line} = sprintf(_("Subcategory: %s"), $row->subcategory) . "\n\n";
- } else {
- $h{subcategory_line} = "\n\n";
- }
+ # If we are in the UK include eastings and northings, and nearest stuff
+ if ( $cobrand->country eq 'GB' && !$h{easting} ) {
+ my $coordsyst = 'G';
+ my $first_area = $body->body_areas->first->area_id;
+ my $area_info = mySociety::MaPit::call('area', $first_area);
+ $coordsyst = 'I' if $area_info->{type} eq 'LGD';
- $h{bodies_name} = join(_(' and '), @dear);
- if ($h{category} eq _('Other')) {
- $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to both councils covering the location of the problem, as the user did not categorise it; please ignore it if you're not the correct council to deal with the issue, or let us know what category of problem this is so we can add it to our system.") . " ]\n\n"
- : '';
- } else {
- $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to several councils covering the location of the problem, as the category selected is provided for all of them; please ignore it if you're not the correct council to deal with the issue.") . " ]\n\n"
- : '';
- }
- $h{missing} = '';
- if ($missing) {
- $h{missing} = '[ '
- . sprintf(_('We realise this problem might be the responsibility of %s; however, we don\'t currently have any contact details for them. If you know of an appropriate contact address, please do get in touch.'), $missing->name)
- . " ]\n\n";
- }
+ ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude}, $coordsyst );
- $sender_count = scalar @dear;
+ # email templates don't have conditionals so we need to format this here
+ $h{easting_northing} = "Easting/Northing";
+ $h{easting_northing} .= " (IE)" if $coordsyst eq 'I';
+ $h{easting_northing} .= ": $h{easting}/$h{northing}\n\n";
+ }
}
unless ( keys %reporters ) {
die 'Report not going anywhere for ID ' . $row->id . '!';
}
- if (! $sender_count) {
+ unless (@dear) {
debug_print("can't send because sender count is zero", $row->id) if $debug_mode;
next;
}
- # If we are in the UK include eastings and northings, and nearest stuff
- $h{easting_northing} = '';
- if ( $cobrand->country eq 'GB' ) {
+ if ($h{category} eq _('Other')) {
+ $h{category_footer} = _('this type of local problem');
+ $h{category_line} = '';
+ } else {
+ $h{category_footer} = "'" . $h{category} . "'";
+ $h{category_line} = sprintf(_("Category: %s"), $h{category}) . "\n\n";
+ }
- my $coordsyst = 'G';
- $coordsyst = 'I' if grep { /FixMyStreet::SendReport::NI/ } keys %reporters;
- ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude}, $coordsyst );
+ if ( $row->subcategory ) {
+ $h{subcategory_line} = sprintf(_("Subcategory: %s"), $row->subcategory) . "\n\n";
+ } else {
+ $h{subcategory_line} = "\n\n";
+ }
- # email templates don't have conditionals so we need to format this here
- $h{easting_northing} = "Easting/Northing";
- $h{easting_northing} .= " (IE)" if $coordsyst eq 'I';
- $h{easting_northing} .= ": $h{easting}/$h{northing}\n\n";
+ $h{bodies_name} = join(_(' and '), @dear);
+ if ($h{category} eq _('Other')) {
+ $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to both councils covering the location of the problem, as the user did not categorise it; please ignore it if you're not the correct council to deal with the issue, or let us know what category of problem this is so we can add it to our system.") . " ]\n\n"
+ : '';
+ } else {
+ $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to several councils covering the location of the problem, as the category selected is provided for all of them; please ignore it if you're not the correct council to deal with the issue.") . " ]\n\n"
+ : '';
+ }
+ $h{missing} = '';
+ if ($missing) {
+ $h{missing} = '[ '
+ . sprintf(_('We realise this problem might be the responsibility of %s; however, we don\'t currently have any contact details for them. If you know of an appropriate contact address, please do get in touch.'), $missing->name)
+ . " ]\n\n";
}
if (mySociety::Config::get('STAGING_SITE') && !mySociety::Config::get('SEND_REPORTS_ON_STAGING')) {
# on a staging server send emails to ourselves rather than the bodies
- %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI|EmptyHomes)/ } keys %reporters;
+ %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|EmptyHomes)/ } keys %reporters;
unless (%reporters) {
%reporters = ( 'FixMyStreet::SendReport::Email' => FixMyStreet::SendReport::Email->new() );
}
diff --git a/perllib/FixMyStreet/SendReport/NI.pm b/perllib/FixMyStreet/SendReport/NI.pm
deleted file mode 100644
index c60643566..000000000
--- a/perllib/FixMyStreet/SendReport/NI.pm
+++ /dev/null
@@ -1,37 +0,0 @@
-package FixMyStreet::SendReport::NI;
-
-use Moose;
-
-BEGIN { extends 'FixMyStreet::SendReport::Email'; }
-
-sub build_recipient_list {
- my ( $self, $row, $h ) = @_;
-
- my $all_confirmed = 1;
- foreach my $body ( @{ $self->bodies } ) {
- my $contact = FixMyStreet::App->model("DB::Contact")->find( {
- deleted => 0,
- body_id => $body->id,
- category => $row->category
- } );
-
- my ($email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note );
-
- unless ($confirmed) {
- $all_confirmed = 0;
- $email = 'N/A' unless $email;
- }
-
- my $name = $body->name;
- if ( $email =~ /^roads.([^@]*)\@drdni/ ) {
- $name = "Roads Service (\u$1)";
- $h->{bodies_name} = $name;
- $row->external_body( 'Roads Service' );
- }
- push @{ $self->to }, [ $email, $name ];
- }
-
- return $all_confirmed && @{$self->to};
-}
-
-1;
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index f88dc09b8..c57f8af3b 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -380,10 +380,15 @@ for my $body (
{ area_id => 14279, name => 'Ballymoney Borough Council' },
{ area_id => 2636, name => 'Isle of Wight Council' },
{ area_id => 2649, name => 'Fife Council' },
+ { area_id => 14279, name => 'TransportNI (Western)' },
) {
my $aid = $body->{area_id};
my $body = $mech->create_body_ok($aid, $body->{name});
- $body_ids{$aid} = $body->id;
+ if ($body_ids{$aid}) {
+ $body_ids{$aid} = [ $body_ids{$aid}, $body->id ];
+ } else {
+ $body_ids{$aid} = $body->id;
+ }
push @bodies, $body;
}
@@ -409,11 +414,11 @@ for my $contact ( {
category => 'potholes',
email => 'highways@example.com',
}, {
- body_id => $body_ids{14279}, # Ballymoney
+ body_id => $body_ids{14279}[1], # TransportNI
category => 'Street lighting',
email => 'roads.western@drdni.example.org',
}, {
- body_id => $body_ids{14279}, # Ballymoney
+ body_id => $body_ids{14279}[0], # Ballymoney
category => 'Graffiti',
email => 'highways@example.com',
}, {
@@ -488,7 +493,7 @@ foreach my $test ( {
email_count => 1,
dear => qr'Dear Ballymoney Borough Council',
to => qr'Ballymoney Borough Council',
- body => $body_ids{14279},
+ body => $body_ids{14279}[0],
category => 'Graffiti',
longitude => -9.5,
}, {
@@ -496,9 +501,9 @@ foreach my $test ( {
desc => 'directs NI correctly, 2',
unset_whendef => 1,
email_count => 1,
- dear => qr'Dear Roads Service \(Western\)',
- to => qr'Roads Service \(Western\)" <roads',
- body => $body_ids{14279},
+ dear => qr'Dear TransportNI \(Western\)',
+ to => qr'TransportNI \(Western\)" <roads',
+ body => $body_ids{14279}[1],
category => 'Street lighting',
longitude => -9.5,
}, {
diff --git a/t/open311/endpoint/warwick.t b/t/open311/endpoint/warwick.t
index e144b745a..b51c601f3 100644
--- a/t/open311/endpoint/warwick.t
+++ b/t/open311/endpoint/warwick.t
@@ -212,6 +212,7 @@ subtest "End to end" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'fixmystreet' ],
SEND_REPORTS_ON_STAGING => 1,
+ MAPIT_URL => 'http://mapit.mysociety.org/',
}, sub {
## we can't (yet) just do following due to
## https://github.com/mysociety/fixmystreet/issues/893
diff --git a/templates/web/base/report/new/councils_text_all.html b/templates/web/base/report/new/councils_text_all.html
index 5e5ad13a0..9947625a5 100644
--- a/templates/web/base/report/new/councils_text_all.html
+++ b/templates/web/base/report/new/councils_text_all.html
@@ -1,20 +1,10 @@
-[%# XXX The below type checking is assuming that a body ID can be used to look up a mapit type. %]
<p>
-[% IF all_areas.${bodies_to_list.0}.type == 'LGD' %]
-[%
- tprintf(
- loc('All the information you provide here will be sent to <strong>%s</strong> or <strong>Roads Service</strong>.'),
- all_body_names.join( '</strong>' _ loc(' or ') _ '<strong>' )
- );
-%]
-[% ELSE %]
[%
tprintf(
loc('All the information you provide here will be sent to <strong>%s</strong>.'),
all_body_names.join( '</strong>' _ loc(' or ') _ '<strong>' )
);
%]
-[% END %]
[% INCLUDE 'report/new/councils_extra_text.html' %]
</p>