diff options
author | Hakim Cassimally <hakim@mysociety.org> | 2015-04-11 15:27:04 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2015-10-06 09:09:24 +0100 |
commit | 2ff36453ebaa86e7f58f17ec63d2f95a88b8be99 (patch) | |
tree | e312b2d95f77434829e3e899a6fc6d3893028d52 | |
parent | 1fd5e4737072c7f6485238826bfbd8ebadaa9d45 (diff) |
[Zurich] prevent invalid bodies_str
See issue in mysociety/FixMyStreet-Commercial#663 with
problems not appearing in the "Erfasst" filter. It looks like Zurich
requires a single id in the `bodies_str` (like '4'), and may rely on the
configuration of bodies/contacts in database to be perfect to avoid them
becoming something like '4|47,48'.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 19 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Zurich.pm | 2 |
2 files changed, 19 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 6a884db7f..246facbee 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -890,8 +890,23 @@ sub process_report : Private { $report->bodies_str(-1); } else { # construct the bodies string: - # 'x,x' - x are body IDs that have this category - my $body_string = join( ',', map { $_->body_id } @contacts ); + my $body_string = do { + if ( $c->cobrand->can('singleton_bodies_str') && $c->cobrand->singleton_bodies_str ) { + # Cobrands like Zurich can only ever have a single body: 'x', because some functionality + # relies on string comparison against bodies_str. + if (@contacts) { + $contacts[0]->body_id; + } + else { + ''; + } + } + else { + # 'x,x' - x are body IDs that have this category + my $bs = join( ',', map { $_->body_id } @contacts ); + $bs; + }; + }; $report->bodies_str($body_string); # Record any body IDs which might have meant to match, but had no contact if ($body_string && @{ $c->stash->{missing_details_bodies} }) { diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm index c039deb0d..6b362d5a2 100644 --- a/perllib/FixMyStreet/Cobrand/Zurich.pm +++ b/perllib/FixMyStreet/Cobrand/Zurich.pm @@ -1034,4 +1034,6 @@ sub contact_details_data_body_default { sub reports_per_page { return 20; } +sub singleton_bodies_str { 1 } + 1; |