aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm23
-rw-r--r--t/open311/getservicerequestupdates.t30
3 files changed, 48 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 67f2da48d..bfe8c04fc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -51,6 +51,8 @@
- More JavaScript-enhanced `<select multiple>` elements #1589
- Council dashboard CSV export now has token based authentication #1911
- Consolidate various admin summary statistics page. #1919.
+ - 'Auto-response' flag on response templates is honoured for fetched
+ Open311 updates. #1924
- UK:
- Use SVG logo, inlined on front page. #1887
- Inline critical CSS on front page.
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index db2a452da..2620b176a 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -103,16 +103,17 @@ sub update_comments {
$problem = $self->schema->resultset('Problem')->to_body($body)->search( $criteria );
if (my $p = $problem->first) {
- next unless defined $request->{update_id} && defined $request->{description};
+ next unless defined $request->{update_id};
my $c = $p->comments->search( { external_id => $request->{update_id} } );
if ( !$c->first ) {
+ my $state = $self->map_state( $request->{status} );
my $comment = $self->schema->resultset('Comment')->new(
{
problem => $p,
user => $self->system_user,
external_id => $request->{update_id},
- text => $request->{description},
+ text => $self->comment_text_for_request($request, $p, $state),
mark_fixed => 0,
mark_open => 0,
anonymous => 0,
@@ -138,8 +139,6 @@ sub update_comments {
# do not change the status of the problem as it's
# tricky to determine the right thing to do.
if ( $comment->created > $p->lastupdate ) {
- my $state = $self->map_state( $request->{status} );
-
# don't update state unless it's an allowed state and it's
# actually changing the state of the problem
if ( FixMyStreet::DB::Result::Problem->visible_states()->{$state} && $p->state ne $state &&
@@ -180,6 +179,22 @@ sub update_comments {
return 1;
}
+sub comment_text_for_request {
+ my ($self, $request, $problem, $state) = @_;
+
+ return $request->{description} if $request->{description};
+
+ if (my $template = $problem->response_templates->search({
+ auto_response => 1,
+ 'me.state' => $state
+ })->first) {
+ return $template->text;
+ }
+
+ print STDERR "Couldn't determine update text for $request->{update_id} (report " . $problem->id . ")\n";
+ return "";
+}
+
sub map_state {
my $self = shift;
my $incoming_state = shift;
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index 9a8db4374..da427e505 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -20,11 +20,18 @@ my $user = FixMyStreet::DB->resultset('User')->find_or_create(
my %bodies = (
2237 => FixMyStreet::DB->resultset("Body")->create({ name => 'Oxfordshire' }),
- 2482 => FixMyStreet::DB->resultset("Body")->new({ id => 2482 }),
+ 2482 => FixMyStreet::DB->resultset("Body")->create({ name=> 'Bromley', id => 2482 }),
2651 => FixMyStreet::DB->resultset("Body")->new({ id => 2651 }),
);
$bodies{2237}->body_areas->create({ area_id => 2237 });
+my $response_template = $bodies{2482}->response_templates->create({
+ title => "investigating template",
+ text => "We are investigating this report.",
+ auto_response => 1,
+ state => "investigating"
+});
+
my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
<service_requests_updates>
<request_update>
@@ -157,6 +164,10 @@ for my $test (
end_state => 'confirmed',
},
+ # NB because we have an auto-response ResponseTemplate set up for
+ # the 'investigating' state, this test is also testing that the
+ # response template isn't used if the update XML has a non-empty
+ # <description>.
{
desc => 'investigating status changes problem status',
description => 'This is a note',
@@ -334,6 +345,18 @@ for my $test (
end_state => 'fixed - council',
},
{
+ desc => 'empty description triggers auto-response template',
+ description => 'We are investigating this report.',
+ xml_description => '',
+ external_id => 638344,
+ start_state => 'fixed - council',
+ comment_status => 'INVESTIGATING',
+ mark_fixed => 0,
+ mark_open => 0,
+ problem_state => 'investigating',
+ end_state => 'investigating',
+ },
+ {
desc => 'open status does not re-open hidden report',
description => 'This is a note',
external_id => 638344,
@@ -346,7 +369,7 @@ for my $test (
},
) {
subtest $test->{desc} => sub {
- my $local_requests_xml = setup_xml($problem->external_id, $problem->id, $test->{comment_status});
+ my $local_requests_xml = setup_xml($problem->external_id, $problem->id, $test->{comment_status}, $test->{xml_description});
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } );
$problem->lastupdate( DateTime->now()->subtract( days => 1 ) );
@@ -762,13 +785,14 @@ foreach my $test ( {
done_testing();
sub setup_xml {
- my ($id, $id_ext, $status) = @_;
+ my ($id, $id_ext, $status, $description) = @_;
my $xml = $requests_xml;
my $updated_datetime = sprintf( '<updated_datetime>%s</updated_datetime>', $dt );
$xml =~ s/UPDATED_DATETIME/$updated_datetime/;
$xml =~ s#<service_request_id>\d+</service_request_id>#<service_request_id>$id</service_request_id>#;
$xml =~ s#<service_request_id_ext>\d+</service_request_id_ext>#<service_request_id_ext>$id_ext</service_request_id_ext>#;
$xml =~ s#<status>\w+</status>#<status>$status</status># if $status;
+ $xml =~ s#<description>.+</description>#<description>$description</description># if defined $description;
return $xml;