diff --git a/perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm b/perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm index dc7242efb6..05e438812a 100644 --- a/perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm +++ b/perllib/FixMyStreet/Cobrand/NottinghamshirePolice.pm @@ -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; +} + +=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(); + + if ( $self->{c}->user->has_body_permission_to('manage_states') ) { + $pages->{states} = [ _('States'), 102 ]; + }; + + return $pages; +} + + + 1; diff --git a/t/cobrand/nottinghamshirepolice.t b/t/cobrand/nottinghamshirepolice.t index 2bb7b61859..66c78d3ac3 100644 --- a/t/cobrand/nottinghamshirepolice.t +++ b/t/cobrand/nottinghamshirepolice.t @@ -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 {