diff options
-rw-r--r-- | db/schema.sql | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Open311conf.pm | 10 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 16 | ||||
-rw-r--r-- | t/open311/getservicerequestupdates.t | 66 | ||||
-rw-r--r-- | templates/web/default/admin/council_contacts.html | 5 |
6 files changed, 100 insertions, 4 deletions
diff --git a/db/schema.sql b/db/schema.sql index cf70cef5c..13f992749 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -434,5 +434,6 @@ create table open311conf ( api_key text, send_method text, send_comments boolean not null default 'f', - comment_user_id int references users(id) + comment_user_id int references users(id), + suppress_alerts boolean not null default 'f' ); diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index d11f1645e..d6f613fd3 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -339,7 +339,7 @@ sub update_contacts : Private { } elsif ( $posted eq 'open311' ) { $c->forward('check_token'); - my %params = map { $_ => $c->req->param($_) } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments comment_user_id/; + my %params = map { $_ => $c->req->param($_) } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts comment_user_id/; if ( $params{open311_id} ) { my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } ); @@ -349,6 +349,7 @@ sub update_contacts : Private { $conf->api_key( $params{api_key} ); $conf->send_method( $params{send_method} ); $conf->send_comments( $params{send_comments} ); + $conf->suppress_alerts( $params{suppress_alerts} ); $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->update(); @@ -362,6 +363,7 @@ sub update_contacts : Private { $conf->api_key( $params{api_key} ); $conf->send_method( $params{send_method} ); $conf->send_comments( $params{send_comments} ); + $conf->suppress_alerts( $params{suppress_alerts} ); $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->insert(); diff --git a/perllib/FixMyStreet/DB/Result/Open311conf.pm b/perllib/FixMyStreet/DB/Result/Open311conf.pm index b9cd432ee..d040cd44b 100644 --- a/perllib/FixMyStreet/DB/Result/Open311conf.pm +++ b/perllib/FixMyStreet/DB/Result/Open311conf.pm @@ -32,6 +32,12 @@ __PACKAGE__->add_columns( { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "comment_user_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "username", + { data_type => "text", is_nullable => 1 }, + "password", + { data_type => "text", is_nullable => 1 }, + "suppress_alerts", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("open311conf_area_id_key", ["area_id"]); @@ -48,8 +54,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-26 17:03:34 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:fC6Ws8p/pXyjgqfm2LRKsw +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-05-11 13:07:38 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Mckkx2rjx9ug3+HaXKzw5g # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index b656da879..b5577ff6c 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -9,6 +9,7 @@ has council_list => ( is => 'ro' ); has system_user => ( is => 'rw' ); has start_date => ( is => 'ro', default => undef ); has end_date => ( is => 'ro', default => undef ); +has suppress_alerts => ( is => 'rw', default => 0 ); sub fetch { my $self = shift; @@ -30,6 +31,7 @@ sub fetch { jurisdiction => $council->jurisdiction, ); + $self->suppress_alerts( $council->suppress_alerts ); $self->system_user( $council->comment_user ); $self->update_comments( $o, { areaid => $council->area_id }, ); } @@ -110,6 +112,20 @@ sub update_comments { } $comment->insert(); + + if ( $self->suppress_alerts ) { + my $alert = FixMyStreet::App->model('DB::Alert')->find( { + alert_type => 'new_updates', + parameter => $p->id, + confirmed => 1, + user_id => $p->user->id, + } ); + + my $alerts_sent = FixMyStreet::App->model('DB::AlertSent')->find_or_create( { + alert_id => $alert->id, + parameter => $comment->id, + } ); + } } } } diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index 062a9e2f1..92d03e385 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -455,6 +455,72 @@ foreach my $test ( { }; } +foreach my $test ( { + desc => 'normally alerts are not suppressed', + suppress_alerts => 0, + }, + { + desc => 'alerts suppressed if suppress_alerts set', + suppress_alerts => 1, + } +) { + subtest $test->{desc} => sub { + my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?> + <service_requests_updates> + <request_update> + <update_id>638344</update_id> + <service_request_id>@{[ $problem->external_id ]}</service_request_id> + <service_request_id_ext>@{[ $problem->id ]}</service_request_id_ext> + <status>closed</status> + <description>This is a note</description> + <updated_datetime>UPDATED_DATETIME</updated_datetime> + </request_update> + </service_requests_updates> + }; + + $problem->comments->delete; + $problem->state( 'confirmed' ); + $problem->lastupdate( $dt->subtract( hours => 3 ) ); + $problem->update; + + my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( { + alert_type => 'new_updates', + parameter => $problem->id, + confirmed => 1, + user_id => $problem->user->id, + } ); + + $requests_xml =~ s/UPDATED_DATETIME/$dt/; + + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $requests_xml } ); + + my $update = Open311::GetServiceRequestUpdates->new( + system_user => $user, + suppress_alerts => $test->{suppress_alerts}, + ); + + my $council_details = { areaid => 2482 }; + $update->update_comments( $o, $council_details ); + $problem->discard_changes; + + my $alerts_sent = FixMyStreet::App->model('DB::AlertSent')->search( + { + alert_id => $alert->id, + parameter => $problem->comments->first->id, + } + ); + + if ( $test->{suppress_alerts} ) { + ok $alerts_sent->count(), 'alerts suppressed'; + } else { + is $alerts_sent->count(), 0, 'alerts not suppressed'; + } + + $alerts_sent->delete; + $alert->delete; + } +} + $problem2->comments->delete(); $problem->comments->delete(); $problem2->delete; diff --git a/templates/web/default/admin/council_contacts.html b/templates/web/default/admin/council_contacts.html index e4bee707f..d0e385ae6 100644 --- a/templates/web/default/admin/council_contacts.html +++ b/templates/web/default/admin/council_contacts.html @@ -137,6 +137,11 @@ </p> <p> + <label for="suppress_alerts">Do not send email alerts on fetched comments to problem creator</label>: + <input type="checkbox" name="suppress_alerts"[% ' checked' IF conf.suppress_alerts %]> + </p> + + <p> <input type="hidden" name="open311_id" value="[% conf.id %]"> <input type="hidden" name="area_id" value="[% area_id %]"> <input type="hidden" name="posted" value="open311"> |