From 921d6f892d28426ae84c12d7388e508e7df2410b Mon Sep 17 00:00:00 2001 From: Moray Jones Date: Tue, 17 Oct 2023 11:34:06 +0100 Subject: [PATCH] [Bristol] Show correct Bristol categories on admin Bristol categories were being filtered out in the dropdown on a report's admin page for changing category. Broaden the checks in munge_overlapping_bodies and responsible_for_areas to check for more than the first area, as the report admin uses a larger pool of areas taken from the MapIt areas for the report location. --- perllib/FixMyStreet/Cobrand/Bristol.pm | 14 +++++++------ perllib/FixMyStreet/Cobrand/UKCouncils.pm | 2 +- t/cobrand/bristol.t | 24 +++++++++++++++++++++-- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/perllib/FixMyStreet/Cobrand/Bristol.pm b/perllib/FixMyStreet/Cobrand/Bristol.pm index bd3d39df547..9c249630f45 100644 --- a/perllib/FixMyStreet/Cobrand/Bristol.pm +++ b/perllib/FixMyStreet/Cobrand/Bristol.pm @@ -188,15 +188,17 @@ sub munge_overlapping_asset_bodies { my ($self, $bodies) = @_; my $all_areas = $self->{c}->stash->{all_areas}; - my $in_area = scalar(%$all_areas) == 1 && (values %$all_areas)[0]->{id} eq $self->council_area_id->[0]; - return if $in_area; - # If we get here, assume we are outside Bristol boundaries. - if ($self->check_report_is_on_cobrand_asset) { - # The report is in a park that Bristol is responsible for, so only show Bristol categories. + if (grep ($self->council_area_id->[0] == $_, keys %$all_areas)) { + # We are in the Bristol area so carry on as normal + return; + } elsif ($self->check_report_is_on_cobrand_asset) { + # We are not in a Bristol area but the report is in a park that Bristol is responsible for, + # so only show Bristol categories. %$bodies = map { $_->id => $_ } grep { $_->name eq $self->council_name } values %$bodies; } else { - # The report is not in a park that Bristol is responsible for, so only show other categories. + # We are not in a Bristol area and the report is not in a park that Bristol is responsible for, + # so only show other categories. %$bodies = map { $_->id => $_ } grep { $_->name ne $self->council_name } values %$bodies; } } diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index dc358443d62..e5d38d01918 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -191,7 +191,7 @@ sub responsible_for_areas { if ($self->can('check_report_is_on_cobrand_asset')) { # This will need changing for two tier councils - if (scalar(%$councils) == 1 && (values %$councils)[0]->{id} eq $self->council_area_id->[0]) { + if (grep ($self->council_area_id->[0] == $_, keys %$councils)) { return 1; } elsif ($self->check_report_is_on_cobrand_asset) { return 1; diff --git a/t/cobrand/bristol.t b/t/cobrand/bristol.t index 535a35cccdb..65012cd631a 100644 --- a/t/cobrand/bristol.t +++ b/t/cobrand/bristol.t @@ -4,6 +4,10 @@ my $mech = FixMyStreet::TestMech->new; use FixMyStreet::Script::Reports; use Open311::PopulateServiceList; use Test::MockModule; +use t::Mock::Tilma; + +my $tilma = t::Mock::Tilma->new; +LWP::Protocol::PSGI->register($tilma->to_psgi_app, host => 'tilma.mysociety.org'); # Create test data my $comment_user = $mech->create_user_ok('bristol@example.net'); @@ -14,6 +18,8 @@ my $bristol = $mech->create_body_ok( 2561, 'Bristol City Council', { }, { cobrand => 'bristol', }); +$comment_user->update({ from_body => $bristol->id }); +$comment_user->user_body_permissions->create({ body => $bristol, permission_type => 'report_edit' }); # Setup Bristol to cover North Somerset and South Gloucestershire $bristol->body_areas->create({ area_id => 2642 }); @@ -192,8 +198,6 @@ FixMyStreet::override_config { my $bristol_mock = Test::MockModule->new('FixMyStreet::Cobrand::Bristol'); $bristol_mock->mock('_fetch_features', sub { [] }); - - # Make sure we're handling National Highways correctly by testing on and off NH roads. my $national_highways_mock = Test::MockModule->new('FixMyStreet::Cobrand::HighwaysEngland'); @@ -246,6 +250,22 @@ FixMyStreet::override_config { $mech->content_lacks($south_gloucestershire_contact->category); $mech->content_contains($north_somerset_contact->category); }; + + subtest 'check report pages after creation' => sub { + $mech->host('bristol.fixmystreet.com'); + my ($p) = $mech->create_problems_for_body(1, $bristol->id, 'Title', { + cobrand => 'bristol', + category => $open311_contact->category, + latitude => 51.494885, + longitude => -2.602237, + areas => ',2561,66009,148659,164861,', + } ); + $mech->log_in_ok($comment_user->email); + $mech->get_ok('/admin/report_edit/' . $p->id); + $mech->content_contains('Flooding'); + $mech->content_contains('Inactive roadworks'); + }; + }; done_testing();