diff options
Diffstat (limited to 'perllib/FixMyStreet/SendReport')
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 27 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/London.pm | 113 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/NI.pm | 37 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 23 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Refused.pm | 7 |
5 files changed, 18 insertions, 189 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 4507091c7..fa4d437fb 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -18,9 +18,6 @@ sub build_recipient_list { my ($body_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note ); - $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 = 'Body ' . $row->bodies_str . ' deleted' @@ -112,30 +109,6 @@ sub send { return $result; } -# Essex has different contact addresses depending upon the district -# Might be easier if we start storing in the db all areas covered by a point -# Will do for now :) -sub essex_contact { - my $district = _get_district_for_contact(@_); - my $email; - $email = 'eastarea' if $district == 2315 || $district == 2312; - $email = 'midarea' if $district == 2317 || $district == 2314 || $district == 2316; - $email = 'southarea' if $district == 2319 || $district == 2320 || $district == 2310; - $email = 'westarea' if $district == 2309 || $district == 2311 || $district == 2318 || $district == 2313; - die "Returned district $district which is not in Essex!" unless $email; - return "highways.$email\@essexcc.gov.uk"; -} - -# Oxfordshire has different contact addresses depending upon the district -sub oxfordshire_contact { - my $district = _get_district_for_contact(@_); - my $email; - $email = 'northernarea' if $district == 2419 || $district == 2420 || $district == 2421; - $email = 'southernarea' if $district == 2417 || $district == 2418; - die "Returned district $district which is not in Oxfordshire!" unless $email; - return "$email\@oxfordshire.gov.uk"; -} - sub _get_district_for_contact { my ( $lat, $lon ) = @_; my $district = diff --git a/perllib/FixMyStreet/SendReport/London.pm b/perllib/FixMyStreet/SendReport/London.pm deleted file mode 100644 index 2a1ebc1c3..000000000 --- a/perllib/FixMyStreet/SendReport/London.pm +++ /dev/null @@ -1,113 +0,0 @@ -package FixMyStreet::SendReport::London; - -use Moose; - -BEGIN { extends 'FixMyStreet::SendReport'; } - -use Digest::MD5; -use FindBin; -use LWP::UserAgent; -use LWP::Simple; - -use Utils; - -sub construct_message { - my %h = @_; - return <<EOF, -A user of FixMyStreet has submitted the following report of a local -problem that they believe might require your attention. - -Subject: $h{title} - -Details: $h{detail} - -$h{fuzzy}, or to provide an update on the problem, please visit the -following link: - -$h{url} - -$h{closest_address} -Yours, -The FixMyStreet team -EOF -} - -sub send { - return if mySociety::Config::get('STAGING_SITE'); - my ( $self, $row, $h ) = @_; - - $h->{message} = construct_message( %$h ); - my $phone = $h->{phone}; - my $mobile = ''; - if ($phone && $phone =~ /^\s*07/) { - $mobile = $phone; - $phone = ''; - } - my ($first, $last) = $h->{name} =~ /^(\S*)(?: (.*))?$/; - my %params = ( - Key => mySociety::Config::get('LONDON_REPORTIT_KEY'), - Signature => Digest::MD5::md5_hex( $h->{confirmed} . mySociety::Config::get('LONDON_REPORTIT_SECRET') ), - Type => Utils::london_categories()->{$h->{category}}, - RequestDate => $h->{confirmed}, - RequestMethod => 'Web', - ExternalId => $h->{url}, - 'Customer.Title' => '', - 'Customer.FirstName' => $first, - 'Customer.Surname' => $last, - 'Customer.Email' => $h->{email}, - 'Customer.Phone' => $phone, - 'Customer.Mobile' => $mobile, - 'ProblemDescription' => $h->{message}, - ); - if ($h->{used_map}) { - $params{'Location.Latitude'} = $h->{latitude}; - $params{'Location.Longitude'} = $h->{longitude}; - } elsif (mySociety::PostcodeUtil::is_valid_postcode($h->{query})) { - # Didn't use map, and entered postcode, so use that. - $params{'Location.Postcode'} = $h->{query}; - } else { - # Otherwise, lat/lon is all we have, even if it's wrong. - $params{'Location.Latitude'} = $h->{latitude}; - $params{'Location.Longitude'} = $h->{longitude}; - } - if ($h->{has_photo}) { - $params{'Document1.Name'} = 'Photograph'; - $params{'Document1.MimeType'} = 'image/jpeg'; - $params{'Document1.URL'} = $h->{image_url}; - $params{'Document1.URLPublic'} = 'true'; - } - my $browser = LWP::UserAgent->new; - my $response = $browser->post( mySociety::Config::get('LONDON_REPORTIT_URL'), \%params ); - my $out = $response->content; - if ($response->code ne 200) { - $self->error( "Failed to post $h->{id} to London API, response was " . $response->code . " $out" ); - return 1; - } - my ($id) = $out =~ /<caseid>(.*?)<\/caseid>/; - my ($org) = $out =~ /<organisation>(.*?)<\/organisation>/; - my ($team) = $out =~ /<team>(.*?)<\/team>/; - - $org = london_lookup($org); - $row->external_id( $id ); - $row->external_body( $org ); - $row->external_team( $team ); - $self->success(1); - return 0; -} - -sub london_lookup { - my $org = shift || ''; - my $str = "Unknown ($org)"; - open(FP, "$FindBin::Bin/../data/dft.csv"); - while (<FP>) { - /^(.*?),(.*)/; - if ($org eq $1) { - $str = $2; - last; - } - } - close FP; - return $str; -} - -1; 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/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index c064eeef5..fa216466e 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -13,6 +13,7 @@ use Readonly; Readonly::Scalar my $COUNCIL_ID_OXFORDSHIRE => 2237; Readonly::Scalar my $COUNCIL_ID_WARWICKSHIRE => 2243; +Readonly::Scalar my $COUNCIL_ID_GREENWICH => 2493; sub send { my $self = shift; @@ -37,7 +38,7 @@ sub send { $revert = 1; - my $extra = $row->extra; + my $extra = $row->get_extra_fields(); if ( $row->used_map || ( !$row->used_map && !$row->postcode ) ) { push @$extra, { name => 'northing', value => $h->{northing} }; push @$extra, { name => 'easting', value => $h->{easting} }; @@ -49,33 +50,31 @@ sub send { push @$extra, { name => 'email_alerts_requested', value => 'FALSE' }; # always false as can never request them push @$extra, { name => 'requested_datetime', value => DateTime::Format::W3CDTF->format_datetime($row->confirmed->set_nanosecond(0)) }; push @$extra, { name => 'email', value => $row->user->email }; - $row->extra( $extra ); - - $always_send_latlong = 0; - $send_notpinpointed = 1; - $use_service_as_deviceid = 0; - # make sure we have last_name attribute present in row's extra, so # it is passed correctly to Bromley as attribute[] if ( $row->cobrand ne 'bromley' ) { my ( $firstname, $lastname ) = ( $row->name =~ /(\w+)\.?\s+(.+)/ ); push @$extra, { name => 'last_name', value => $lastname }; } + $row->set_extra_fields( @$extra ); + $always_send_latlong = 0; + $send_notpinpointed = 1; + $use_service_as_deviceid = 0; $extended_desc = 0; } # extra Oxfordshire fields: send nearest street, postcode, northing and easting, and the FMS id if ( $row->bodies_str =~ /\b(?:$COUNCIL_ID_OXFORDSHIRE|$COUNCIL_ID_WARWICKSHIRE)\b/ ) { - my $extra = $row->extra; + my $extra = $row->get_extra_fields; push @$extra, { name => 'external_id', value => $row->id }; push @$extra, { name => 'closest_address', value => $h->{closest_address} } if $h->{closest_address}; if ( $row->used_map || ( !$row->used_map && !$row->postcode ) ) { push @$extra, { name => 'northing', value => $h->{northing} }; push @$extra, { name => 'easting', value => $h->{easting} }; } - $row->extra( $extra ); + $row->set_extra_fields( @$extra ); if ($row->bodies_str =~ /$COUNCIL_ID_OXFORDSHIRE/) { $extended_desc = 'oxfordshire'; @@ -129,9 +128,9 @@ sub send { $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 } ] ); + if ($row->cobrand eq 'fixmybarangay' || $row->bodies_str =~ /$COUNCIL_ID_GREENWICH/) { + # FixMyBarangay endpoints expect external_id as an attribute, as do Greenwich + $row->set_extra_fields( { 'name' => 'external_id', 'value' => $row->id } ); $revert = 1; } diff --git a/perllib/FixMyStreet/SendReport/Refused.pm b/perllib/FixMyStreet/SendReport/Refused.pm new file mode 100644 index 000000000..d71fc5c2c --- /dev/null +++ b/perllib/FixMyStreet/SendReport/Refused.pm @@ -0,0 +1,7 @@ +package FixMyStreet::SendReport::Refused; + +use Moose; + +BEGIN { extends 'FixMyStreet::SendReport::Noop'; } + +1; |