diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-05-01 16:51:48 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-06-20 12:57:12 +0100 |
commit | 67ef55d16668102724fc23d2d95dcbc9705afed1 (patch) | |
tree | edc9b29c7f17b9e5a71d8cc1a80d274ba2984a34 | |
parent | 1aeca7c6130aa6de377c8e00e8d22ae05943e919 (diff) |
[Open311] Allow description in email template.
By specifying a placeholder in an email template, it can be replaced
by the description returned from the Open311 server.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | docs/_includes/admin-tasks-content.md | 11 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 17 | ||||
-rw-r--r-- | t/open311/getservicerequestupdates.t | 33 |
4 files changed, 53 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ffa67eb5..48098f0d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ marked private on the site. - Add new upload_files flag which sends files/photos as part of the POST service request. + - Allow description in email template with placeholder. * v2.6 (3rd May 2019) - New features: diff --git a/docs/_includes/admin-tasks-content.md b/docs/_includes/admin-tasks-content.md index 3f18a00dc..b04cc01ef 100644 --- a/docs/_includes/admin-tasks-content.md +++ b/docs/_includes/admin-tasks-content.md @@ -342,7 +342,7 @@ underway’ and ‘This issue is now closed’. From the report page, staff with the appropriate permissions may select from the ‘public update’ dropdown. This will prefill an update with template text for one of a number of common statuses. -The templates are created by the Administrator; see ‘[Creating response templates](#creating-and-editing-priorities)’. +The templates are created by the Administrator; see ‘[Creating response templates](#creating-editing-response-templates)’. The text in template responses is fully editable on the report page, so staff may also choose to add their own comments or edit the preformatted responses to reflect the precise circumstances of the @@ -379,7 +379,7 @@ details' must be ticked.</span> #### Setting a priority From the panel on the right hand side of a report, staff with the appropriate permissions may select a priority from a drop-down list. These priorities are created by Administrator-level users; -see ‘[Setting categories and priorities](#creating-and-editing-priorities) ’. +see ‘[Setting categories and priorities](#creating-editing-priorities) ’. </div> @@ -694,8 +694,11 @@ the ‘Resolved’ status update text is automatically applied. While this funct time-saver, we advise using it with caution to ensure that the template text is applicable to every situation in which is will be automatically applied. -If you have an Open311 connection, you can click ‘auto-response’ so that a template will be -applied when the state is updated by the automated Open311 process. +If you have an Open311 connection, you can click ‘auto-response’ so that a +template will be applied when the state is updated by the automated Open311 +process. In this instance, if your Open311 server returns extra text as part of +the update, you may put the placeholder `{{description}}` in the template here, +and that placeholder will be replaced by the text from the Open311 server. #### Editing or deleting a template diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 8193aaa9b..c0da7793f 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -235,13 +235,12 @@ sub comment_text_for_request { my ($self, $request, $problem, $state, $old_state, $ext_code, $old_ext_code) = @_; - return $request->{description} if $request->{description}; - # Response templates are only triggered if the state/external status has changed. # And treat any fixed state as fixed. my $state_changed = $state ne $old_state && !( $problem->is_fixed && FixMyStreet::DB::Result::Problem->fixed_states()->{$state} ); my $ext_code_changed = $ext_code ne $old_ext_code; + my $template; if ($state_changed || $ext_code_changed) { my $state_params = { 'me.state' => $state @@ -250,14 +249,24 @@ sub comment_text_for_request { $state_params->{'me.external_status_code'} = $ext_code; }; - if (my $template = $problem->response_templates->search({ + if (my $t = $problem->response_templates->search({ auto_response => 1, -or => $state_params, })->first) { - return $template->text; + $template = $t->text; } } + my $desc = $request->{description} || ''; + if ($desc && (!$template || $template !~ /\{\{description}}/)) { + return $desc; + } + + if ($template) { + $template =~ s/\{\{description}}/$desc/; + return $template; + } + return "" if $self->blank_updates_permitted; print STDERR "Couldn't determine update text for $request->{update_id} (report " . $problem->id . ")\n"; diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index 130b618c9..3cb2fda69 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -144,7 +144,7 @@ sub create_problem { detail => '', used_map => 1, user_id => 1, - name => '', + name => 'Test User', state => 'confirmed', service => '', cobrand => 'default', @@ -453,6 +453,37 @@ for my $test ( }; } +my $response_template_vars = $bodies{2482}->response_templates->create({ + title => "a placeholder action scheduled template", + text => "We are investigating this report: {{description}}", + auto_response => 1, + state => "action scheduled" +}); +subtest 'Check template placeholders' => sub { + my $local_requests_xml = setup_xml($problem->external_id, $problem->id, 'ACTION_SCHEDULED', 'We will do this in the morning.'); + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', extended_statuses => undef, test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } ); + + $problem->lastupdate( DateTime->now()->subtract( days => 1 ) ); + $problem->state( 'fixed - council' ); + $problem->update; + + my $update = Open311::GetServiceRequestUpdates->new; + $update->fetch($o); + + is $problem->comments->count, 1, 'comment count'; + $problem->discard_changes; + + my $c = FixMyStreet::DB->resultset('Comment')->search( { external_id => 638344 } )->first; + ok $c, 'comment exists'; + is $c->text, "We are investigating this report: We will do this in the morning.", 'text correct'; + is $c->mark_fixed, 0, 'mark_closed correct'; + is $c->problem_state, 'action scheduled', 'problem_state correct'; + is $c->mark_open, 0, 'mark_open correct'; + is $c->state, 'confirmed', 'comment state correct'; + is $problem->state, 'action scheduled', 'correct problem state'; + $problem->comments->delete; +}; + my $problemB = create_problem($bodies{2237}->id); for my $test ( |