aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth.pm23
-rw-r--r--t/app/controller/report_inspect.t68
2 files changed, 73 insertions, 18 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm
index 4660f45dd..6badbf518 100644
--- a/perllib/FixMyStreet/App/Controller/Auth.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth.pm
@@ -388,8 +388,11 @@ sub redirect_on_signin : Private {
}
unless ( $redirect ) {
- $c->detach('redirect_to_categories') if $c->user->from_body && scalar @{ $c->user->categories };
- $redirect = 'my';
+ my $inspector = $c->user->from_body && (
+ scalar @{ $c->user->categories } ||
+ scalar @{ $c->user->area_ids || [] }
+ );
+ $redirect = $inspector ? 'my/inspector_redirect' : 'my';
}
$redirect = 'my' if $redirect =~ /^admin/ && !$c->cobrand->admin_allow_user($c->user);
if ( $c->cobrand->moniker eq 'zurich' ) {
@@ -402,22 +405,6 @@ sub redirect_on_signin : Private {
}
}
-=head2 redirect_to_categories
-
-Redirects the user to their body's reports page, prefiltered to whatever
-categories this user has been assigned to.
-
-=cut
-
-sub redirect_to_categories : Private {
- my ( $self, $c ) = @_;
-
- my $categories = $c->user->categories_string;
- my $body_short = $c->cobrand->short_name( $c->user->from_body );
-
- $c->res->redirect( $c->uri_for( "/reports/" . $body_short, { filter_category => $categories } ) );
-}
-
=head2 redirect
Used when trying to view a page that requires sign in when you're not.
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 6ba4fe115..afd8d6d17 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -79,6 +79,74 @@ FixMyStreet::override_config {
$mech->content_lacks('/admin/report_edit/'.$report_id.'">admin</a>)');
};
+ for my $test (
+ {
+ name => "categories only",
+ area_ids => undef,
+ categories => [ $contact->id ],
+ destination => "/reports/Oxfordshire",
+ previous => "/my/inspector_redirect",
+ query_form => { filter_category => $contact->category },
+ good_link => "/my/inspector_redirect",
+ bad_link => "/reports",
+ },
+ {
+ name => "categories and areas",
+ area_ids => [60705],
+ categories => [ $contact->id ],
+ destination => "/reports/Oxfordshire/Trowbridge",
+ previous => "/my/inspector_redirect",
+ query_form => { filter_category => $contact->category },
+ good_link => "/my/inspector_redirect",
+ bad_link => "/reports",
+ },
+ {
+ name => "areas only",
+ area_ids => [60705],
+ categories => undef,
+ destination => "/reports/Oxfordshire/Trowbridge",
+ previous => "/my/inspector_redirect",
+ query_form => {},
+ good_link => "/my/inspector_redirect",
+ bad_link => "/reports",
+ },
+ {
+ name => "no categories or areas",
+ area_ids => undef,
+ categories => undef,
+ destination => "/my",
+ query_form => {},
+ good_link => "/reports",
+ bad_link => "/my/inspector_redirect",
+ },
+ ) {
+ subtest "login destination and top-level nav for inspectors with " . $test->{name} => sub {
+ $mech->log_out_ok;
+
+ $user->area_ids($test->{area_ids});
+ $user->set_extra_metadata('categories', $test->{categories});
+ $user->update;
+
+ # Can't use log_in_ok, as the call to logged_in_ok clobbers our post-login
+ # redirect.
+ $mech->get_ok('/auth');
+ $mech->submit_form_ok(
+ { with_fields => { username => $user->email, password_sign_in => 'secret' } },
+ "sign in using form" );
+ is $mech->res->code, 200, "got 200";
+ is $mech->uri->path, $test->{destination}, 'redirected to correct destination';
+ is_deeply { $mech->uri->query_form }, $test->{query_form}, 'destination query params set correctly';
+ if ($test->{previous}) {
+ is $mech->res->previous->code, 302, "got 302 for post-login redirect";
+ is $mech->res->previous->base->path, $test->{previous}, "previous URI correct";
+ }
+
+ $mech->get_ok("/");
+ ok $mech->find_link( text => 'All reports', url => $test->{good_link} );
+ ok !$mech->find_link( text => 'All reports', url => $test->{bad_link} );
+ };
+ }
+
subtest "council staff can't see admin report edit link on FMS.com" => sub {
my $report_edit_permission = $user->user_body_permissions->create({
body => $oxon, permission_type => 'report_edit' });