aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-06-18 15:42:46 +0100
committerStruan Donald <struan@exo.org.uk>2012-06-18 15:42:46 +0100
commit01f7b57818a2732ee4fcca2480019595b9bd5380 (patch)
tree7a4533b00d1c4cab166ebfdff58f06a2440ad0ba
parent42b6c0bafd69db408c1c5664081dbd9dd174b411 (diff)
Change alerts on council cobrands so they link to main
site if sending alerts about problems not covered by the cobrand. Also remove cobrand restriction from local area alerts
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/AlertType.pm15
-rw-r--r--t/app/model/alert_type.t144
2 files changed, 155 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
index 32654e534..26d8f32a9 100644
--- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
@@ -65,6 +65,8 @@ sub email_alerts ($) {
# call checks if this is the host that sends mail for this cobrand.
next unless $cobrand->email_host;
+ my ( $sql_restriction, $name_restictions, $hashref_restriction ) = $cobrand->site_restriction( $row->{cobrand_data} );
+
FixMyStreet::App->model('DB::AlertSent')->create( {
alert_id => $row->{alert_id},
parameter => $row->{item_id},
@@ -84,6 +86,9 @@ sub email_alerts ($) {
}
my $url = $cobrand->base_url_for_emails( $row->{alert_cobrand_data} );
+ if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} ne $hashref_restriction->{council} ) {
+ $url = mySociety::Config::get('BASE_URL');
+ }
# this is currently only for new_updates
if ($row->{item_text}) {
$data{problem_url} = $url . "/report/" . $row->{id};
@@ -136,8 +141,7 @@ sub email_alerts ($) {
my $longitude = $alert->parameter;
my $latitude = $alert->parameter2;
- my $url = $cobrand->base_url_for_emails( $alert->cobrand_data );
- my ($site_restriction, $site_id) = $cobrand->site_restriction( $alert->cobrand_data );
+ my ($site_restriction, $site_id, $hashref_restriction) = $cobrand->site_restriction( $alert->cobrand_data );
my $d = mySociety::Gaze::get_radius_containing_population($latitude, $longitude, 200000);
# Convert integer to GB locale string (with a ".")
$d = mySociety::Locale::in_gb_locale {
@@ -145,14 +149,13 @@ sub email_alerts ($) {
};
my $states = "'" . join( "', '", FixMyStreet::DB::Result::Problem::visible_states() ) . "'";
my %data = ( template => $template, data => '', alert_id => $alert->id, alert_email => $alert->user->email, lang => $alert->lang, cobrand => $alert->cobrand, cobrand_data => $alert->cobrand_data );
- my $q = "select problem.id, problem.postcode, problem.geocode, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users
+ my $q = "select problem.id, problem.council, problem.postcode, problem.geocode, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users
where nearby.problem_id = problem.id
and problem.user_id = users.id
and problem.state in ($states)
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 <> ?
- $site_restriction
order by confirmed desc";
$q = dbh()->prepare($q);
$q->execute($latitude, $longitude, $d, $alert->whensubscribed, $alert->id, $alert->user->email);
@@ -161,6 +164,10 @@ sub email_alerts ($) {
alert_id => $alert->id,
parameter => $row->{id},
} );
+ my $url = $cobrand->base_url_for_emails( $alert->cobrand_data );
+ if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} ne $hashref_restriction->{council} ) {
+ $url = mySociety::Config::get('BASE_URL');
+ }
my $postcode = $cobrand->format_postcode( $row->{postcode} );
$postcode = ", $postcode" if $postcode;
$data{data} .= $url . "/report/" . $row->{id} . " - $row->{title}$postcode\n\n";
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
index 67ddc10aa..c23252de6 100644
--- a/t/app/model/alert_type.t
+++ b/t/app/model/alert_type.t
@@ -347,6 +347,150 @@ foreach my $test (
};
}
+my $ward_alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
+ {
+ user => $user,
+ parameter => 7117,
+ alert_type => 'area_problems',
+ whensubscribed => $dt->ymd . ' ' . $dt->hms,
+ confirmed => 1,
+ cobrand => 'lichfielddc',
+ }
+);
+
+my $report_to_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'WS13 6YY',
+ council => '2434',
+ areas => ',105255,11806,11828,2247,2504,7117,',
+ category => 'Other',
+ title => 'council report',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'closed',
+ confirmed => $now->ymd . ' ' . $now->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '52.727588',
+ longitude => '-1.731322',
+ user_id => $user2->id,
+ }
+);
+
+my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'WS13 6YY',
+ council => '2240',
+ areas => ',105255,11806,11828,2247,2504,7117,',
+ category => 'Other',
+ title => 'county report',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'closed',
+ confirmed => $now->ymd . ' ' . $now->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '52.727588',
+ longitude => '-1.731322',
+ user_id => $user2->id,
+ }
+);
+
+my $report_outside_district = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'WS13 6YY',
+ council => '2221',
+ areas => ',105255,11806,11828,2247,2504,7117,',
+ category => 'Other',
+ title => 'outside district report',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'closed',
+ confirmed => $now->ymd . ' ' . $now->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '52.7352866189',
+ longitude => '-1.69540489214',
+ user_id => $user2->id,
+ }
+);
+
+subtest "check alerts from cobrand send main site url for alerts for different council" => sub {
+ $mech->clear_emails_ok;
+
+ my $sent = FixMyStreet::App->model('DB::AlertSent')->search(
+ {
+ alert_id => $ward_alert->id,
+ }
+ )->delete;
+
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+
+ $mech->email_count_is( 1 );
+ my $email = $mech->get_email;
+ my $body = $email->body;
+
+ my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_council->id;
+ my $expected3 = mySociety::Config::get('BASE_URL') . '/report/' . $report_outside_district->id;
+ my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('lichfielddc')->new();
+ my $expected2 = $cobrand->base_url_for_emails . '/report/' . $report_to_council->id;
+
+ like $body, qr#$expected1#, 'non cobrand area report point to fixmystreet.com';
+ like $body, qr#$expected2#, 'cobrand area report point to cobrand url';
+ like $body, qr#$expected3#, 'report outside district report point to fixmystreet.com';
+};
+
+
+my $local_alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
+ {
+ user => $user,
+ parameter => -1.731322,
+ parameter2 => 52.727588,
+ alert_type => 'local_problems',
+ whensubscribed => $dt->ymd . ' ' . $dt->hms,
+ cobrand => 'lichfielddc',
+ confirmed => 1,
+ }
+);
+
+subtest "check local alerts from cobrand send main site url for alerts for different council" => sub {
+ $mech->clear_emails_ok;
+
+ my $sent = FixMyStreet::App->model('DB::AlertSent')->search(
+ {
+ alert_id => $local_alert->id,
+ }
+ )->delete;
+
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+
+ $mech->email_count_is( 1 );
+ my $email = $mech->get_email;
+ my $body = $email->body;
+
+ my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_council->id;
+ my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('lichfielddc')->new();
+ my $expected2 = $cobrand->base_url_for_emails . '/report/' . $report_to_council->id;
+
+ like $body, qr#$expected1#, 'non cobrand area report point to fixmystreet.com';
+ like $body, qr#$expected2#, 'cobrand area report point to cobrand url';
+};
+
$report->comments->delete();
$report->delete();
done_testing();