aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm49
-rw-r--r--t/app/controller/report_inspect.t36
-rw-r--r--templates/web/base/report/_inspect.html5
4 files changed, 69 insertions, 22 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 499bd55e0..fdbb6c638 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@
- Extra fields on contacts can be edited. #1743
- Clearer highlight for selected duplicate on inspect form. #1798
- Include MapIt API key on admin config page. #1778
+ - Redirect to same map view after inspection. #1820
- Bugfixes:
- Set up action scheduled field when report loaded. #1789
- Fix display of thumbnail images on page reload. #1815
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index c617f5733..60d373a16 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -316,6 +316,10 @@ sub inspect : Private {
$c->stash->{templates_by_category} = $templates_by_category;
}
+ if ($c->user->has_body_permission_to('planned_reports')) {
+ $c->stash->{post_inspect_url} = $c->req->referer;
+ }
+
if ( $c->get_param('save') ) {
$c->forward('/auth/check_csrf_token');
@@ -438,33 +442,36 @@ sub inspect : Private {
anonymous => 0,
%update_params,
} );
- # This problem might no longer be visible on the current cobrand,
- # if its body has changed (e.g. by virtue of the category changing)
- # so redirect to a cobrand where it can be seen if necessary
- $problem->discard_changes;
+
my $redirect_uri;
- if ( $c->cobrand->is_council && !$c->cobrand->owns_problem($problem) ) {
+ $problem->discard_changes;
+
+ # If inspector, redirect back to the map view they came from
+ # with the right filters. If that wasn't set, go to /around at this
+ # report's location.
+ # We go here rather than the shortlist because it makes it much
+ # simpler to inspect many reports in the same location. The
+ # shortlist is always a single click away, being on the main nav.
+ if ($c->user->has_body_permission_to('planned_reports')) {
+ unless ($redirect_uri = $c->get_param("post_inspect_url")) {
+ my $categories = join(',', @{ $c->user->categories });
+ my $params = {
+ lat => $problem->latitude,
+ lon => $problem->longitude,
+ };
+ $params->{filter_category} = $categories if $categories;
+ $params->{js} = 1 if $c->get_param('js');
+ $redirect_uri = $c->uri_for( "/around", $params );
+ }
+ } elsif ( $c->cobrand->is_council && !$c->cobrand->owns_problem($problem) ) {
+ # This problem might no longer be visible on the current cobrand,
+ # if its body has changed (e.g. by virtue of the category changing)
+ # so redirect to a cobrand where it can be seen if necessary
$redirect_uri = $c->cobrand->base_url_for_report( $problem ) . $problem->url;
} else {
$redirect_uri = $c->uri_for( $problem->url );
}
- # Or if inspector, redirect back to /around at this report's
- # location with the right filters. We go here rather than the
- # shortlist because it makes it much simpler to inspect many reports
- # in the same location. The shortlist is always a single click away,
- # being on the main nav.
- if ($c->user->has_body_permission_to('planned_reports')) {
- my $categories = join(',', @{ $c->user->categories });
- my $params = {
- lat => $problem->latitude,
- lon => $problem->longitude,
- };
- $params->{filter_category} = $categories if $categories;
- $params->{js} = 1 if $c->get_param('js');
- $redirect_uri = $c->uri_for( "/around", $params );
- }
-
$c->log->debug( "Redirecting to: " . $redirect_uri );
$c->res->redirect( $redirect_uri );
}
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 33486aa28..fcd7c724d 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -191,6 +191,42 @@ FixMyStreet::override_config {
$report->update({ state => $old_state });
};
+ subtest "post-inspect redirect is to the right place if URL set" => sub {
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'planned_reports' });
+ $mech->get_ok("/report/$report_id");
+ my $update_text = "This text was entered as an update by the user.";
+ $mech->submit_form_ok({ button => 'save', with_fields => {
+ public_update => $update_text,
+ include_update => "1",
+ post_inspect_url => "/"
+ }});
+ is $mech->res->code, 200, "got 200";
+ is $mech->res->previous->code, 302, "got 302 for redirect";
+ is $mech->uri->path, '/', 'redirected to front page';
+ $user->user_body_permissions->search({ body_id => $oxon->id, permission_type => 'planned_reports' })->delete;
+ };
+
+ subtest "post-inspect redirect is to the right place if URL not set" => sub {
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'planned_reports' });
+ $user->set_extra_metadata(categories => [ $contact->id ]);
+ $user->update;
+ $mech->get_ok("/report/$report_id");
+ my $update_text = "This text was entered as an update by the user.";
+ $mech->submit_form_ok({ button => 'save', with_fields => {
+ public_update => $update_text,
+ include_update => "1",
+ post_inspect_url => ""
+ }});
+ is $mech->res->code, 200, "got 200";
+ is $mech->res->previous->code, 302, "got 302 for redirect";
+ is $mech->uri->path, '/around', 'redirected to /around';
+ my %params = $mech->uri->query_form;
+ is $params{lat}, $report->latitude, "latitude param is correct";
+ is $params{lon}, $report->longitude, "longitude param is correct";
+ is $params{filter_category}, $contact->category, "categories param is correct";
+ $user->user_body_permissions->search({ body_id => $oxon->id, permission_type => 'planned_reports' })->delete;
+ };
+
foreach my $test (
{ type => 'report_edit_priority', priority => 1 },
{ type => 'report_edit_category', category => 1 },
diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html
index cd34b147b..fb58a0cfa 100644
--- a/templates/web/base/report/_inspect.html
+++ b/templates/web/base/report/_inspect.html
@@ -174,7 +174,10 @@
[% END %]
<p>
- <input type="hidden" name="token" value="[% csrf_token %]">
+ <input type="hidden" name="token" value="[% csrf_token %]" />
+ [% IF permissions.planned_reports %]
+ <input type="hidden" name="post_inspect_url" value="[% post_inspect_url | html %]" />
+ [% END %]
<input class="btn btn-primary" type="submit" value="[% loc('Save changes') %]" data-value-original="[% loc('Save changes') %]" data-value-duplicate="[% loc('Save + close as duplicate') %]" name="save" />
</p>
</div>