diff options
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 14 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Open311conf.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 26 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 27 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Nearby.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 97 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm | 7 |
8 files changed, 158 insertions, 33 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 4f155ace3..b551be9ef 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -54,10 +54,6 @@ __PACKAGE__->add_columns( { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "problem_state", { data_type => "text", is_nullable => 1 }, - "external_id", - { data_type => "text", is_nullable => 1 }, - "extra", - { data_type => "text", is_nullable => 1 }, "send_fail_count", { data_type => "integer", default_value => 0, is_nullable => 0 }, "send_fail_reason", @@ -66,6 +62,10 @@ __PACKAGE__->add_columns( { data_type => "timestamp", is_nullable => 1 }, "whensent", { data_type => "timestamp", is_nullable => 1 }, + "external_id", + { data_type => "text", is_nullable => 1 }, + "extra", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( @@ -82,8 +82,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-26 15:44:18 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nvkElEgSU6XcLd9znSqhmQ +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-07-11 18:53:26 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tSejJzLxHD/fMWjpa10lfA __PACKAGE__->filter_column( extra => { diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index c32b75d0c..993e3524b 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -36,13 +36,23 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 0 }, "extra", { data_type => "text", is_nullable => 1 }, + "non_public", + { data_type => "boolean", default_value => \"false", is_nullable => 1 }, + "endpoint", + { data_type => "text", is_nullable => 1 }, + "jurisdiction", + { data_type => "text", default_value => "", is_nullable => 1 }, + "api_key", + { data_type => "text", default_value => "", is_nullable => 1 }, + "send_method", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("contacts_area_id_category_idx", ["area_id", "category"]); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hyvU0bMWSFxEPAJT7wqM/Q +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-31 10:29:17 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:t6yOPhZmedV/eH6AUvHI6w __PACKAGE__->filter_column( extra => { diff --git a/perllib/FixMyStreet/DB/Result/Open311conf.pm b/perllib/FixMyStreet/DB/Result/Open311conf.pm index 6748db825..f01a20dec 100644 --- a/perllib/FixMyStreet/DB/Result/Open311conf.pm +++ b/perllib/FixMyStreet/DB/Result/Open311conf.pm @@ -34,6 +34,8 @@ __PACKAGE__->add_columns( { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "suppress_alerts", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "can_be_devolved", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "send_extended_statuses", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, ); @@ -52,9 +54,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-10-03 14:49:22 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OO3kNIohRp+84PGI2154fg - +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-29 14:04:20 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Yoult8K/ldH6DMAKURtr3Q # You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 83939bfab..b1f59e78a 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -85,13 +85,23 @@ __PACKAGE__->add_columns( "geocode", { data_type => "bytea", is_nullable => 1 }, "send_fail_count", - { data_type => "integer", is_nullable => 1 }, + { data_type => "integer", default_value => 0, is_nullable => 0 }, "send_fail_reason", { data_type => "text", is_nullable => 1 }, "send_fail_timestamp", { data_type => "timestamp", is_nullable => 1 }, "send_method_used", { data_type => "text", is_nullable => 1 }, + "non_public", + { data_type => "boolean", default_value => \"false", is_nullable => 1 }, + "external_source", + { data_type => "text", is_nullable => 1 }, + "external_source_id", + { data_type => "text", is_nullable => 1 }, + "interest_count", + { data_type => "integer", is_nullable => 1 }, + "subcategory", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( @@ -114,8 +124,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-05-03 16:05:20 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EvwI91Ot7SioQWqwnXRTBQ +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-03 17:48:10 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xN/RB8Vx50CwyOeBjvJezQ # Add fake relationship to stored procedure table __PACKAGE__->has_one( @@ -606,9 +616,6 @@ sub meta_line { } - $meta .= '; ' . _('the map was not used so pin location may be inaccurate') - unless $problem->used_map; - return $meta; } @@ -644,7 +651,8 @@ sub body { # Note: this only makes sense when called on a problem that has been sent! sub can_display_external_id { my $self = shift; - if ($self->external_id && $self->send_method_used && $self->send_method_used eq 'barnet') { + if ($self->external_id && $self->send_method_used && + ($self->send_method_used eq 'barnet' || $self->council =~ /2237/)) { return 1; } return 0; @@ -664,11 +672,11 @@ sub processed_summary_string { my ( $problem, $c ) = @_; my ($duration_clause, $external_ref_clause); if ($problem->whensent) { - $duration_clause = $problem->duration_string($c) + $duration_clause = $problem->duration_string($c); } if ($problem->can_display_external_id) { if ($duration_clause) { - $external_ref_clause = sprintf(_('their ref: %s'), $problem->external_id); + $external_ref_clause = sprintf(_('council ref: %s'), $problem->external_id); } else { $external_ref_clause = sprintf(_('%s ref: %s'), $problem->external_body, $problem->external_id); } diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index a0320ccc3..d903f8eb2 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -65,6 +65,9 @@ sub email_alerts ($) { # call checks if this is the host that sends mail for this cobrand. next unless $cobrand->email_host; + # this is for the new_updates alerts + next if $row->{non_public} and $row->{user_id} != $row->{alert_user_id}; + my $hashref_restriction = $cobrand->site_restriction( $row->{cobrand_data} ); FixMyStreet::App->model('DB::AlertSent')->create( { @@ -91,7 +94,23 @@ sub email_alerts ($) { } # this is currently only for new_updates if ($row->{item_text}) { - $data{problem_url} = $url . "/report/" . $row->{id}; + if ( $row->{alert_user_id} == $row->{user_id} ) { + # This is an alert to the same user who made the report - make this a login link + my $user = FixMyStreet::App->model('DB::User')->find( { + id => $row->{alert_user_id} + } ); + $data{alert_email} = $user->email; + my $token_obj = FixMyStreet::App->model('DB::Token')->create( { + scope => 'email_sign_in', + data => { + email => $user->email, + r => 'report/' . $row->{id}, + } + } ); + $data{problem_url} = $url . "/M/" . $token_obj->token; + } else { + $data{problem_url} = $url . "/report/" . $row->{id}; + } $data{data} .= $row->{item_name} . ' : ' if $row->{item_name} && !$row->{item_anonymous}; $data{data} .= $row->{item_text} . "\n\n------\n\n"; # this is ward and council problems @@ -151,6 +170,7 @@ sub email_alerts ($) { where nearby.problem_id = problem.id and problem.user_id = users.id and problem.state in ($states) + and problem.non_public = 'f' and problem.confirmed >= ? and problem.confirmed >= ms_current_timestamp() - '7 days'::interval and (select whenqueued from alert_sent where alert_sent.alert_id = ? and alert_sent.parameter::integer = problem.id) is null and users.email <> ? @@ -210,13 +230,12 @@ sub _send_aggregated_alert_email(%) { unless -e $template; $template = Utils::read_file($template); - my $sender = $cobrand->contact_email; - (my $from = $sender) =~ s/team/fms-DO-NOT-REPLY/; # XXX + my $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL'); my $result = FixMyStreet::App->send_email_cron( { _template_ => $template, _parameters_ => \%data, - From => [ $from, _($cobrand->contact_name) ], + From => [ $sender, _($cobrand->contact_name) ], To => $data{alert_email}, }, $sender, diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm index 83fc85a88..191223572 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm @@ -8,6 +8,7 @@ sub nearby { my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval ) = @_; my $params = { + non_public => 0, state => [ FixMyStreet::DB::Result::Problem::visible_states() ], }; $params->{'current_timestamp-lastupdate'} = { '<', \"'$interval'::interval" } diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 4036c4b05..faed3b8ac 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -85,7 +85,8 @@ sub _recent { $key .= ":$site_key:$num"; my $query = { - state => [ FixMyStreet::DB::Result::Problem->visible_states() ], + non_public => 0, + state => [ FixMyStreet::DB::Result::Problem->visible_states() ], }; $query->{photo} = { '!=', undef } if $photos; @@ -141,6 +142,7 @@ sub around_map { $attr->{rows} = $limit if $limit; my $q = { + non_public => 0, state => [ FixMyStreet::DB::Result::Problem->visible_states() ], latitude => { '>=', $min_lat, '<', $max_lat }, longitude => { '>=', $min_lon, '<', $max_lon }, @@ -286,6 +288,16 @@ sub send_reports { $h{closest_address} = $cobrand->find_closest( $h{latitude}, $h{longitude}, $row ); } + if ( $cobrand->allow_anonymous_reports && + $row->user->email eq $cobrand->anonymous_account->{'email'} + ) { + $h{anonymous_report} = 1; + $h{user_details} = _('This report was submitted anonymously'); + } else { + $h{user_details} = sprintf(_('Name: %s'), $row->name) . "\n\n"; + $h{user_details} .= sprintf(_('Email: %s'), $row->user->email) . "\n\n"; + } + my %reporters = (); my ( $sender_count ); if ($site eq 'emptyhomes') { @@ -308,8 +320,8 @@ sub send_reports { foreach my $council (@councils) { my $name = $areas_info->{$council}->{name}; - my $sender = $cobrand->get_council_sender( $council, $areas_info->{$council} ); - $sender = "FixMyStreet::SendReport::$sender"; + my $sender_info = $cobrand->get_council_sender( $council, $areas_info->{$council}, $row->category ); + my $sender = "FixMyStreet::SendReport::" . $sender_info->{method}; if ( ! exists $senders->{ $sender } ) { warn "No such sender [ $sender ] for council $name ( $council )"; @@ -322,7 +334,7 @@ sub send_reports { $reporters{ $sender }->skipped; } else { push @dear, $name; - $reporters{ $sender }->add_council( $council, $areas_info->{$council} ); + $reporters{ $sender }->add_council( $council, $areas_info->{$council}, $sender_info->{config} ); } } @@ -334,6 +346,10 @@ sub send_reports { $h{category_line} = sprintf(_("Category: %s"), $h{category}) . "\n\n"; } + if ( $row->subcategory ) { + $h{subcategory_line} = sprintf(_("Subcategory: %s"), $row->subcategory) . "\n\n"; + } + $h{councils_name} = join(_(' and '), @dear); if ($h{category} eq _('Other')) { $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to both councils covering the location of the problem, as the user did not categorise it; please ignore it if you're not the correct council to deal with the issue, or let us know what category of problem this is so we can add it to our system.") . " ]\n\n" @@ -361,8 +377,33 @@ sub send_reports { if (mySociety::Config::get('STAGING_SITE')) { # on a staging server send emails to ourselves rather than the councils - my @testing_councils = split( '\|', mySociety::Config::get('TESTING_COUNCILS') || '' ); - unless ( grep { $row->council eq $_ } @testing_councils ) { + # however, we can configure a list of councils that we use non email + # delivery, e.g. Open311, for testing purposes. For those we want to + # send using the non email method and for everyone else we want to use + # email + my @testing_councils = split( '\|', mySociety::Config::get('TESTING_COUNCILS') ); + + # we only care about non missing councils so we get the missing ones + # and then essentially throw them away as we're not going to have + # configured them to do anything. + my %councils = map { $_ => 1 } @{ $row->councils }; + + # We now take the councils that we have contact details for and if any of them + # are in the list of testing councils we look a bit harder otherwise we throw + # away all the non email delivery methods + if ( grep { $councils{ $_ } } @testing_councils ) { + my %tc = map { $_ => 1 } @testing_councils; + my @non_matching = grep { !$tc{$_} } keys %councils; + for my $sender ( keys %reporters ) { + next if $sender =~ /FixMyStreet::SendReport::(Email|NI)/; + for my $council ( @non_matching ) { + $reporters{$sender}->delete_council( $council ); + } + } + if ( @non_matching ) { + $reporters{'FixMyStreet::SendReport::Email'} = FixMyStreet::SendReport::Email->new(); + } + } else { %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI)/ } keys %reporters; unless (%reporters) { %reporters = ( 'FixMyStreet::SendReport::Email' => FixMyStreet::SendReport::Email->new() ); @@ -393,6 +434,9 @@ sub send_reports { whensent => \'ms_current_timestamp()', lastupdate => \'ms_current_timestamp()', } ); + if ( $cobrand->report_sent_confirmation_email && !$h{anonymous_report}) { + _send_report_sent_email( $row, \%h, $nomail ); + } } else { my @errors; for my $sender ( keys %reporters ) { @@ -420,7 +464,48 @@ sub send_reports { } printf " %-24s %4d\n", "Total:", $c; } + my $sending_errors = ''; + my $unsent = FixMyStreet::App->model("DB::Problem")->search( { + state => [ 'confirmed', 'fixed' ], + whensent => undef, + council => { '!=', undef }, + send_fail_count => { '>', 0 } + } ); + while (my $row = $unsent->next) { + $sending_errors .= "* http://www.fixmystreet.com/report/" . $row->id . ", failed " + . $row->send_fail_count . " times, last at " . $row->send_fail_timestamp + . ", reason " . $row->send_fail_reason . "\n"; + } + if ($sending_errors) { + print "The following reports had problems sending:\n$sending_errors"; + } } } +sub _send_report_sent_email { + my $row = shift; + my $h = shift; + my $nomail = shift; + + my $template = 'confirm_report_sent.txt'; + 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; + $template_path = FixMyStreet->path_to( "templates", "email", "default", $template )->stringify + unless -e $template_path; + $template = Utils::read_file( $template_path ); + + my $result = FixMyStreet::App->send_email_cron( + { + _template_ => $template, + _parameters_ => $h, + To => $row->user->email, + From => mySociety::Config::get('CONTACT_EMAIL'), + }, + mySociety::Config::get('CONTACT_EMAIL'), + [ $row->user->email ], + $nomail + ); +} + 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm index bbf0c9a9e..1b9521a9f 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm @@ -62,7 +62,9 @@ sub send_questionnaires_period { ($template = $period) =~ s/ //; $template = Utils::read_file( FixMyStreet->path_to( "templates/email/emptyhomes/" . $row->lang . "/questionnaire-$template.txt" )->stringify ); } else { - $template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, "questionnaire.txt" )->stringify; + $template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, $row->lang, "questionnaire.txt" )->stringify; + $template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, "questionnaire.txt" )->stringify + unless -e $template; $template = FixMyStreet->path_to( "templates", "email", "default", "questionnaire.txt" )->stringify unless -e $template; $template = Utils::read_file( $template ); @@ -87,9 +89,8 @@ sub send_questionnaires_period { } ); $h{url} = $cobrand->base_url($row->cobrand_data) . '/Q/' . $token->token; - my $sender = $cobrand->contact_email; + my $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL'); my $sender_name = _($cobrand->contact_name); - $sender =~ s/team/fms-DO-NOT-REPLY/; print "Sending questionnaire " . $questionnaire->id . ", problem " . $row->id . ", token " . $token->token . " to " |