diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 25 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 6 |
2 files changed, 16 insertions, 15 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index b5e5c5738..aa2e09892 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -872,7 +872,6 @@ sub process_report : Private { 'partial', # 'service', # 'non_public', - 'single_body_only' ); # load the report @@ -931,8 +930,18 @@ sub process_report : Private { return 1; } - my $bodies = $c->forward('contacts_to_bodies', [ $report->category, $params{single_body_only} ]); - my $body_string = join(',', map { $_->id } @$bodies) || '-1'; + # 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. + my $body_string = do { + if (my $single_body_only = $c->get_param('single_body_only')) { + my $body = $c->model('DB::Body')->search({ name => $single_body_only })->first; + $body ? $body->id : '-1'; + } else { + my $bodies = $c->forward('contacts_to_bodies', [ $report->category ]); + join(',', map { $_->id } @$bodies) || '-1'; + } + }; $report->bodies_str($body_string); # Record any body IDs which might have meant to match, but had no contact @@ -988,18 +997,10 @@ sub process_report : Private { } sub contacts_to_bodies : Private { - my ($self, $c, $category, $single_body_only) = @_; + my ($self, $c, $category) = @_; 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 dff04176b..4022ba31a 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -960,9 +960,9 @@ foreach my $test ( email_count => 1, }, { - desc => "test invalid single_body_only means multiple report bodies", + desc => "test invalid single_body_only means no report bodies", category => 'Street lighting', - councils => [ 2226, 2326 ], + councils => [], extra_fields => { single_body_only => 'Invalid council' }, email_count => 1, }, @@ -1036,7 +1036,7 @@ foreach my $test ( ok $report, "Found the report"; # Check the report has been assigned appropriately - is $report->bodies_str, join(',', @body_ids{@{$test->{councils}}}); + is $report->bodies_str, join(',', @body_ids{@{$test->{councils}}}) || undef; $mech->content_contains('Thank you for reporting this issue'); |