aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2020-01-06 09:55:12 +0000
committerDave Arter <davea@mysociety.org>2020-01-06 09:55:12 +0000
commit9d876bf9829ec3b00240707ff4ba04b1a1265317 (patch)
tree98d900a05b8082b410c7535f540c32a29b9cc031
parent36fc093d2fe61bca3cbf44d2a6e9c8bc795714cd (diff)
Fix 'all reports' link for users with categories but no from_body
In the rare situation that a user has no from_body set but does have categories set in their extra metadata, the 'All reports' link would point to /my/inspector_redirect but this URL would 404 if the user did not have a from_body. This commit updates the template to use the same logic when generating the 'all reports' link, so users without from_body will never be sent to /my/inspector_redirect. Fixes #2815.
-rw-r--r--t/app/controller/report_inspect.t13
-rw-r--r--templates/web/base/navigation/_all_reports.html2
2 files changed, 14 insertions, 1 deletions
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index aeb344922..8deb2667e 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -119,12 +119,23 @@ FixMyStreet::override_config {
good_link => "/reports",
bad_link => "/my/inspector_redirect",
},
+ {
+ name => "categories but no from_body",
+ area_ids => undef,
+ categories => [ $contact->id ],
+ destination => "/my",
+ query_form => {},
+ good_link => "/reports",
+ bad_link => "/my/inspector_redirect",
+ unset_from_body => 1,
+ },
) {
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->from_body(undef) if $test->{unset_from_body};
$user->update;
# Can't use log_in_ok, as the call to logged_in_ok clobbers our post-login
@@ -144,6 +155,8 @@ FixMyStreet::override_config {
$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} );
+
+ $user->update( { from_body => $oxon } ) if $test->{unset_from_body};
};
}
diff --git a/templates/web/base/navigation/_all_reports.html b/templates/web/base/navigation/_all_reports.html
index bcc40ed5d..3f2aa6bbc 100644
--- a/templates/web/base/navigation/_all_reports.html
+++ b/templates/web/base/navigation/_all_reports.html
@@ -1,5 +1,5 @@
[%~
- IF c.user_exists AND ( c.user.categories.size OR c.user.area_ids.size );
+ IF c.user_exists AND c.user.from_body AND ( c.user.categories.size OR c.user.area_ids.size );
reports_uri = '/my/inspector_redirect';
ELSE;
reports_uri = '/reports';