Skip to content

Commit

Permalink
[Bristol] Show correct Bristol categories on admin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MorayMySoc authored and dracos committed Oct 18, 2023
1 parent 05316e1 commit 921d6f8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
14 changes: 8 additions & 6 deletions perllib/FixMyStreet/Cobrand/Bristol.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/Cobrand/UKCouncils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 22 additions & 2 deletions t/cobrand/bristol.t
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]');
Expand All @@ -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 });
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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();

0 comments on commit 921d6f8

Please sign in to comment.