diff options
Diffstat (limited to 'perllib/FixMyStreet')
46 files changed, 354 insertions, 136 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index e5e483937..769a6bb8f 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -10,9 +10,9 @@ use FixMyStreet; use FixMyStreet::Cobrand; use Memcached; use mySociety::Email; -use mySociety::EmailUtil; use mySociety::Random qw(random_bytes); use FixMyStreet::Map; +use Utils; use Path::Class; use URI; @@ -348,9 +348,19 @@ sub send_email { } sub send_email_cron { - my ( $c, $params, $env_from, $env_to, $nomail, $cobrand, $lang_code ) = @_; - - return 1 if $c->is_abuser( $env_to ); + my ( $c, $params, $env_from, $nomail, $cobrand, $lang_code ) = @_; + + my $first_to; + if (ref($params->{To}) eq 'ARRAY') { + if (ref($params->{To}[0]) eq 'ARRAY') { + $first_to = $params->{To}[0][0]; + } else { + $first_to = $params->{To}[0]; + } + } else { + $first_to = $params->{To}; + } + return 1 if $c->is_abuser($first_to); $params->{'Message-ID'} = sprintf('<fms-cron-%s-%s@%s>', time(), unpack('h*', random_bytes(5, 1)), FixMyStreet->config('EMAIL_DOMAIN') @@ -379,23 +389,23 @@ sub send_email_cron { $sig = Encode::decode('utf8', $sig); $params->{_parameters_}->{signature} = $sig; - $tt->process( 'site_name.txt', $params, \$site_name ); - $site_name = Encode::decode('utf8', $site_name); - my $site_title = $cobrand ? $cobrand->site_title : ''; - $params->{_parameters_}->{site_name} = $site_name || $site_title; + $tt->process( 'site-name.txt', $params, \$site_name ); + $site_name = Utils::trim_text(Encode::decode('utf8', $site_name)); + $params->{_parameters_}->{site_name} = $site_name; $params->{_line_indent} = ''; my $email = mySociety::Locale::in_gb_locale { mySociety::Email::construct_email($params) }; - if ( FixMyStreet->test_mode ) { - my $sender = Email::Send->new({ mailer => 'Test' }); - $sender->send( $email ); - return 0; - } elsif (!$nomail) { - return mySociety::EmailUtil::send_email( $email, $env_from, @$env_to ); - } else { + if ($nomail) { print $email; return 1; # Failure + } else { + my %model_args; + if (!FixMyStreet->test_mode && $env_from eq FixMyStreet->config('CONTACT_EMAIL')) { + $model_args{mailer} = 'FixMyStreet::EmailSend::ContactEmail'; + } + my $result = $c->model('EmailSend', %model_args)->send($email); + return $result ? 0 : 1; } } diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index b2e0bdc2e..de13a76de 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -427,7 +427,7 @@ sub update_contacts : Private { # Remove any others $c->stash->{body}->body_areas->search( { area_id => [ keys %current ] } )->delete; - $c->stash->{updated} = _('Configuration updated - contacts will be generated automatically later'); + $c->stash->{updated} = _('Values updated'); } } @@ -485,13 +485,13 @@ sub lookup_body : Private { } # This is for if the category name contains a '/' -sub body_edit_all : Path('body_edit') { +sub category_edit_all : Path('body') { my ( $self, $c, $body_id, @category ) = @_; my $category = join( '/', @category ); - $c->go( 'body_edit', [ $body_id, $category ] ); + $c->go( 'category_edit', [ $body_id, $category ] ); } -sub body_edit : Path('body_edit') : Args(2) { +sub category_edit : Path('body') : Args(2) { my ( $self, $c, $body_id, $category ) = @_; $c->stash->{body_id} = $body_id; @@ -1197,11 +1197,10 @@ sub set_allowed_pages : Private { 'questionnaire' => [_('Survey'), 4], 'users' => [_('Users'), 5], 'flagged' => [_('Flagged'), 6], - 'stats' => [_('Stats'), 6], - 'config' => [ undef, undef ], + 'stats' => [_('Stats'), 7], + 'config' => [ _('Configuration'), 8], 'user_edit' => [undef, undef], 'body' => [undef, undef], - 'body_edit' => [undef, undef], 'report_edit' => [undef, undef], 'update_edit' => [undef, undef], 'abuse_edit' => [undef, undef], diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm index 5a51c8494..f48518d77 100644 --- a/perllib/FixMyStreet/App/Controller/Contact.pm +++ b/perllib/FixMyStreet/App/Controller/Contact.pm @@ -4,6 +4,8 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } +use mySociety::EmailUtil; + =head1 NAME FixMyStreet::App::Controller::Contact - Catalyst Controller diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index c20a6754a..88a49f6c9 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -112,9 +112,10 @@ sub load_problem_or_display_error : Private { ); } elsif ( $problem->non_public ) { if ( !$c->user || $c->user->id != $problem->user->id ) { + my $site_name = Utils::trim_text($c->render_fragment('site-name.html')); $c->detach( '/page_error_403_access_denied', - [ sprintf(_('That report cannot be viewed on %s.'), $c->cobrand->site_title) ] # + [ sprintf(_('That report cannot be viewed on %s.'), $site_name) ] # ); } } diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 10ef30c90..352c47da8 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -74,7 +74,7 @@ sub index : Path : Args(0) { if ($@) { $c->stash->{message} = _("There was a problem showing the All Reports page. Please try again later."); if ($c->config->{STAGING_SITE}) { - $c->stash->{message} .= '</p><p>Perhaps the bin/update-all-reports script needs running. Use: bin/cron-wrapper bin/update-all-reports</p><p>' + $c->stash->{message} .= '</p><p>Perhaps the bin/update-all-reports script needs running. Use: bin/update-all-reports</p><p>' . sprintf(_('The error was: %s'), $@); } $c->stash->{template} = 'errors/generic.html'; diff --git a/perllib/FixMyStreet/App/Model/EmailSend.pm b/perllib/FixMyStreet/App/Model/EmailSend.pm index 7f130c26d..475026267 100644 --- a/perllib/FixMyStreet/App/Model/EmailSend.pm +++ b/perllib/FixMyStreet/App/Model/EmailSend.pm @@ -1,5 +1,5 @@ package FixMyStreet::App::Model::EmailSend; -use base 'Catalyst::Model::Adaptor'; +use base 'Catalyst::Model::Factory'; use strict; use warnings; @@ -54,7 +54,7 @@ elsif ( my $smtp_host = FixMyStreet->config('SMTP_SMARTHOST') ) { push @$mailer_args, username => $username, password => $password if $username && $password; $args = { - mailer => 'FixMyStreet::EmailSend', + mailer => 'FixMyStreet::EmailSend::DoNotReply', mailer_args => $mailer_args, }; } diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index 531582f0e..99b38ca6a 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -24,6 +24,24 @@ sub disambiguate_location { # Bromley by Bow. $town .= ', BR1' if $string =~ /^high\s+st(reet)?$/i; + # Disambiguations required for BR5 + $town .= ', BR5' if $string =~ /^kelsey\s+r(?:oa)?d$/i; + $town = 'BR5 Bromley' if $string =~ /^leith\s+hill$/i; # doesn't like appended BR5 for some reason + + # There has also been a road name change for a section of Ramsden Road + # (BR5) between Church Hill and Court Road has changed to 'Old Priory + # Avenue' - presently entering Old Priory Avenue simply takes the user to + # a different Priory Avenue in Petts Wood + # From Google maps search, "BR6 0PL" is a valid postcode for Old Priory Avenue + if ($string =~/^old\s+priory\s+av\w*$/i) { + $string = 'Ramsden Road'; + $town = ', BR6 0PL'; + } + $town .= ', BR5' if $string =~ /^meadway/i; + + # and BR6 + $town .= ', BR6' if $string =~ /^berrylands/i; + # White Horse Hill is on boundary with Greenwich, so need a # specific postcode $town = 'chislehurst, BR7 6DH' if $string =~ /^white\s+horse/i; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index ec7a8a81d..7f1fba67a 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -146,14 +146,6 @@ Can be specified in template. sub enter_postcode_text { } -=head2 site_title - -The name of the site - -=cut - -sub site_title { return 'FixMyStreet'; } - =head2 set_lang_and_domain my $set_lang = $cobrand->set_lang_and_domain( $lang, $unicode, $dir ) diff --git a/perllib/FixMyStreet/Cobrand/EastSussex.pm b/perllib/FixMyStreet/Cobrand/EastSussex.pm index 5447545e7..5aabae449 100644 --- a/perllib/FixMyStreet/Cobrand/EastSussex.pm +++ b/perllib/FixMyStreet/Cobrand/EastSussex.pm @@ -119,5 +119,9 @@ sub pin_colour { return $open_states->{ $p->state } ? 'yellow' : 'green'; } +sub send_questionnaires { + return 0; +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/FixMindelo.pm b/perllib/FixMyStreet/Cobrand/FixMindelo.pm index fd3a55c6c..59debf157 100644 --- a/perllib/FixMyStreet/Cobrand/FixMindelo.pm +++ b/perllib/FixMyStreet/Cobrand/FixMindelo.pm @@ -4,8 +4,6 @@ use base 'FixMyStreet::Cobrand::Default'; use strict; use warnings; -sub site_title { return 'FixMindelo'; } - sub country { return 'CV'; } diff --git a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm index 98c157aef..60f98dd47 100644 --- a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm +++ b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm @@ -9,11 +9,6 @@ use mySociety::MaPit; use FixMyStreet::Geocode::FixaMinGata; use DateTime; -sub site_title { - my ($self) = @_; - return 'FixaMinGata'; -} - sub country { return 'SE'; } diff --git a/perllib/FixMyStreet/Cobrand/Harrogate.pm b/perllib/FixMyStreet/Cobrand/Harrogate.pm new file mode 100644 index 000000000..6bcc2f227 --- /dev/null +++ b/perllib/FixMyStreet/Cobrand/Harrogate.pm @@ -0,0 +1,242 @@ +package FixMyStreet::Cobrand::Harrogate; +use base 'FixMyStreet::Cobrand::UKCouncils'; + +use strict; +use warnings; +use feature 'say'; + +sub council_id { return 2407; } +sub council_area { return 'Harrogate'; } +sub council_name { return 'Harrogate Borough Council'; } +sub council_url { return 'harrogate'; } +sub is_two_tier { return 1; } # with North Yorkshire CC 2235 + +sub disambiguate_location { + my $self = shift; + my $string = shift; + + my $town = 'Harrogate'; + + # as it's the requested example location, try to avoid a disambiguation page + $town .= ', HG1 1DH' if $string =~ /^\s*king'?s\s+r(?:oa)?d\s*(?:,\s*har\w+\s*)?$/i; + + return { + %{ $self->SUPER::disambiguate_location() }, + town => $town, + centre => '54.0671557690306,-1.59581319536637', + span => '0.370193897090822,0.829517054931808', + bounds => [ 53.8914112467619, -2.00450542308575, 54.2616051438527, -1.17498836815394 ], + }; +} + +sub example_places { + return ( 'HG1 2SG', "King's Road" ); +} + +sub enter_postcode_text { + my ($self) = @_; + return 'Enter a Harrogate district postcode, or street name and area'; +} + +# increase map zoom level so street names are visible +sub default_map_zoom { return 3; } + + +=head2 temp_email_to_update, temp_update_contacts + +Temporary helper routines to update the extra for potholes (temporary setup +hack, cargo-culted from ESCC, may in future be superseded either by +Open311/integration or a better mechanism for manually creating rich contacts). + +Can run with a script or command line like: + + bin/cron-wrapper perl -MFixMyStreet::App -MFixMyStreet::Cobrand::Harrogate -e \ + 'FixMyStreet::Cobrand::Harrogate->new({c => FixMyStreet::App->new})->temp_update_contacts' + +=cut + +sub temp_email_to_update { + return 'CustomerServices@harrogate.gov.uk'; +} + +sub temp_update_contacts { + my $self = shift; + + my $contact_rs = $self->{c}->model('DB::Contact'); + + my $email = $self->temp_email_to_update; + my $_update = sub { + my ($category, $field, $category_details) = @_; + # NB: we're accepting just 1 field, but supply as array [ $field ] + + my $contact = $contact_rs->find_or_create( + { + body_id => $self->council_id, + category => $category, + + confirmed => 1, + deleted => 0, + email => $email, + editor => 'automated script', + note => '', + send_method => '', + whenedited => \'NOW()', + %{ $category_details || {} }, + }, + { + key => 'contacts_body_id_category_idx' + } + ); + + say "Editing category: $category"; + + my %default = ( + variable => 'true', + order => '1', + required => 'no', + datatype => 'string', + datatype_description => 'a string', + ); + + if ($field->{datatype} || '' eq 'boolean') { + my $description = $field->{description}; + %default = ( + %default, + datatype => 'singlevaluelist', + datatype_description => 'Yes or No', + values => { value => [ + { key => ['No'], name => ['No'] }, + { key => ['Yes'], name => ['Yes'] }, + ] }, + ); + } + + $contact->update({ + extra => [ { %default, %$field } ], + confirmed => 1, + deleted => 0, + editor => 'automated script', + whenedited => \'NOW()', + note => 'Edited by script as per requirements Dec 2014', + }); + }; + + $_update->( 'Abandoned vehicles', { + code => 'registration', + description => 'Vehicle Registration number:', + }); + + $_update->( 'Dead animals', { + code => 'INFO_TEXT', + variable => 'false', + description => 'We do not remove small species, e.g. squirrels, rabbits, and small birds.', + }); + + $_update->( 'Flyposting', { + code => 'offensive', + description => 'Is it offensive?', + datatype => 'boolean', # mapped onto singlevaluelist + }); + + $_update->( 'Flytipping', { + code => 'size', + description => 'Size?', + datatype => 'singlevaluelist', + values => { value => [ + { key => ['Single Item'], name => ['Single item'] }, + { key => ['Car boot load'], name => ['Car boot load'] }, + { key => ['Small van load'], name => ['Small van load'] }, + { key => ['Transit van load'], name => ['Transit van load'] }, + { key => ['Tipper lorry load'], name => ['Tipper lorry load'] }, + { key => ['Significant load'], name => ['Significant load'] }, + ] }, + }); + + $_update->( 'Graffiti', { + code => 'offensive', + description => 'Is it offensive?', + datatype => 'boolean', # mapped onto singlevaluelist + }); + + $_update->( 'Parks and playgrounds', { + code => 'dangerous', + description => 'Is it dangerous or could cause injury?', + datatype => 'boolean', # mapped onto singlevaluelist + }); + + $_update->( 'Trees', { + code => 'dangerous', + description => 'Is it dangerous or could cause injury?', + datatype => 'boolean', # mapped onto singlevaluelist + }); + + # also ensure that the following categories are created: + for my $category ( + 'Car parking', + 'Dog and litter bins', + 'Dog fouling', + 'Other', + 'Rubbish (refuse and recycling)', + 'Street cleaning', + 'Street lighting', + 'Street nameplates', + ) { + say "Creating $category if required"; + my $contact = $contact_rs->find_or_create( + { + body_id => $self->council_id, + category => $category, + confirmed => 1, + deleted => 0, + email => $email, + editor => 'automated script', + note => 'Created by script as per requirements Dec 2014', + send_method => '', + whenedited => \'NOW()', + } + ); + } + + my @to_delete = ( + 'Parks/landscapes', # delete in favour of to parks and playgrounds + 'Public toilets', # as no longer in specs + ); + say sprintf "Deleting: %s (if present)", join ',' => @to_delete; + $contact_rs->search({ + body_id => $self->council_id, + category => \@to_delete, + deleted => 0 + })->update({ + deleted => 1, + editor => 'automated script', + whenedited => \'NOW()', + note => 'Deleted by script as per requirements Dec 2014', + }); +} + +sub contact_email { + my $self = shift; + return join( '@', 'customerservices', 'harrogate.gov.uk' ); +} + +sub process_additional_metadata_for_email { + my ($self, $problem, $h) = @_; + + my $additional = ''; + if (my $extra = $problem->extra) { + $additional = join "\n\n", map { + if ($_->{name} eq 'INFO_TEXT') { + (); + } + else { + sprintf '%s: %s', $_->{description}, $_->{value}; + } + } @$extra; + $additional = "\n\n$additional" if $additional; + } + + $h->{additional_information} = $additional; +} + +1; + diff --git a/perllib/FixMyStreet/Cobrand/MakeMyIsland.pm b/perllib/FixMyStreet/Cobrand/MakeMyIsland.pm index ebeb15fbb..f263df4cc 100644 --- a/perllib/FixMyStreet/Cobrand/MakeMyIsland.pm +++ b/perllib/FixMyStreet/Cobrand/MakeMyIsland.pm @@ -4,8 +4,6 @@ use base 'FixMyStreet::Cobrand::Default'; use strict; use warnings; -sub site_title { return 'MakeMyIsland'; } - sub country { return 'MV'; } diff --git a/perllib/FixMyStreet/Cobrand/SeeSomething.pm b/perllib/FixMyStreet/Cobrand/SeeSomething.pm index 5e6d3a8cd..775ba770b 100644 --- a/perllib/FixMyStreet/Cobrand/SeeSomething.pm +++ b/perllib/FixMyStreet/Cobrand/SeeSomething.pm @@ -9,8 +9,6 @@ sub council_area { return 'West Midlands'; } sub council_name { return 'See Something Say Something'; } sub council_url { return 'seesomething'; } sub area_types { [ 'MTD' ] } -sub site_title { return 'See Something, Say Something'; } - sub site_restriction { my $self = shift; diff --git a/perllib/FixMyStreet/Cobrand/ZeroTB.pm b/perllib/FixMyStreet/Cobrand/ZeroTB.pm index 087bf0912..cdf4e5ad4 100644 --- a/perllib/FixMyStreet/Cobrand/ZeroTB.pm +++ b/perllib/FixMyStreet/Cobrand/ZeroTB.pm @@ -4,8 +4,6 @@ use base 'FixMyStreet::Cobrand::Default'; use strict; use warnings; -sub site_title { return 'ZeroTB'; } - sub enter_postcode_text { return _ ('Enter a nearby street name and area, postal code or district in Delhi'); } sub country { diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm index 087d9046b..577da9dd5 100644 --- a/perllib/FixMyStreet/Cobrand/Zurich.pm +++ b/perllib/FixMyStreet/Cobrand/Zurich.pm @@ -296,7 +296,6 @@ sub admin_pages { $pages = { %$pages, 'bodies' => [_('Bodies'), 1], 'body' => [undef, undef], - 'body_edit' => [undef, undef], }; return $pages if $type eq 'dm'; diff --git a/perllib/FixMyStreet/DB/Result/Token.pm b/perllib/FixMyStreet/DB/Result/Token.pm index 5525fe7a5..0156af137 100644 --- a/perllib/FixMyStreet/DB/Result/Token.pm +++ b/perllib/FixMyStreet/DB/Result/Token.pm @@ -30,9 +30,6 @@ __PACKAGE__->set_primary_key("scope", "token"); # Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+LLZ8P5GXqPetuGyrra2vw -# Trying not to use this -# use mySociety::DBHandle qw(dbh); - use mySociety::AuthToken; =head1 NAME @@ -43,8 +40,6 @@ FixMyStreet::DB::Result::Token Representation of mySociety::AuthToken in the DBIx::Class world. -Mostly done so that we don't need to use mySociety::DBHandle. - The 'data' value is automatically inflated and deflated in the same way that the AuthToken would do it. 'token' is set to a new random value by default and the 'created' timestamp is achieved using the database function diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index 5bed95811..b704fa7dd 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -5,7 +5,6 @@ use strict; use warnings; use mySociety::DBHandle qw(dbh); -use mySociety::EmailUtil; use mySociety::Gaze; use mySociety::Locale; use mySociety::MaPit; @@ -262,13 +261,12 @@ sub _send_aggregated_alert_email(%) { To => $data{alert_email}, }, $sender, - [ $data{alert_email} ], 0, $cobrand, $data{lang} ); - if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { + unless ($result) { $token->insert(); } else { print "Failed to send alert $data{alert_id}!"; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 5d70bf47d..a84a309ee 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -8,7 +8,6 @@ use CronFns; use Utils; use mySociety::Config; -use mySociety::EmailUtil; use mySociety::MaPit; use FixMyStreet::App; @@ -323,6 +322,10 @@ sub send_reports { $h{user_details} .= sprintf(_('Email: %s'), $row->user->email) . "\n\n"; } + if ($cobrand->can('process_additional_metadata_for_email')) { + $cobrand->process_additional_metadata_for_email($row, \%h); + } + my %reporters = (); my ( $sender_count ); if ($site eq 'emptyhomes') { @@ -434,7 +437,7 @@ sub send_reports { } } - if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { + unless ($result) { $row->update( { whensent => \'ms_current_timestamp()', lastupdate => \'ms_current_timestamp()', @@ -497,7 +500,7 @@ sub _send_report_sent_email { my $template = FixMyStreet->get_email_template($row->cobrand, $row->lang, 'confirm_report_sent.txt'); - my $result = FixMyStreet::App->send_email_cron( + FixMyStreet::App->send_email_cron( { _template_ => $template, _parameters_ => $h, @@ -505,7 +508,6 @@ sub _send_report_sent_email { From => mySociety::Config::get('CONTACT_EMAIL'), }, mySociety::Config::get('CONTACT_EMAIL'), - [ $row->user->email ], $nomail, $cobrand ); diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm index b7af9e60e..63a91697d 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm @@ -5,7 +5,6 @@ use strict; use warnings; use Encode; use Utils; -use mySociety::EmailUtil; sub send_questionnaires { my ( $rs, $params ) = @_; @@ -93,8 +92,6 @@ sub send_questionnaires_period { . $row->user->email . "\n" if $params->{verbose}; - $h{site_name} = $cobrand->site_title(); - my $result = FixMyStreet::App->send_email_cron( { _template_ => $template, @@ -103,11 +100,10 @@ sub send_questionnaires_period { From => [ $sender, $sender_name ], }, $sender, - [ $row->user->email ], $params->{nomail}, $cobrand ); - if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { + unless ($result) { print " ...success\n" if $params->{verbose}; $row->update(); $token->insert(); diff --git a/perllib/FixMyStreet/EmailSend/ContactEmail.pm b/perllib/FixMyStreet/EmailSend/ContactEmail.pm new file mode 100644 index 000000000..28bcc983b --- /dev/null +++ b/perllib/FixMyStreet/EmailSend/ContactEmail.pm @@ -0,0 +1,9 @@ +package FixMyStreet::EmailSend::ContactEmail; +use base Email::Send::SMTP; + +sub get_env_sender { + my $sender = FixMyStreet->config('CONTACT_EMAIL'); + return $sender; +} + +1; diff --git a/perllib/FixMyStreet/EmailSend.pm b/perllib/FixMyStreet/EmailSend/DoNotReply.pm index 8b6eed462..d1368f00f 100644 --- a/perllib/FixMyStreet/EmailSend.pm +++ b/perllib/FixMyStreet/EmailSend/DoNotReply.pm @@ -1,4 +1,4 @@ -package FixMyStreet::EmailSend; +package FixMyStreet::EmailSend::DoNotReply; use base Email::Send::SMTP; sub get_env_sender { diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 2a318ea5a..b5be152a8 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet::Geocode # The geocoding functions for FixMyStreet. # diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 85eef3d0f..702e19814 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet::Geocode::Bing # Geocoding with Bing for FixMyStreet. # diff --git a/perllib/FixMyStreet/Geocode/FixaMinGata.pm b/perllib/FixMyStreet/Geocode/FixaMinGata.pm index 2db25f504..2ea92c422 100644 --- a/perllib/FixMyStreet/Geocode/FixaMinGata.pm +++ b/perllib/FixMyStreet/Geocode/FixaMinGata.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Geocode::FixaMinGata # OpenStreetmap forward and reverse geocoding for FixMyStreet. # diff --git a/perllib/FixMyStreet/Geocode/Google.pm b/perllib/FixMyStreet/Geocode/Google.pm index fd65b89b1..11ff8ef80 100644 --- a/perllib/FixMyStreet/Geocode/Google.pm +++ b/perllib/FixMyStreet/Geocode/Google.pm @@ -1,6 +1,4 @@ -#!/usr/bin/perl -# -# FixMyStreet::Geocode +# FixMyStreet::Geocode::Google # The geocoding functions for FixMyStreet. # # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. diff --git a/perllib/FixMyStreet/Geocode/OSM.pm b/perllib/FixMyStreet/Geocode/OSM.pm index fd14b0acc..919940f78 100644 --- a/perllib/FixMyStreet/Geocode/OSM.pm +++ b/perllib/FixMyStreet/Geocode/OSM.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Geocode::OSM # OpenStreetmap forward and reverse geocoding for FixMyStreet. # diff --git a/perllib/FixMyStreet/Geocode/Zurich.pm b/perllib/FixMyStreet/Geocode/Zurich.pm index 84fd83fc7..1f0b4fc16 100644 --- a/perllib/FixMyStreet/Geocode/Zurich.pm +++ b/perllib/FixMyStreet/Geocode/Zurich.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet::Geocode::Zurich # Geocoding with Zurich web service. # diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index f2dd0da6d..7d490fde3 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Map # Adding the ability to have different maps on FixMyStreet. # diff --git a/perllib/FixMyStreet/Map/Bing.pm b/perllib/FixMyStreet/Map/Bing.pm index 676e70bf6..09c951a5f 100644 --- a/perllib/FixMyStreet/Map/Bing.pm +++ b/perllib/FixMyStreet/Map/Bing.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Map::Bing # Bing maps on FixMyStreet. # diff --git a/perllib/FixMyStreet/Map/Bromley.pm b/perllib/FixMyStreet/Map/Bromley.pm index 20821236f..fc8726b34 100644 --- a/perllib/FixMyStreet/Map/Bromley.pm +++ b/perllib/FixMyStreet/Map/Bromley.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Map::Bromley # Bromley have slightly different tiles, with trees etc. # diff --git a/perllib/FixMyStreet/Map/FMS.pm b/perllib/FixMyStreet/Map/FMS.pm index 62849a157..96e265a4d 100644 --- a/perllib/FixMyStreet/Map/FMS.pm +++ b/perllib/FixMyStreet/Map/FMS.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Map::FMS # Bing and OS StreetView maps on FixMyStreet, using OpenLayers. # diff --git a/perllib/FixMyStreet/Map/Google.pm b/perllib/FixMyStreet/Map/Google.pm index 9deefc033..172d2d60e 100644 --- a/perllib/FixMyStreet/Map/Google.pm +++ b/perllib/FixMyStreet/Map/Google.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Map::Google # Google maps on FixMyStreet. # diff --git a/perllib/FixMyStreet/Map/GoogleOL.pm b/perllib/FixMyStreet/Map/GoogleOL.pm index 64baf8d36..2dfb697e5 100644 --- a/perllib/FixMyStreet/Map/GoogleOL.pm +++ b/perllib/FixMyStreet/Map/GoogleOL.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Map::GoogleOL # Google maps on FixMyStreet, using OpenLayers. # diff --git a/perllib/FixMyStreet/Map/OSM.pm b/perllib/FixMyStreet/Map/OSM.pm index 74af0e9f3..df2d16b82 100644 --- a/perllib/FixMyStreet/Map/OSM.pm +++ b/perllib/FixMyStreet/Map/OSM.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Map::OSM # OSM maps on FixMyStreet. # @@ -29,10 +27,10 @@ sub map_tiles { my ( $x, $y, $z ) = ( $params{x_tile}, $params{y_tile}, $params{zoom_act} ); my $tile_url = $self->base_tile_url(); return [ - "http://a.$tile_url/$z/" . ($x - 1) . "/" . ($y - 1) . ".png", - "http://b.$tile_url/$z/$x/" . ($y - 1) . ".png", - "http://c.$tile_url/$z/" . ($x - 1) . "/$y.png", - "http://$tile_url/$z/$x/$y.png", + "https://a.$tile_url/$z/" . ($x - 1) . "/" . ($y - 1) . ".png", + "https://b.$tile_url/$z/$x/" . ($y - 1) . ".png", + "https://c.$tile_url/$z/" . ($x - 1) . "/$y.png", + "https://a.$tile_url/$z/$x/$y.png", ]; } diff --git a/perllib/FixMyStreet/Map/OSM/CycleMap.pm b/perllib/FixMyStreet/Map/OSM/CycleMap.pm index 71b86de8f..8f1de39d2 100644 --- a/perllib/FixMyStreet/Map/OSM/CycleMap.pm +++ b/perllib/FixMyStreet/Map/OSM/CycleMap.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Map::OSM::CycleMap # OSM CycleMap maps on FixMyStreet. # diff --git a/perllib/FixMyStreet/Map/OSM/MapQuest.pm b/perllib/FixMyStreet/Map/OSM/MapQuest.pm index a7f1b334e..2c3cbaf00 100644 --- a/perllib/FixMyStreet/Map/OSM/MapQuest.pm +++ b/perllib/FixMyStreet/Map/OSM/MapQuest.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Map::OSM::CycleMap # OSM CycleMap maps on FixMyStreet. # diff --git a/perllib/FixMyStreet/Map/OSM/StreetView.pm b/perllib/FixMyStreet/Map/OSM/StreetView.pm index 8fe4744a4..c70dd93aa 100644 --- a/perllib/FixMyStreet/Map/OSM/StreetView.pm +++ b/perllib/FixMyStreet/Map/OSM/StreetView.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Map::OSM::StreetView # OSM StreetView maps on FixMyStreet. # diff --git a/perllib/FixMyStreet/Map/Zurich.pm b/perllib/FixMyStreet/Map/Zurich.pm index e09f8c90f..d667a4701 100644 --- a/perllib/FixMyStreet/Map/Zurich.pm +++ b/perllib/FixMyStreet/Map/Zurich.pm @@ -1,5 +1,3 @@ -#!/usr/bin/perl -# # FixMyStreet:Map::Zurich # Zurich have their own tileserver. # diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm index 5087c7ead..40e76ef72 100644 --- a/perllib/FixMyStreet/SendReport.pm +++ b/perllib/FixMyStreet/SendReport.pm @@ -10,6 +10,7 @@ use Module::Pluggable has 'body_config' => ( is => 'rw', isa => 'HashRef', default => sub { {} } ); has 'bodies' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } ); has 'to' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } ); +has 'bcc' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } ); has 'success' => ( is => 'rw', isa => 'Bool', default => 0 ); has 'error' => ( is => 'rw', isa => 'Str', default => '' ); has 'unconfirmed_counts' => ( 'is' => 'rw', isa => 'HashRef', default => sub { {} } ); @@ -44,6 +45,7 @@ sub reset { $self->bodies( [] ); $self->body_config( {} ); $self->to( [] ); + $self->bcc( [] ); } sub add_body { diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 19c6405d2..4507091c7 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -4,11 +4,8 @@ use Moose; BEGIN { extends 'FixMyStreet::SendReport'; } -use mySociety::EmailUtil; - sub build_recipient_list { my ( $self, $row, $h ) = @_; - my %recips; my $all_confirmed = 1; foreach my $body ( @{ $self->bodies } ) { @@ -49,19 +46,20 @@ sub build_recipient_list { } for my $email ( @emails ) { push @{ $self->to }, [ $email, $body_name ]; - $recips{$email} = 1; } } - return () unless $all_confirmed; - return keys %recips; + return $all_confirmed && @{$self->to}; } sub get_template { my ( $self, $row ) = @_; my $template = 'submit.txt'; - $template = 'submit-brent.txt' if $row->bodies_str eq 2488 || $row->bodies_str eq 2237; + + if ($row->cobrand eq 'fixmystreet') { + $template = 'submit-oxfordshire.txt' if $row->bodies_str eq 2237; + } $template = FixMyStreet->get_email_template($row->cobrand, $row->lang, $template); return $template; @@ -76,34 +74,36 @@ sub send { my $self = shift; my ( $row, $h ) = @_; - my @recips = $self->build_recipient_list( $row, $h ); + my $recips = $self->build_recipient_list( $row, $h ); # 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 = ( $row->user->email ); + $recips = 1; + @{$self->to} = [ $row->user->email, $self->to->[0][1] || $row->name ]; } - unless ( @recips ) { + unless ($recips) { $self->error( 'No recipients' ); return 1; } my ($verbose, $nomail) = CronFns::options(); my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new(); + my $params = { + _template_ => $self->get_template( $row ), + _parameters_ => $h, + To => $self->to, + From => $self->send_from( $row ), + }; + $params->{Bcc} = $self->bcc if @{$self->bcc}; my $result = FixMyStreet::App->send_email_cron( - { - _template_ => $self->get_template( $row ), - _parameters_ => $h, - To => $self->to, - From => $self->send_from( $row ), - }, + $params, mySociety::Config::get('CONTACT_EMAIL'), - \@recips, $nomail, $cobrand ); - if ( $result == mySociety::EmailUtil::EMAIL_SUCCESS ) { + unless ($result) { $self->success(1); } else { $self->error( 'Failed to send email' ); @@ -143,4 +143,5 @@ sub _get_district_for_contact { ($district) = keys %$district; return $district; } + 1; diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm index 4bae6af46..ce69aaac3 100644 --- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm +++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm @@ -9,7 +9,6 @@ BEGIN { extends 'FixMyStreet::SendReport::Email'; } sub build_recipient_list { my ( $self, $row, $h ) = @_; - my %recips; my $all_confirmed = 1; foreach my $body ( @{ $self->bodies } ) { @@ -31,24 +30,22 @@ sub build_recipient_list { } push @{ $self->to }, [ $body_email, $body->name ]; - $recips{$body_email} = 1; my $area_info = mySociety::MaPit::call('area', $body->body_areas->first->area_id); my $country = $area_info->{country}; if ($country eq 'W') { - $recips{ 'wales@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1; + push @{$self->bcc}, 'wales@' . mySociety::Config::get('EMAIL_DOMAIN'); } elsif ($country eq 'S') { - $recips{ 'scotland@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1; + push @{$self->bcc}, 'scotland@' . mySociety::Config::get('EMAIL_DOMAIN'); } else { - $recips{ 'eha@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1; + push @{$self->bcc}, 'eha@' . mySociety::Config::get('EMAIL_DOMAIN'); } } # Set address email parameter from added data $h->{address} = $row->extra->{address}; - return () unless $all_confirmed; - return keys %recips; + return $all_confirmed && @{$self->to}; } sub get_template { diff --git a/perllib/FixMyStreet/SendReport/London.pm b/perllib/FixMyStreet/SendReport/London.pm index 2c48a091c..2a1ebc1c3 100644 --- a/perllib/FixMyStreet/SendReport/London.pm +++ b/perllib/FixMyStreet/SendReport/London.pm @@ -5,6 +5,7 @@ use Moose; BEGIN { extends 'FixMyStreet::SendReport'; } use Digest::MD5; +use FindBin; use LWP::UserAgent; use LWP::Simple; diff --git a/perllib/FixMyStreet/SendReport/NI.pm b/perllib/FixMyStreet/SendReport/NI.pm index e0ea24f9c..c60643566 100644 --- a/perllib/FixMyStreet/SendReport/NI.pm +++ b/perllib/FixMyStreet/SendReport/NI.pm @@ -6,7 +6,6 @@ BEGIN { extends 'FixMyStreet::SendReport::Email'; } sub build_recipient_list { my ( $self, $row, $h ) = @_; - my %recips; my $all_confirmed = 1; foreach my $body ( @{ $self->bodies } ) { @@ -30,11 +29,9 @@ sub build_recipient_list { $row->external_body( 'Roads Service' ); } push @{ $self->to }, [ $email, $name ]; - $recips{$email} = 1; } - return () unless $all_confirmed; - return keys %recips; + return $all_confirmed && @{$self->to}; } 1; diff --git a/perllib/FixMyStreet/SendReport/Zurich.pm b/perllib/FixMyStreet/SendReport/Zurich.pm index d46561e9e..40417b41e 100644 --- a/perllib/FixMyStreet/SendReport/Zurich.pm +++ b/perllib/FixMyStreet/SendReport/Zurich.pm @@ -26,7 +26,7 @@ sub build_recipient_list { } push @{ $self->to }, [ $body_email, $body->name ]; - return $body_email; + return 1; } sub get_template { diff --git a/perllib/FixMyStreet/TestAppProve.pm b/perllib/FixMyStreet/TestAppProve.pm index 4d8cdaccb..75e9fe0a4 100644 --- a/perllib/FixMyStreet/TestAppProve.pm +++ b/perllib/FixMyStreet/TestAppProve.pm @@ -14,7 +14,7 @@ FixMyStreet::TestAppProve - spin up a clean database and configuration for tests =head1 USAGE -see bin/test-wrapper for usage +see bin/run-tests for usage =cut |