diff options
author | Struan Donald <struan@exo.org.uk> | 2018-03-26 17:09:26 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2018-04-03 11:08:21 +0100 |
commit | a253bba519da66f2b0d3de09de895b5364de277f (patch) | |
tree | 0338b92787ad50a9d673c70ff2895400d9c37d19 | |
parent | 9971657aaf579c37a91f546b01aaee7d96c9db38 (diff) |
limit problem body to single body if required
Add a single_body_only form value to reports that contains the name of
the only body to send the problem to. If the name doesn't match any of
the valid bodies for the report then send to all.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 13 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 25 | ||||
-rw-r--r-- | templates/web/base/report/new/form_report.html | 1 |
3 files changed, 35 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 82787e9da..312268f65 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -875,6 +875,7 @@ sub process_report : Private { 'partial', # 'service', # 'non_public', + 'single_body_only' ); # load the report @@ -932,7 +933,7 @@ sub process_report : Private { return 1; } - my $bodies = $c->forward('contacts_to_bodies', [ $report->category ]); + my $bodies = $c->forward('contacts_to_bodies', [ $report->category, $params{single_body_only} ]); my $body_string = join(',', map { $_->id } @$bodies) || '-1'; $report->bodies_str($body_string); @@ -982,10 +983,18 @@ sub process_report : Private { } sub contacts_to_bodies : Private { - my ($self, $c, $category) = @_; + my ($self, $c, $category, $single_body_only) = @_; my @contacts = grep { $_->category eq $category } @{$c->stash->{contacts}}; + # check that we've not indicated we only want to sent to a single body + # and if we find a matching one then only send to that. e.g. if we clicked + # on a TfL road on the map. + if ($single_body_only) { + my @contacts_filtered = grep { $_->body->name eq $single_body_only } @contacts; + @contacts = @contacts_filtered if scalar @contacts_filtered; + } + if ($c->stash->{unresponsive}{$category} || $c->stash->{unresponsive}{ALL} || !@contacts) { []; } else { diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index f937acd19..0e7547a85 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -944,9 +944,29 @@ foreach my $test ( # XXX add test for category with multiple bodies foreach my $test ( - { category => 'Street lighting', councils => [ 2226, 2326 ] }, + { + desc => "test report creation for multiple bodies", + category => 'Street lighting', + councils => [ 2226, 2326 ], + extra_fields => {}, + email_count => 2, + }, + { + desc => "test single_body_only means only one report body", + category => 'Street lighting', + councils => [ 2326 ], + extra_fields => { single_body_only => 'Cheltenham Borough Council' }, + email_count => 1, + }, + { + desc => "test invalid single_body_only means multiple report bodies", + category => 'Street lighting', + councils => [ 2226, 2326 ], + extra_fields => { single_body_only => 'Invalid council' }, + email_count => 1, + }, ) { - subtest "test report creation for multiple bodies" => sub { + subtest $test->{desc} => sub { # check that the user does not exist my $test_email = 'test-2@example.com'; @@ -1003,6 +1023,7 @@ foreach my $test ( may_show_name => '1', phone => '07903 123 456', category => $test->{category}, + %{$test->{extra_fields}} } }, "submit good details" diff --git a/templates/web/base/report/new/form_report.html b/templates/web/base/report/new/form_report.html index 1d1a0e289..9fce25248 100644 --- a/templates/web/base/report/new/form_report.html +++ b/templates/web/base/report/new/form_report.html @@ -63,4 +63,5 @@ <input type="hidden" name="partial" value="[% partial_token.token %]"> [% END %] + <input type="hidden" id="single_body_only" name="single_body_only" value=""> <input type="hidden" name="submit_problem" value="1"> |