Skip to content

Commit

Permalink
[Bromley] Allow reporting on 3 assets outside Bromley area
Browse files Browse the repository at this point in the history
  • Loading branch information
MorayMySoc committed May 24, 2024
1 parent 097b453 commit 788fb35
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
28 changes: 27 additions & 1 deletion perllib/FixMyStreet/Cobrand/Bromley.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ with 'FixMyStreet::Roles::Open311Multi';
with 'FixMyStreet::Roles::Cobrand::SCP';
with 'FixMyStreet::Roles::Cobrand::BulkyWaste';

sub council_area_id { return 2482; }
sub council_area_id { return [2482]; }
sub council_area { return 'Bromley'; }
sub council_name { return 'Bromley Council'; }
sub council_url { return 'bromley'; }
Expand Down Expand Up @@ -148,6 +148,32 @@ sub title_list {
return ["MR", "MISS", "MRS", "MS", "DR", 'PCSO', 'PC', 'N/A'];
}

sub check_report_is_on_cobrand_asset {
my ($self, $council_area) = shift @_;

if ($self->{c}->get_param('feature_id') && $self->{c}->get_param('feature_id') =~ /A-48-24|A-48-26|A-48-27/) {
return 1;
} else {
return 0;
}
}

sub munge_overlapping_asset_bodies {
my ($self, $bodies) = @_;

# in_bromley will be true if the point is within the administrative area of Bromley
my $in_bromley = grep ($self->council_area_id->[0] == $_, keys %{$self->{c}->stash->{all_areas}});

# cobrand will be true if the point is within an area of different responsibility from the norm
my $cobrand = $self->check_report_is_on_cobrand_asset;
if (!$in_bromley && $cobrand) {
my $bromley = FixMyStreet::DB->resultset('Body')->find({ name => $self->council_name });
%$bodies = map { $_->id => $_ } grep { $_->name ne 'Lewisham Borough Council' } values %$bodies;
%$bodies = map { $_->id => $_ } grep { $_->name ne 'TfL' } values %$bodies;
$$bodies{$bromley->id} = $bromley;
}
}

sub waste_check_staff_payment_permissions {
my $self = shift;
my $c = $self->{c};
Expand Down
5 changes: 5 additions & 0 deletions perllib/FixMyStreet/Cobrand/FixMyStreet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ sub munge_report_new_bodies {
my $brent = FixMyStreet::Cobrand::Brent->new({ c => $self->{c} });
$brent->munge_overlapping_asset_bodies($bodies);
}

if ( $bodies{'Lewisham Borough Council'} ) {
my $bromley = FixMyStreet::Cobrand::Bromley->new({ c => $self->{c} });
$bromley->munge_overlapping_asset_bodies($bodies);
}
}

sub munge_report_new_contacts {
Expand Down
2 changes: 2 additions & 0 deletions t/Mock/MapIt.pm
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ my @PLACES = (
[ 'NE61 1BE', 55.169081, -1.691012, 2248, 'Northumberland County Council', 'UTA' ],
[ 'SG17 5TQ', 52.03553, -0.36067, 21070, 'Central Bedfordshire Council', 'UTA' ],
[ '?', 51.558568, -0.207702, 2489, 'Barnet Borough Council', 'DIS' ],
[ '?', 51.418776, 0.005357, 2492, 'Lewisham Borough Council', 'DIS' ],

);

sub dispatch_request {
Expand Down
61 changes: 60 additions & 1 deletion t/cobrand/bromley.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ LWP::Protocol::PSGI->register($tilma->to_psgi_app, host => 'tilma.mysociety.org'

# Create test data
my $user = $mech->create_user_ok( '[email protected]', name => 'Bromley' );
my $standard_user = $mech->create_user_ok('[email protected]', name => 'Bob Betts');
my $body = $mech->create_body_ok( 2482, 'Bromley Council', {
can_be_devolved => 1, send_extended_statuses => 1, comment_user => $user,
send_method => 'Open311', endpoint => 'http://endpoint.example.com', jurisdiction => 'FMS', api_key => 'test', send_comments => 1
}, {
cobrand => 'bromley'
});
my $lewisham = $mech->create_body_ok( 2492, 'Lewisham Borough Council');
my $staffuser = $mech->create_user_ok( '[email protected]', name => 'Staffie', from_body => $body );
my $role = FixMyStreet::DB->resultset("Role")->create({
body => $body, name => 'Role A', permissions => ['moderate', 'user_edit', 'report_mark_private', 'report_inspect', 'contribute_as_body'] });
Expand All @@ -46,7 +48,17 @@ $contact->set_extra_fields(
{ code => 'service_request_id_ext', datatype => 'number', },
);
$contact->update;
my $tfl = $mech->create_body_ok( 2482, 'TfL');
my $streetlights = $mech->create_contact_ok(
body_id => $body->id,
category => 'Streetlights',
email => 'LIGHT',
);
$streetlights->set_extra_fields(
{ code => 'feature_id', datatype => 'string', automated => 'hidden_field' },
);
$streetlights->update;

my $tfl = $mech->create_body_ok( 2482, 'TfL', {}, { cobrand => 'tfl' });
$mech->create_contact_ok(
body_id => $tfl->id,
category => 'Traffic Lights',
Expand Down Expand Up @@ -612,4 +624,51 @@ for my $test (
};
}

subtest 'Can select asset that is in Lewisham area on Bromley Cobrand' => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => ['bromley', 'tfl'],
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->log_in_ok('[email protected]');
$mech->get_ok('/report/new/?longitude=0.005357&latitude=51.418776');
$mech->content_contains('That location is not covered by Bromley Council', 'Area in Lewisham not reportable on Bromley cobrand');
$mech->get_ok('/report/new/?longitude=-0.071410&latitude=51.419275&category=Streetlights');
$mech->submit_form_ok( { with_fields => {
title => 'Lamp issue in Lewisham on Bromley',
detail => 'Lamp issue over the border',
feature_id => 'A-48-24',
longitude => 0.005357,
latitude => 51.418776,
fms_extra_title => 'Mr'
}}, 'Location in Lewisham ok as clicked from Bromley location onto Bromley asset');
my $problem = FixMyStreet::DB->resultset("Problem")->search(undef, { order_by => { -desc => 'id' } })->first;
is $problem->title, 'Lamp issue in Lewisham on Bromley', 'Report has been made';
is $problem->body, 'Bromley Council', 'Problem on correct body';
};
};

subtest 'Can select asset that is in Lewisham area on FMS' => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => ['fixmystreet', 'tfl'],
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->log_in_ok('[email protected]');
$mech->get_ok('/report/new/?longitude=0.005357&latitude=51.418776');
$mech->content_contains('We do not yet have details for the council that covers this location', 'Lewisham does not have Bromley categories');
$mech->get_ok('/report/new/?longitude=-0.071410&latitude=51.419275&category=Streetlights');
$mech->submit_form_ok( { with_fields => {
title => 'Lamp issue in Lewisham on FMS',
detail => 'Lamp issue over the border',
feature_id => 'A-48-26',
longitude => 0.005357,
latitude => 51.418776,
fms_extra_title => 'Mr'
}}, 'Location in Lewisham ok as clicked from Bromley location onto Bromley asset');
my $problem = FixMyStreet::DB->resultset("Problem")->search(undef, { order_by => { -desc => 'id' } })->first;
is $problem->title, 'Lamp issue in Lewisham on FMS', 'Report has been made';
is $problem->body, 'Bromley Council', 'Problem on correct body';
};
};


done_testing();

0 comments on commit 788fb35

Please sign in to comment.