aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/SendReport
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/SendReport')
-rw-r--r--perllib/FixMyStreet/SendReport/Barnet.pm8
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm37
-rw-r--r--perllib/FixMyStreet/SendReport/EmptyHomes.pm23
-rw-r--r--perllib/FixMyStreet/SendReport/NI.pm8
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm55
-rw-r--r--perllib/FixMyStreet/SendReport/Zurich.pm58
6 files changed, 129 insertions, 60 deletions
diff --git a/perllib/FixMyStreet/SendReport/Barnet.pm b/perllib/FixMyStreet/SendReport/Barnet.pm
index 9a92686ec..05ca20809 100644
--- a/perllib/FixMyStreet/SendReport/Barnet.pm
+++ b/perllib/FixMyStreet/SendReport/Barnet.pm
@@ -80,9 +80,9 @@ sub send {
? $h{query} : $nearest_postcode; # use given postcode if available
# note: endpoint can be of form 'https://username:password@url'
- my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => COUNCIL_ID_BARNET} )->first;
- if ($council_config and $council_config->endpoint) {
- $interface->set_proxy($council_config->endpoint);
+ my $body = FixMyStreet::App->model("DB::Body")->search( { 'body_areas.area_id' => COUNCIL_ID_BARNET }, { join => "body_areas" } )->first;
+ if ($body and $body->endpoint) {
+ $interface->set_proxy($body->endpoint);
# Barnet web service doesn't like namespaces in the elements so use a prefix
$interface->set_prefix('urn');
# uncomment these lines to print XML that will be sent rather
@@ -90,7 +90,7 @@ sub send {
#$interface->outputxml(1);
#$interface->no_dispatch(1);
} else {
- die "Barnet webservice FAIL: looks like you're missing some config data: no endpoint (URL) found for area_id=" . COUNCIL_ID_BARNET;
+ die "Barnet webservice FAIL: looks like you're missing some config data: no endpoint (URL) found for area ID " . COUNCIL_ID_BARNET;
}
eval {
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index f26116bc4..1ff476da3 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -11,36 +11,36 @@ sub build_recipient_list {
my %recips;
my $all_confirmed = 1;
- foreach my $council ( keys %{ $self->councils } ) {
+ foreach my $body ( @{ $self->bodies } ) {
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
- area_id => $council,
+ body_id => $body->id,
category => $row->category
} );
- my ($council_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note );
+ my ($body_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note );
- $council_email = essex_contact($row->latitude, $row->longitude) if $council == 2225;
- $council_email = oxfordshire_contact($row->latitude, $row->longitude) if $council == 2237 && $council_email eq 'SPECIAL';
+ $body_email = essex_contact($row->latitude, $row->longitude) if $body->areas->{2225};
+ $body_email = oxfordshire_contact($row->latitude, $row->longitude) if $body->areas->{2237} && $body_email eq 'SPECIAL';
unless ($confirmed) {
$all_confirmed = 0;
- $note = 'Council ' . $row->council . ' deleted'
+ $note = 'Body ' . $row->bodies_str . ' deleted'
unless $note;
- $council_email = 'N/A' unless $council_email;
- $self->unconfirmed_counts->{$council_email}{$row->category}++;
- $self->unconfirmed_notes->{$council_email}{$row->category} = $note;
+ $body_email = 'N/A' unless $body_email;
+ $self->unconfirmed_counts->{$body_email}{$row->category}++;
+ $self->unconfirmed_notes->{$body_email}{$row->category} = $note;
}
# see something uses council areas but doesn't send to councils so just use a
# generic name here to minimise confusion
if ( $row->cobrand eq 'seesomething' ) {
- push @{ $self->to }, [ $council_email, 'See Something, Say Something' ];
+ push @{ $self->to }, [ $body_email, 'See Something, Say Something' ];
} else {
- push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{info}->{name} ];
+ push @{ $self->to }, [ $body_email, $body->name ];
}
- $recips{$council_email} = 1;
+ $recips{$body_email} = 1;
}
return () unless $all_confirmed;
@@ -51,7 +51,7 @@ sub get_template {
my ( $self, $row ) = @_;
my $template = 'submit.txt';
- $template = 'submit-brent.txt' if $row->council eq 2488 || $row->council eq 2237;
+ $template = 'submit-brent.txt' if $row->bodies_str eq 2488 || $row->bodies_str eq 2237;
my $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $row->lang, $template )->stringify;
$template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $template )->stringify
unless -e $template_path;
@@ -61,14 +61,19 @@ sub get_template {
return $template;
}
+sub send_from {
+ my ( $self, $row ) = @_;
+ return [ $row->user->email, $row->name ];
+}
+
sub send {
my $self = shift;
my ( $row, $h ) = @_;
my @recips = $self->build_recipient_list( $row, $h );
- # on a staging server send emails to ourselves rather than the councils
- if (mySociety::Config::get('STAGING_SITE') && !FixMyStreet->test_mode) {
+ # on a staging server send emails to ourselves rather than the bodies
+ if (mySociety::Config::get('STAGING_SITE') && !mySociety::Config::get('SEND_REPORTS_ON_STAGING') && !FixMyStreet->test_mode) {
@recips = ( mySociety::Config::get('CONTACT_EMAIL') );
}
@@ -83,7 +88,7 @@ sub send {
_template_ => $self->get_template( $row ),
_parameters_ => $h,
To => $self->to,
- From => [ $row->user->email, $row->name ],
+ From => $self->send_from( $row ),
},
mySociety::Config::get('CONTACT_EMAIL'),
\@recips,
diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm
index 4a6f058fe..b29c1fd3c 100644
--- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm
+++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm
@@ -3,6 +3,8 @@ package FixMyStreet::SendReport::EmptyHomes;
use Moose;
use namespace::autoclean;
+use mySociety::MaPit;
+
BEGIN { extends 'FixMyStreet::SendReport::Email'; }
sub build_recipient_list {
@@ -10,28 +12,29 @@ sub build_recipient_list {
my %recips;
my $all_confirmed = 1;
- foreach my $council ( keys %{ $self->councils } ) {
+ foreach my $body ( @{ $self->bodies } ) {
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
- area_id => $council,
+ body_id => $body->id,
category => 'Empty property',
} );
- my ($council_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note );
+ my ($body_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note );
unless ($confirmed) {
$all_confirmed = 0;
- #$note = 'Council ' . $row->council . ' deleted'
+ #$note = 'Council ' . $row->body . ' deleted'
#unless $note;
- $council_email = 'N/A' unless $council_email;
- #$notgot{$council_email}{$row->category}++;
- #$note{$council_email}{$row->category} = $note;
+ $body_email = 'N/A' unless $body_email;
+ #$notgot{$body_email}{$row->category}++;
+ #$note{$body_email}{$row->category} = $note;
}
- push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{ info }->{name} ];
- $recips{$council_email} = 1;
+ push @{ $self->to }, [ $body_email, $body->name ];
+ $recips{$body_email} = 1;
- my $country = $self->councils->{$council}->{country};
+ my $area_info = mySociety::MaPit::call('area', $body->area_id);
+ my $country = $area_info->{country};
if ($country eq 'W') {
$recips{ 'shelter@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1;
} else {
diff --git a/perllib/FixMyStreet/SendReport/NI.pm b/perllib/FixMyStreet/SendReport/NI.pm
index 810ee60e2..e0ea24f9c 100644
--- a/perllib/FixMyStreet/SendReport/NI.pm
+++ b/perllib/FixMyStreet/SendReport/NI.pm
@@ -9,10 +9,10 @@ sub build_recipient_list {
my %recips;
my $all_confirmed = 1;
- foreach my $council ( keys %{ $self->councils } ) {
+ foreach my $body ( @{ $self->bodies } ) {
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
- area_id => $council,
+ body_id => $body->id,
category => $row->category
} );
@@ -23,10 +23,10 @@ sub build_recipient_list {
$email = 'N/A' unless $email;
}
- my $name = $self->councils->{$council}->{info}->{name};
+ my $name = $body->name;
if ( $email =~ /^roads.([^@]*)\@drdni/ ) {
$name = "Roads Service (\u$1)";
- $h->{councils_name} = $name;
+ $h->{bodies_name} = $name;
$row->external_body( 'Roads Service' );
}
push @{ $self->to }, [ $email, $name ];
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
index 93b96ce00..61f59f725 100644
--- a/perllib/FixMyStreet/SendReport/Open311.pm
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -30,8 +30,8 @@ sub send {
my $result = -1;
- foreach my $council ( keys %{ $self->councils } ) {
- my $conf = $self->councils->{$council}->{config};
+ foreach my $body ( @{ $self->bodies } ) {
+ my $conf = $self->body_config->{ $body->id };
my $always_send_latlong = 1;
my $send_notpinpointed = 0;
@@ -39,8 +39,13 @@ sub send {
my $extended_desc = 1;
+ # To rollback temporary changes made by this function
+ my $revert = 0;
+
# Extra bromley fields
- if ( $row->council =~ /2482/ ) {
+ if ( $row->bodies_str == 2482 ) {
+
+ $revert = 1;
my $extra = $row->extra;
if ( $row->used_map || ( !$row->used_map && !$row->postcode ) ) {
@@ -71,7 +76,7 @@ sub send {
}
# extra Oxfordshire fields: send nearest street, postcode, northing and easting, and the FMS id
- if ( $row->council =~ /$COUNCIL_ID_OXFORDSHIRE/ ) {
+ if ( $row->bodies_str =~ /$COUNCIL_ID_OXFORDSHIRE/ ) {
my $extra = $row->extra;
push @$extra, { name => 'external_id', value => $row->id };
@@ -88,11 +93,11 @@ sub send {
# FIXME: we've already looked this up before
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
- area_id => $conf->area_id,
+ body_id => $body->id,
category => $row->category
} );
- my $open311 = Open311->new(
+ my %open311_params = (
jurisdiction => $conf->jurisdiction,
endpoint => $conf->endpoint,
api_key => $conf->api_key,
@@ -101,56 +106,54 @@ sub send {
use_service_as_deviceid => $use_service_as_deviceid,
extended_description => $extended_desc,
);
+ if (FixMyStreet->test_mode) {
+ my $test_res = HTTP::Response->new();
+ $test_res->code(200);
+ $test_res->message('OK');
+ $test_res->content('<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>');
+ $open311_params{test_mode} = 1;
+ $open311_params{test_get_returns} = { 'requests.xml' => $test_res };
+ }
+
+ my $open311 = Open311->new( %open311_params );
# non standard west berks end points
- if ( $row->council =~ /2619/ ) {
+ if ( $row->bodies_str =~ /2619/ ) {
$open311->endpoints( { services => 'Services', requests => 'Requests' } );
}
# non-standard Oxfordshire endpoint (because it's just a script, not a full Open311 service)
- if ( $row->council =~ /$COUNCIL_ID_OXFORDSHIRE/ ) {
+ if ( $row->bodies_str =~ /$COUNCIL_ID_OXFORDSHIRE/ ) {
$open311->endpoints( { requests => 'open311_service_request.cgi' } );
+ $revert = 1;
}
# required to get round issues with CRM constraints
- if ( $row->council =~ /2218/ ) {
+ if ( $row->bodies_str =~ /2218/ ) {
$row->user->name( $row->user->id . ' ' . $row->user->name );
+ $revert = 1;
}
if ($row->cobrand eq 'fixmybarangay') {
# FixMyBarangay endpoints expect external_id as an attribute, as do Oxfordshire
$row->extra( [ { 'name' => 'external_id', 'value' => $row->id } ] );
+ $revert = 1;
}
my $resp = $open311->send_service_request( $row, $h, $contact->email );
# make sure we don't save user changes from above
- if ( $row->council =~ /(2218|2482|$COUNCIL_ID_OXFORDSHIRE)/ || $row->cobrand eq 'fixmybarangay') {
- $row->discard_changes();
- }
+ $row->discard_changes() if $revert;
if ( $resp ) {
$row->external_id( $resp );
$row->send_method_used('Open311');
- if ($row->cobrand eq 'fixmybarangay') {
- # FixMyBarangay: currently the external bodies using Open311 are DPS, DEPW, DPWH
- # for now identify the latter two by their name in the service_code ($contact->email)
- # So: this works because we are anticipating the service codes for (e.g., potholes) look
- # like this:
- # POTDEPW or POTDPWH
- # (TODO: this will change when we have 'body' logic in place, meanwhile: hardcoded)
- if ($contact->email =~ /(DEPW|DPWH)$/i) {
- $row->external_body(uc $1); # body is DEPW (city roads) or DPWH (national roads)
- } else {
- $row->external_body("DPS"); # only other open311 dept is DPS
- }
- }
$result *= 0;
$self->success( 1 );
} else {
$result *= 1;
# temporary fix to resolve some issues with west berks
- if ( $row->council =~ /2619/ ) {
+ if ( $row->bodies_str =~ /2619/ ) {
$result *= 0;
}
}
diff --git a/perllib/FixMyStreet/SendReport/Zurich.pm b/perllib/FixMyStreet/SendReport/Zurich.pm
new file mode 100644
index 000000000..e0c95283e
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/Zurich.pm
@@ -0,0 +1,58 @@
+package FixMyStreet::SendReport::Zurich;
+
+use Moose;
+
+BEGIN { extends 'FixMyStreet::SendReport::Email'; }
+
+sub build_recipient_list {
+ my ( $self, $row, $h ) = @_;
+
+ # Only one body ever, most of the time with an email endpoint
+ my $body = @{ $self->bodies }[0];
+ $body = FixMyStreet::App->model("DB::Body")->find( { id => $row->external_body } )
+ if $row->external_body;
+ my $body_email = $body->endpoint;
+
+ my @bodies = $body->bodies;
+ if ($body->parent && @bodies) {
+ # Division, might have an individual contact email address
+ my $contact = FixMyStreet::App->model("DB::Contact")->find( {
+ body_id => $body->id,
+ category => $row->category
+ } );
+ $body_email = $contact->email if $contact && $contact->email;
+ }
+
+ push @{ $self->to }, [ $body_email, $body->name ];
+ return $body_email;
+}
+
+sub get_template {
+ my ( $self, $row ) = @_;
+
+ my $template;
+ if ( $row->state eq 'unconfirmed' || $row->state eq 'confirmed' ) {
+ $template = 'submit.txt';
+ } elsif ( $row->state eq 'in progress' ) {
+ $template = 'submit-in-progress.txt';
+ } elsif ( $row->state eq 'planned' ) {
+ $template = 'submit-feedback-pending.txt';
+ } elsif ( $row->state eq 'closed' ) {
+ $template = 'submit-external.txt';
+ if ( $row->extra->{third_personal} ) {
+ $template = 'submit-external-personal.txt';
+ }
+ }
+
+ my $template_path = FixMyStreet->path_to( "templates", "email", "zurich", $template )->stringify;
+ $template = Utils::read_file( $template_path );
+ return $template;
+}
+
+# Zurich emails come from the site itself
+sub send_from {
+ my ( $self, $row ) = @_;
+ return [ FixMyStreet->config('CONTACT_EMAIL'), FixMyStreet->config('CONTACT_NAME') ];
+}
+
+1;