diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-12-20 09:43:38 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-12-20 14:24:51 +0000 |
commit | 5724c6adf8db7cca611fcc000e6fa4e995fcc2bd (patch) | |
tree | 5d2dfe04d5606d07413e113af9f2ea0ddbac9d6f | |
parent | 649692298b0b870b161a3f8b755f46b16b534e48 (diff) |
Show all questionnaire responses lacking updates.
Since questionnaire responses were recorded on email link click, we
should have been showing those that reopened or fixed reports, not
just steady-state "Still open" ones.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 32 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Questionnaire.pm | 7 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 18 | ||||
-rw-r--r-- | templates/web/base/report/updates.html | 9 |
5 files changed, 59 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index cdd389ca9..a2bb6104e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Bugfixes: - Restore map zoom out when navigating to /around from /report. #1649 - Don’t escape HTML entities in report titles pulled in by ajax. #2346 + - Show reopening/fixed questionnaire responses lacking updates. #2357 - Open311 improvements: - Fix bug in contact group handling. #2323 - Improve validation of fetched reports timestamps. #2327 diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 10aabd1fd..58ce64af6 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -186,14 +186,30 @@ sub load_updates : Private { { order_by => [ 'confirmed', 'id' ] } ); - my $questionnaires = $c->model('DB::Questionnaire')->search( + my $questionnaires_still_open = $c->model('DB::Questionnaire')->search( { problem_id => $c->stash->{problem}->id, whenanswered => { '!=', undef }, - old_state => [ -and => - { -in => [ FixMyStreet::DB::Result::Problem::closed_states, FixMyStreet::DB::Result::Problem::open_states ] }, - \'= new_state', - ] + -or => [ { + # Any steady state open/closed + old_state => [ -and => + { -in => [ FixMyStreet::DB::Result::Problem::closed_states, FixMyStreet::DB::Result::Problem::open_states ] }, + \'= new_state', + ], + }, { + # Any reopening + new_state => 'confirmed', + } ] + }, + { order_by => 'whenanswered' } + ); + + my $questionnaires_fixed = $c->model('DB::Questionnaire')->search( + { + problem_id => $c->stash->{problem}->id, + whenanswered => { '!=', undef }, + old_state => { -not_in => [ FixMyStreet::DB::Result::Problem::fixed_states ] }, + new_state => { -in => [ FixMyStreet::DB::Result::Problem::fixed_states ] }, }, { order_by => 'whenanswered' } ); @@ -206,13 +222,17 @@ sub load_updates : Private { $questionnaires_with_updates{$qid} = $update; } } - while (my $q = $questionnaires->next) { + while (my $q = $questionnaires_still_open->next) { if (my $update = $questionnaires_with_updates{$q->id}) { $update->set_extra_metadata('open_from_questionnaire', 1); next; } push @combined, [ $q->whenanswered, $q ]; } + while (my $q = $questionnaires_fixed->next) { + next if $questionnaires_with_updates{$q->id}; + push @combined, [ $q->whenanswered, $q ]; + } @combined = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @combined; $c->stash->{updates} = \@combined; diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm index 30f2ab7ce..6b7ab9452 100644 --- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm @@ -57,4 +57,11 @@ my $stz = sub { around whensent => $stz; around whenanswered => $stz; +sub marks_fixed { + my $self = shift; + my $new_fixed = FixMyStreet::DB::Result::Problem->fixed_states()->{$self->new_state}; + my $old_fixed = FixMyStreet::DB::Result::Problem->fixed_states()->{$self->old_state}; + return $new_fixed && !$old_fixed; +} + 1; diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 9a95c296e..76594a74a 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -186,6 +186,20 @@ subtest "several updates shown in correct order" => sub { old_state => 'confirmed', new_state => 'fixed - user', }, + { # One reopening, no associated update + problem_id => $report_id, + whensent => '2011-03-16 08:12:36', + whenanswered => '2011-03-16 08:12:36', + old_state => 'fixed - user', + new_state => 'confirmed', + }, + { # One marking fixed, no associated update + problem_id => $report_id, + whensent => '2011-03-17 08:12:36', + whenanswered => '2011-03-17 08:12:36', + old_state => 'confirmed', + new_state => 'fixed - user', + }, ) { my $q = FixMyStreet::App->model('DB::Questionnaire')->find_or_create( $fields @@ -240,13 +254,15 @@ subtest "several updates shown in correct order" => sub { $mech->get_ok("/report/$report_id"); my $meta = $mech->extract_update_metas; - is scalar @$meta, 6, 'number of updates'; + is scalar @$meta, 8, 'number of updates'; is $meta->[0], 'Posted by Other User at 12:23, Thu 10 March 2011', 'first update'; is $meta->[1], 'Posted by Main User at 12:23, Thu 10 March 2011 Still open, via questionnaire', 'second update'; is $meta->[2], 'Still open, via questionnaire, 12:23, Fri 11 March 2011', 'questionnaire'; is $meta->[3], 'Still open, via questionnaire, 12:23, Sat 12 March 2011', 'questionnaire'; is $meta->[4], 'State changed to: Fixed', 'third update, part 1'; is $meta->[5], 'Posted anonymously at 08:12, Tue 15 March 2011', 'third update, part 2'; + is $meta->[6], 'Still open, via questionnaire, 08:12, Wed 16 March 2011', 'reopen questionnaire'; + is $meta->[7], 'Questionnaire filled in by problem reporter; State changed to: Fixed, 08:12, Thu 17 March 2011', 'fix questionnaire'; $report->questionnaires->delete; }; diff --git a/templates/web/base/report/updates.html b/templates/web/base/report/updates.html index 1d37c1d99..817cc7eb4 100644 --- a/templates/web/base/report/updates.html +++ b/templates/web/base/report/updates.html @@ -12,9 +12,16 @@ [% BLOCK meta_line %] [% IF update.whenanswered %] + [% IF update.marks_fixed %] + [%# A questionnaire update that marked the report fixed %] + [% loc("Questionnaire filled in by problem reporter") %]; + [% loc('State changed to:') %] [% prettify_state('fixed') %], + [% prettify_dt( update.whenanswered ) %] + [% ELSE %] [%# A questionnaire update, currently saying report is still open %] [% loc('Still open, via questionnaire') %], [% prettify_dt( update.whenanswered ) %] - [% RETURN %] + [% END %] + [% RETURN %] [% END %] [% update.meta_line(c) %] |