diff options
Diffstat (limited to 'perllib/FixMyStreet/SendReport')
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 38 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email/Highways.pm | 24 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email/TfL.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Noop.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 24 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Triage.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Zurich.pm | 5 |
8 files changed, 82 insertions, 51 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index cd697fa0f..72cd42952 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -12,23 +12,20 @@ sub build_recipient_list { my $all_confirmed = 1; foreach my $body ( @{ $self->bodies } ) { - my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find( { - body_id => $body->id, - category => $row->category - } ); + my $contact = $self->fetch_category($body, $row) or next; 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'; + if $body->name eq 'Somerset West and Taunton Council' && $body_email eq 'SPECIAL'; unless ($state eq 'confirmed') { $all_confirmed = 0; $note = 'Body ' . $row->bodies_str . ' deleted' unless $note; $body_email = 'N/A' unless $body_email; - $self->unconfirmed_counts->{$body_email}{$row->category}++; - $self->unconfirmed_notes->{$body_email}{$row->category} = $note; + $self->unconfirmed_data->{$body_email}{$row->category}{count}++; + $self->unconfirmed_data->{$body_email}{$row->category}{note} = $note; } my @emails; @@ -56,6 +53,15 @@ sub send_from { return [ $row->user->email, $row->name ]; } +sub envelope_sender { + my ($self, $row) = @_; + + if ($row->user->email && $row->user->email_verified) { + return FixMyStreet::Email::unique_verp_id('report', $row->id); + } + return $row->get_cobrand_logged->do_not_reply_email; +} + sub send { my $self = shift; my ( $row, $h ) = @_; @@ -85,12 +91,10 @@ sub send { $params->{Bcc} = $self->bcc if @{$self->bcc}; - my $sender; + my $sender = $self->envelope_sender($row); if ($row->user->email && $row->user->email_verified) { - $sender = FixMyStreet::Email::unique_verp_id('report', $row->id); $params->{From} = $self->send_from( $row ); } else { - $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL'); my $name = sprintf(_("On behalf of %s"), @{ $self->send_from($row) }[1]); $params->{From} = [ $sender, $name ]; } @@ -102,10 +106,14 @@ sub send { } my $result = FixMyStreet::Email::send_cron($row->result_source->schema, - $self->get_template($row), $h, + $self->get_template($row), { + %$h, + cobrand => $cobrand, # For correct logo that uses cobrand object + }, $params, $sender, $nomail, $cobrand, $row->lang); unless ($result) { + $row->set_extra_metadata('sent_to' => email_list($params->{To})); $self->success(1); } else { $self->error( 'Failed to send email' ); @@ -114,6 +122,12 @@ sub send { return $result; } +sub email_list { + my $list = shift; + my @list = map { ref $_ ? $_->[0] : $_ } @$list; + return \@list; +} + # SW&T has different contact addresses depending upon the old district sub swandt_contact { my $district = _get_district_for_contact(@_); @@ -126,7 +140,7 @@ sub swandt_contact { sub _get_district_for_contact { my ( $lat, $lon ) = @_; my $district = - FixMyStreet::MapIt::call( 'point', "4326/$lon,$lat", type => 'DIS' ); + FixMyStreet::MapIt::call( 'point', "4326/$lon,$lat", type => 'DIS', generation => 34 ); ($district) = keys %$district; return $district; } diff --git a/perllib/FixMyStreet/SendReport/Email/Highways.pm b/perllib/FixMyStreet/SendReport/Email/Highways.pm index 2a1f7b305..2bcd120d3 100644 --- a/perllib/FixMyStreet/SendReport/Email/Highways.pm +++ b/perllib/FixMyStreet/SendReport/Email/Highways.pm @@ -1,11 +1,25 @@ package FixMyStreet::SendReport::Email::Highways; use Moo; -extends 'FixMyStreet::SendReport::Email::SingleBodyOnly'; +extends 'FixMyStreet::SendReport::Email'; -has contact => ( - is => 'ro', - default => 'Pothole' -); +sub build_recipient_list { + my ( $self, $row, $h ) = @_; + + return unless @{$self->bodies} == 1; + my $body = $self->bodies->[0]; + + my $contact = $self->fetch_category($body, $row) or return; + my $email = $contact->email; + my $area_name = $row->get_extra_field_value('area_name') || ''; + if ($area_name eq 'Area 7') { + my $a7email = FixMyStreet->config('COBRAND_FEATURES') || {}; + $a7email = $a7email->{open311_email}->{highwaysengland}->{area_seven}; + $email = $a7email if $a7email; + } + + @{$self->to} = map { [ $_, $body->name ] } split /,/, $email; + return 1; +} 1; diff --git a/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm b/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm index cf778c549..1ae938317 100644 --- a/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm +++ b/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm @@ -15,11 +15,7 @@ sub build_recipient_list { 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; + my $contact = $self->fetch_category($body, $row, $self->contact) or return; @{$self->to} = map { [ $_, $body->name ] } split /,/, $contact->email; return 1; diff --git a/perllib/FixMyStreet/SendReport/Email/TfL.pm b/perllib/FixMyStreet/SendReport/Email/TfL.pm deleted file mode 100644 index 383df9792..000000000 --- a/perllib/FixMyStreet/SendReport/Email/TfL.pm +++ /dev/null @@ -1,11 +0,0 @@ -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/Noop.pm b/perllib/FixMyStreet/SendReport/Noop.pm index 60edda373..933291b7c 100644 --- a/perllib/FixMyStreet/SendReport/Noop.pm +++ b/perllib/FixMyStreet/SendReport/Noop.pm @@ -4,9 +4,4 @@ use Moo; BEGIN { extends 'FixMyStreet::SendReport'; } -# Always skip when using this method -sub should_skip { - return 1; -} - 1; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index a661ff206..e8e840ef5 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -29,20 +29,26 @@ sub send { use_service_as_deviceid => 0, extended_description => 1, multi_photos => 0, + upload_files => 0, + always_upload_photos => 0, fixmystreet_body => $body, ); + my $contact = $self->fetch_category($body, $row) or next; + my $cobrand = $body->get_cobrand_handler || $row->get_cobrand_logged; $cobrand->call_hook(open311_config => $row, $h, \%open311_params); # Try and fill in some ones that we've been asked for, but not asked the user for - - my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find( { - body_id => $body->id, - category => $row->category - } ); - my $extra = $row->get_extra_fields(); + my ($include, $exclude) = $cobrand->call_hook(open311_extra_data => $row, $h, $extra, $contact); + + my $original_extra = [ @$extra ]; + push @$extra, @$include if $include; + if ($exclude) { + $exclude = join('|', @$exclude); + @$extra = grep { $_->{name} !~ /$exclude/ } @$extra; + } my $id_field = $contact->id_field; foreach (@{$contact->get_extra_fields}) { @@ -83,8 +89,8 @@ sub send { $self->open311_test_req_used($open311->test_req_used); } - # make sure we don't save user changes from above - $row->discard_changes(); + # make sure we don't save extra changes from above + $row->set_extra_fields( @$original_extra ); if ( $resp ) { $row->external_id( $resp ); @@ -96,7 +102,7 @@ sub send { $self->error( $self->error . "\n" . $open311->error ); } - $cobrand->call_hook(open311_post_send => $row, $h); + $cobrand->call_hook(open311_post_send => $row, $h, $contact); } diff --git a/perllib/FixMyStreet/SendReport/Triage.pm b/perllib/FixMyStreet/SendReport/Triage.pm new file mode 100644 index 000000000..38341f3ff --- /dev/null +++ b/perllib/FixMyStreet/SendReport/Triage.pm @@ -0,0 +1,20 @@ +package FixMyStreet::SendReport::Triage; + +use Moo; + +BEGIN { extends 'FixMyStreet::SendReport'; } + +sub send { + my $self = shift; + my ( $row, $h ) = @_; + + $row->update({ + state => 'for triage' + }); + + $self->success(1); + + return 0; +} + +1; diff --git a/perllib/FixMyStreet/SendReport/Zurich.pm b/perllib/FixMyStreet/SendReport/Zurich.pm index 59adfd688..7416c64f9 100644 --- a/perllib/FixMyStreet/SendReport/Zurich.pm +++ b/perllib/FixMyStreet/SendReport/Zurich.pm @@ -29,10 +29,7 @@ sub build_recipient_list { my $parent = $body->parent; if ($parent && !$parent->parent) { # Division, might have an individual contact email address - my $contact = $row->result_source->schema->resultset("Contact")->find( { - body_id => $body->id, - category => $row->category - } ); + my $contact = $self->fetch_category($body, $row); $body_email = $contact->email if $contact && $contact->email; } |