Skip to content

Commit

Permalink
[Notts Police] Allow staff to manage available states
Browse files Browse the repository at this point in the history
  • Loading branch information
davea committed Nov 12, 2024
1 parent f46c9a3 commit f4ea046
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
32 changes: 32 additions & 0 deletions perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,36 @@ sub example_places {
return [ 'NG2 3DZ', 'Meadows Way, Nottingham' ];
}

=head2 available_permissions
Add the manage_states permission to the list of available permissions.
=cut

sub available_permissions {
my $self = shift;
my $perms = $self->next::method();
$perms->{Problems}->{manage_states} = "Add/remove states";
return $perms;

Check warning on line 203 in perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm#L200-L203

Added lines #L200 - L203 were not covered by tests
}

=head2 admin_pages
Users with the manage_states permission can access the states admin page.
=cut

sub admin_pages {
my $self = shift;
my $pages = $self->next::method();

Check warning on line 214 in perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm#L213-L214

Added lines #L213 - L214 were not covered by tests

if ( $self->{c}->user->has_body_permission_to('manage_states') ) {
$pages->{states} = [ _('States'), 102 ];

Check warning on line 217 in perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm#L217

Added line #L217 was not covered by tests
};

return $pages;

Check warning on line 220 in perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm#L220

Added line #L220 was not covered by tests
}



1;
19 changes: 19 additions & 0 deletions t/cobrand/nottinghamshirepolice.t
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ FixMyStreet::override_config {
$report->discard_changes;
is $report->get_extra_metadata('sent_to_council'), 'Gedling Borough Council';
};

subtest 'check new permission is available' => sub {
$mech->log_in_ok($staff->email);
$staff->user_body_permissions->create({ body => $notts_police, permission_type => 'user_edit' });
$staff->user_body_permissions->create({ body => $notts_police, permission_type => 'user_manage_permissions' });

$mech->get("/admin/users/" . $staff->id);
$mech->content_contains('Add/remove states');
};

subtest 'check states page behind permission' => sub {
$mech->log_in_ok($staff->email);

$mech->get("/admin/states");
is $mech->status, 404, "Staff user can't access states page without permission";

$staff->user_body_permissions->create({ body => $notts_police, permission_type => 'manage_states' });
$mech->get_ok("/admin/states");
};
};

subtest 'Permissions for report updates' => sub {
Expand Down

0 comments on commit f4ea046

Please sign in to comment.