aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/SendReport
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/SendReport')
-rw-r--r--perllib/FixMyStreet/SendReport/Angus.pm167
-rw-r--r--perllib/FixMyStreet/SendReport/Blackhole.pm20
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm20
-rw-r--r--perllib/FixMyStreet/SendReport/Email/Highways.pm11
-rw-r--r--perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm28
-rw-r--r--perllib/FixMyStreet/SendReport/Email/TfL.pm11
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm3
7 files changed, 90 insertions, 170 deletions
diff --git a/perllib/FixMyStreet/SendReport/Angus.pm b/perllib/FixMyStreet/SendReport/Angus.pm
deleted file mode 100644
index 4ba5f3070..000000000
--- a/perllib/FixMyStreet/SendReport/Angus.pm
+++ /dev/null
@@ -1,167 +0,0 @@
-package FixMyStreet::SendReport::Angus;
-
-use Moo;
-
-BEGIN { extends 'FixMyStreet::SendReport'; }
-
-use Try::Tiny;
-use Encode;
-use XML::Simple;
-
-sub get_auth_token {
- my ($self, $authxml) = @_;
-
- my $xml = new XML::Simple;
- my $obj;
-
- eval {
- $obj = $xml->parse_string( $authxml );
- };
-
- my $success = $obj->{success};
- $success =~ s/^\s+|\s+$//g if defined $success;
- my $token = $obj->{AuthenticateResult};
- $token =~ s/^\s+|\s+$//g if defined $token;
-
- if (defined $success && $success eq 'True' && defined $token) {
- return $token;
- } else {
- $self->error("Couldn't authenticate against Angus endpoint.");
- }
-}
-
-sub get_external_id {
- my ($self, $resultxml) = @_;
-
- my $xml = new XML::Simple;
- my $obj;
-
- eval {
- $obj = $xml->parse_string( $resultxml );
- };
-
- my $success = $obj->{success};
- $success =~ s/^\s+|\s+$//g if defined $success;
- my $external_id = $obj->{CreateRequestResult}->{RequestId};
-
- if (defined $success && $success eq 'True' && defined $external_id) {
- return $external_id;
- } else {
- $self->error("Couldn't find external id in response from Angus endpoint.");
- return undef;
- }
-}
-
-sub crm_request_type {
- my ($self, $row, $h) = @_;
- return 'StLight'; # TODO: Set this according to report category
-}
-
-sub jadu_form_fields {
- my ($self, $row, $h) = @_;
- my $xml = XML::Simple->new(
- NoAttr=> 1,
- KeepRoot => 1,
- SuppressEmpty => 0,
- );
- my $metas = $row->get_extra_fields();
- my %extras;
- foreach my $field (@$metas) {
- $extras{$field->{name}} = $field->{value};
- }
- my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new();
- my $output = $xml->XMLout({
- formfields => {
- formfield => [
- {
- name => 'RequestTitle',
- value => $h->{title}
- },
- {
- name => 'RequestDetails',
- value => $h->{detail}
- },
- {
- name => 'ReporterName',
- value => $h->{name}
- },
- {
- name => 'ReporterEmail',
- value => $h->{email}
- },
- {
- name => 'ReporterAnonymity',
- value => $row->anonymous ? 'True' : 'False'
- },
- {
- name => 'ReportedDateTime',
- value => $h->{confirmed}
- },
- {
- name => 'ColumnId',
- value => $extras{'column_id'} || ''
- },
- {
- name => 'ReportId',
- value => $h->{id}
- },
- {
- name => 'ReportedNorthing',
- value => $h->{northing}
- },
- {
- name => 'ReportedEasting',
- value => $h->{easting}
- },
- {
- name => 'Imageurl1',
- value => $row->photos->[0] ? ($cobrand->base_url . $row->photos->[0]->{url_full}) : ''
- },
- {
- name => 'Imageurl2',
- value => $row->photos->[1] ? ($cobrand->base_url . $row->photos->[1]->{url_full}) : ''
- },
- {
- name => 'Imageurl3',
- value => $row->photos->[2] ? ($cobrand->base_url . $row->photos->[2]->{url_full}) : ''
- }
- ]
- }
- });
- # The endpoint crashes if the JADUFormFields string has whitespace between XML elements, so strip it out...
- $output =~ s/>[\s\n]+</></g;
- return $output;
-}
-
-sub send {
- my ( $self, $row, $h ) = @_;
-
- # FIXME: should not recreate this each time
- my $angus_service;
-
- require Integrations::AngusSOAP;
-
- my $return = 1;
- $angus_service ||= Integrations::AngusSOAP->on_fault(sub { my($soap, $res) = @_; die ref $res ? $res->faultstring : $soap->transport->status, "\n"; });
- try {
- my $authresult = $angus_service->AuthenticateJADU();
- my $authtoken = $self->get_auth_token( $authresult );
- # authenticationtoken, CallerId, CallerAddressId, DeliveryId, DeliveryAddressId, CRMRequestType, JADUXFormRef, PaymentRef, JADUFormFields
- my $result = $angus_service->CreateServiceRequest(
- $authtoken, '1', '1', '1', '1', $self->crm_request_type($row, $h),
- 'FMS', '', $self->jadu_form_fields($row, $h)
- );
- my $external_id = $self->get_external_id( $result );
- if ( $external_id ) {
- $row->external_id( $external_id );
- $return = 0;
- }
- } catch {
- my $e = $_;
- $self->error( "Error sending to Angus: $e" );
- };
- $self->success( !$return );
- return $return;
-}
-
-1;
diff --git a/perllib/FixMyStreet/SendReport/Blackhole.pm b/perllib/FixMyStreet/SendReport/Blackhole.pm
new file mode 100644
index 000000000..2c1a4fc8e
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/Blackhole.pm
@@ -0,0 +1,20 @@
+package FixMyStreet::SendReport::Blackhole;
+
+use Moo;
+
+BEGIN { extends 'FixMyStreet::SendReport'; }
+
+=head2 send
+
+Immediately marks the report as successfully sent, but doesn't actually send
+it anywhere.
+
+=cut
+
+sub send {
+ my $self = shift;
+ $self->success(1);
+ return 0;
+}
+
+1;
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index 583aaaa08..cd697fa0f 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -19,6 +19,9 @@ sub build_recipient_list {
my ($body_email, $state, $note) = ( $contact->email, $contact->state, $contact->note );
+ $body_email = swandt_contact($row->latitude, $row->longitude)
+ if ($body->areas->{2427} || $body->areas->{2429}) && $body_email eq 'SPECIAL';
+
unless ($state eq 'confirmed') {
$all_confirmed = 0;
$note = 'Body ' . $row->bodies_str . ' deleted'
@@ -57,7 +60,7 @@ sub send {
my $self = shift;
my ( $row, $h ) = @_;
- my $recips = $self->build_recipient_list( $row, $h );
+ my $recips = @{$self->to} ? 1 : $self->build_recipient_list( $row, $h );
# on a staging server send emails to ourselves rather than the bodies
if (FixMyStreet->staging_flag('send_reports', 0) && !FixMyStreet->test_mode) {
@@ -71,7 +74,9 @@ sub send {
}
my ($verbose, $nomail) = CronFns::options();
- my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new();
+ my $cobrand = $row->get_cobrand_logged;
+ $cobrand = $cobrand->call_hook(get_body_handler_for_problem => $row) || $cobrand;
+
my $params = {
To => $self->to,
};
@@ -109,10 +114,19 @@ sub send {
return $result;
}
+# SW&T has different contact addresses depending upon the old district
+sub swandt_contact {
+ my $district = _get_district_for_contact(@_);
+ my $email;
+ $email = ['customerservices', 'westsomerset'] if $district == 2427;
+ $email = ['enquiries', 'tauntondeane'] if $district == 2429;
+ return join('@', $email->[0], $email->[1] . '.gov.uk');
+}
+
sub _get_district_for_contact {
my ( $lat, $lon ) = @_;
my $district =
- mySociety::MaPit::call( 'point', "4326/$lon,$lat", type => 'DIS' );
+ FixMyStreet::MapIt::call( 'point', "4326/$lon,$lat", type => 'DIS' );
($district) = keys %$district;
return $district;
}
diff --git a/perllib/FixMyStreet/SendReport/Email/Highways.pm b/perllib/FixMyStreet/SendReport/Email/Highways.pm
new file mode 100644
index 000000000..2a1f7b305
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/Email/Highways.pm
@@ -0,0 +1,11 @@
+package FixMyStreet::SendReport::Email::Highways;
+
+use Moo;
+extends 'FixMyStreet::SendReport::Email::SingleBodyOnly';
+
+has contact => (
+ is => 'ro',
+ default => 'Pothole'
+);
+
+1;
diff --git a/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm b/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm
new file mode 100644
index 000000000..cf778c549
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm
@@ -0,0 +1,28 @@
+package FixMyStreet::SendReport::Email::SingleBodyOnly;
+
+use Moo;
+extends 'FixMyStreet::SendReport::Email';
+
+has contact => (
+ is => 'ro',
+ default => sub { die 'Need to override contact' }
+);
+
+sub build_recipient_list {
+ my ( $self, $row, $h ) = @_;
+
+ return unless @{$self->bodies} == 1;
+ my $body = $self->bodies->[0];
+
+ # We don't care what the category was, look up the relevant contact
+ my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find({
+ body_id => $body->id,
+ category => $self->contact,
+ });
+ return unless $contact;
+
+ @{$self->to} = map { [ $_, $body->name ] } split /,/, $contact->email;
+ return 1;
+}
+
+1;
diff --git a/perllib/FixMyStreet/SendReport/Email/TfL.pm b/perllib/FixMyStreet/SendReport/Email/TfL.pm
new file mode 100644
index 000000000..383df9792
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/Email/TfL.pm
@@ -0,0 +1,11 @@
+package FixMyStreet::SendReport::Email::TfL;
+
+use Moo;
+extends 'FixMyStreet::SendReport::Email::SingleBodyOnly';
+
+has contact => (
+ is => 'ro',
+ default => 'Traffic lights'
+);
+
+1;
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
index 84aa851ed..a661ff206 100644
--- a/perllib/FixMyStreet/SendReport/Open311.pm
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -29,6 +29,7 @@ sub send {
use_service_as_deviceid => 0,
extended_description => 1,
multi_photos => 0,
+ fixmystreet_body => $body,
);
my $cobrand = $body->get_cobrand_handler || $row->get_cobrand_logged;
@@ -94,6 +95,8 @@ sub send {
$self->error( "Failed to send over Open311\n" ) unless $self->error;
$self->error( $self->error . "\n" . $open311->error );
}
+
+ $cobrand->call_hook(open311_post_send => $row, $h);
}