Skip to content

Commit

Permalink
[.com] Add ability to have additional parish areas
Browse files Browse the repository at this point in the history
This adds a configuration value containing the MapIt IDs of parish areas
for which we want to be able to add bodies in the system.

Include the Bucks parishes by default.
  • Loading branch information
dracos committed Oct 25, 2024
1 parent f0c93e6 commit 506d2bd
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ sub body_form_dropdowns : Private {
# Some cobrands may want to add extra areas at runtime beyond those
# available via MAPIT_WHITELIST or MAPIT_TYPES. This can be used for,
# e.g., parish councils on a particular council cobrand.
$areas = $c->cobrand->call_hook("add_extra_areas" => $areas) || $areas;
$areas = $c->cobrand->call_hook("add_extra_areas_for_admin" => $areas) || $areas;

$c->stash->{areas} = [ sort { strcoll($a->{name}, $b->{name}) } values %$areas ];

Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ sub _parish_ids {
}

# Enable adding/editing of parish councils in the admin
sub add_extra_areas {
sub add_extra_areas_for_admin {
my ($self, $areas) = @_;

my $ids_string = join ",", @{ $self->_parish_ids };
Expand Down
20 changes: 20 additions & 0 deletions perllib/FixMyStreet/Cobrand/FixMyStreet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,26 @@ sub reopening_disallowed {
return $self->next::method($problem);
}

=head2 add_extra_areas_for_admin
Add the parish IDs from Buckinghamshire's cobrand, plus any other IDs from
configuration, so that we can manually add specific parish councils.
=cut

sub add_extra_areas_for_admin {
my ($self, $areas) = @_;

my $bucks = FixMyStreet::Cobrand::Buckinghamshire->new;
my @extra = @{ $bucks->_parish_ids };
my $extra = $self->feature('extra_parishes') || [];
push @extra, @$extra;
my $ids_string = join ",", @extra;
my $extra_areas = mySociety::MaPit::call('areas', [ $ids_string ]);
my %all_areas = ( %$areas, %$extra_areas );
return \%all_areas;
}

=head2 fetch_area_children
If we are looking at the All Reports page for one of the extra London (TfL)
Expand Down
10 changes: 8 additions & 2 deletions t/Mock/MapIt.pm
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,15 @@ sub dispatch_request {
}
},

sub (POST + /areas) {
sub (POST + /areas + %*) {
my ($self, $areas) = @_;
$self->output({53319 => {parent_area => 2217, id => 53319, name => "Bradenham", type => "CPC"}});
my $out = {
53319 => { parent_area => 2217, id => 53319, name => "Bradenham", type => "CPC" },
};
if ($areas->{URL} =~ /59087/) {
$out->{59087} = { parent_area => 2538, id => 59087, name => "Castle Bromwich", type => "CPC" },
}
$self->output($out);
},

sub (GET + .geojson) {
Expand Down
22 changes: 22 additions & 0 deletions t/cobrand/fixmystreet.t
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ subtest 'check heatmap page for cllr' => sub {

FixMyStreet::override_config {
ALLOWED_COBRANDS => 'fixmystreet',
MAPIT_URL => 'http://mapit.uk/',
COBRAND_FEATURES => {
extra_parishes => {
fixmystreet => [ 59087 ],
}
}
}, sub {
subtest 'test enforced 2FA for superusers' => sub {
my $test_email = 'test@example.com';
Expand All @@ -223,6 +229,22 @@ FixMyStreet::override_config {
{ with_fields => { username => $test_email, password_sign_in => 'password' } },
"sign in using form" );
$mech->content_contains('requires two-factor');

# Sign up for 2FA
$mech->submit_form_ok({ with_fields => { '2fa_action' => 'activate' } }, "submit 2FA activation");
my ($token) = $mech->content =~ /name="secret32" value="([^"]*)">/;
use Auth::GoogleAuth;
my $auth = Auth::GoogleAuth->new({ secret32 => $token });
my $code = $auth->code;
$mech->submit_form_ok({ with_fields => { '2fa_code' => $code } }, "provide correct 2FA code" );
$mech->content_contains('successfully enabled two-factor authentication', "2FA activated");
};

subtest 'test extra parish areas' => sub {
$mech->get_ok('/admin/bodies/add');
$mech->content_contains('Bradenham');
$mech->content_contains('Castle Bromwich');
$mech->log_out_ok;
};
};

Expand Down

0 comments on commit 506d2bd

Please sign in to comment.