aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-10-20 16:17:31 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-10-24 12:20:48 +0100
commita034e22c5ce2d8f67091ee45d4c479b488919ef1 (patch)
tree221da830f653dd642f4b7f02abde9ddd01c7a2ad
parente12e5a7685b4ae5dcfeaf931adde2dbb91ef745f (diff)
Have report page show inspect form if available.
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm32
-rw-r--r--t/app/controller/report_inspect.t23
-rw-r--r--templates/web/base/report/_inspect.html2
-rw-r--r--templates/web/base/report/_main.html12
-rw-r--r--templates/web/base/report/inspect.html3
5 files changed, 28 insertions, 44 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index db3b16dcd..f69bdc8c0 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -78,6 +78,13 @@ sub _display : Private {
$c->forward( 'load_problem_or_display_error', [ $id ] );
$c->forward( 'load_updates' );
$c->forward( 'format_problem_for_display' );
+
+ my $permissions = $c->stash->{_permissions} = $c->forward( 'check_has_permission_to',
+ [ qw/report_inspect report_edit_category report_edit_priority/ ] );
+ if (any { $_ } values %$permissions) {
+ $c->stash->{template} = 'report/inspect.html';
+ $c->forward('inspect');
+ }
}
sub support : Path('support') : Args(0) {
@@ -292,23 +299,15 @@ e.g. /report/1/inspect
sub action_router : Path('') : Args(2) {
my ( $self, $c, $id, $action ) = @_;
- $c->go( 'inspect', [ $id ] ) if $action eq 'inspect';
$c->go( 'map', [ $id ] ) if $action eq 'map';
$c->detach( '/page_error_404_not_found', [] );
}
sub inspect : Private {
- my ( $self, $c, $id ) = @_;
-
- $c->forward('/auth/get_csrf_token');
- $c->forward( 'load_problem_or_display_error', [ $id ] );
- my $permissions = $c->forward( 'check_has_permission_to',
- [ qw/report_inspect report_edit_category report_edit_priority/ ] );
- $c->forward( 'load_updates' );
- $c->forward( 'format_problem_for_display' );
-
+ my ( $self, $c ) = @_;
my $problem = $c->stash->{problem};
+ my $permissions = $c->stash->{_permissions};
$c->stash->{categories} = $c->forward('/admin/categories_for_point');
$c->stash->{report_meta} = { map { $_->{name} => $_ } @{ $c->stash->{problem}->get_extra_fields() } };
@@ -347,7 +346,7 @@ sub inspect : Private {
$problem->get_photoset->delete_cached;
}
if ( $problem->state ne $old_state ) {
- $c->forward( '/admin/log_edit', [ $id, 'problem', 'state_change' ] );
+ $c->forward( '/admin/log_edit', [ $problem->id, 'problem', 'state_change' ] );
}
}
@@ -391,7 +390,7 @@ sub inspect : Private {
anonymous => 0,
} );
}
- $c->res->redirect( $c->uri_for( '/report', $problem->id, 'inspect' ) );
+ $c->res->redirect( $c->uri_for( '/report', $problem->id ) );
}
}
};
@@ -416,14 +415,9 @@ to the current Problem in $c->stash->{problem}. Shows the 403 page if not.
sub check_has_permission_to : Private {
my ( $self, $c, @permissions ) = @_;
-
+ return {} unless $c->user_exists;
my $bodies = $c->stash->{problem}->bodies_str_ids;
-
- my %permissions = map { $_ => $c->user->has_permission_to($_, $bodies) } @permissions
- if $c->user_exists;
- $c->detach('/page_error_403_access_denied', [ _("Sorry, you don't have permission to do that.") ] )
- unless $c->user_exists && any { $_ } values %permissions;
-
+ my %permissions = map { $_ => $c->user->has_permission_to($_, $bodies) } @permissions;
return \%permissions;
};
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 831959fff..cfa76ebb3 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -31,18 +31,21 @@ FixMyStreet::override_config {
}, sub {
subtest "test inspect page" => sub {
$mech->get_ok("/report/$report_id");
- $mech->content_lacks('Inspect');
- $mech->content_lacks('Manage');
+ $mech->content_lacks('Save changes');
+ $mech->content_lacks('Priority');
+ $mech->content_lacks('Traffic management');
$user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_priority' });
$mech->get_ok("/report/$report_id");
- $mech->content_contains('Manage');
- $mech->follow_link_ok({ text => 'Manage' });
+ $mech->content_contains('Save changes');
+ $mech->content_contains('Priority');
+ $mech->content_lacks('Traffic management');
$user->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' });
$mech->get_ok("/report/$report_id");
- $mech->content_contains('Inspect');
- $mech->follow_link_ok({ text => 'Inspect' });
+ $mech->content_contains('Save changes');
+ $mech->content_contains('Priority');
+ $mech->content_contains('Traffic management');
};
subtest "test basic inspect submission" => sub {
@@ -56,7 +59,7 @@ FixMyStreet::override_config {
$report->unset_extra_metadata('inspected');
$report->update;
my $reputation = $report->user->get_extra_metadata("reputation");
- $mech->get_ok("/report/$report_id/inspect");
+ $mech->get_ok("/report/$report_id");
$mech->submit_form_ok({ button => 'save', with_fields => { public_update => "This is a public update.", save_inspected => "1" } });
$report->discard_changes;
is $report->comments->first->text, "This is a public update.", 'Update was created';
@@ -68,7 +71,7 @@ FixMyStreet::override_config {
$report->unset_extra_metadata('inspected');
$report->update;
$report->comments->delete_all;
- $mech->get_ok("/report/$report_id/inspect");
+ $mech->get_ok("/report/$report_id");
$mech->submit_form_ok({ button => 'save', with_fields => { public_update => undef, save_inspected => "1" } });
is_deeply $mech->page_errors, [ "Please provide a public update for this report." ], 'errors match';
$report->discard_changes;
@@ -77,7 +80,7 @@ FixMyStreet::override_config {
};
subtest "test location changes" => sub {
- $mech->get_ok("/report/$report_id/inspect");
+ $mech->get_ok("/report/$report_id");
$mech->submit_form_ok({ button => 'save', with_fields => { latitude => 55, longitude => -2 } });
$mech->content_contains('Invalid location');
$mech->submit_form_ok({ button => 'save', with_fields => { latitude => 51.754926, longitude => -1.256179 } });
@@ -92,7 +95,7 @@ FixMyStreet::override_config {
subtest "test $test->{type} permission" => sub {
$user->user_body_permissions->delete;
$user->user_body_permissions->create({ body => $oxon, permission_type => $test->{type} });
- $mech->get_ok("/report/$report_id/inspect");
+ $mech->get_ok("/report/$report_id");
$mech->contains_or_lacks($test->{priority}, 'Priority');
$mech->contains_or_lacks($test->{priority}, 'High');
$mech->contains_or_lacks($test->{category}, 'Category');
diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html
index 34a7ea96c..b85fec0bb 100644
--- a/templates/web/base/report/_inspect.html
+++ b/templates/web/base/report/_inspect.html
@@ -4,7 +4,7 @@
<div id="side-inspect">
[% INCLUDE 'errors.html' %]
- <form id="report_inspect_form" method="post" action="[% c.uri_for( '/report', problem.id, 'inspect' ) %]">
+ <form id="report_inspect_form" method="post" action="[% c.uri_for( '/report', problem.id ) %]">
<div class="inspect-section">
<p>
diff --git a/templates/web/base/report/_main.html b/templates/web/base/report/_main.html
index 0a4056da7..4de26535c 100644
--- a/templates/web/base/report/_main.html
+++ b/templates/web/base/report/_main.html
@@ -119,24 +119,12 @@
[% IF
(permissions.moderate)
OR
- (!hide_inspect_button AND
- permissions.keys.grep('report_inspect|report_edit_category|report_edit_priority').size)
- OR
(c.user.has_permission_to('planned_reports', problem.bodies_str_ids))
%]
<div class="moderate-display segmented-control" role="menu">
[% IF permissions.moderate %]
<a class="js-moderate btn" role="menuitem" aria-label="[% loc('Moderate this report') %]">[% loc('Moderate') %]</a>
[% END %]
- [% IF !hide_inspect_button AND permissions.keys.grep('report_inspect|report_edit_category|report_edit_priority').size %]
- <a class="btn" href="/report/[% problem.id %]/inspect#side-inspect" role="menuitem">
- [%~ IF permissions.report_inspect ~%]
- [%~ loc('Inspect') ~%]
- [%~ ELSE ~%]
- [%~ loc('Manage') ~%]
- [%~ END ~%]
- </a>
- [% END %]
[% IF c.user.has_permission_to('planned_reports', problem.bodies_str_ids) %]
[%~ IF c.user.is_planned_report(problem) ~%]
<label class="btn" for="shortlist-report" role="menuitem" aria-label="[% loc('Remove from shortlist') %]">[% loc('Shortlisted') %]</label>
diff --git a/templates/web/base/report/inspect.html b/templates/web/base/report/inspect.html
index f4a9e4c46..7f02374e2 100644
--- a/templates/web/base/report/inspect.html
+++ b/templates/web/base/report/inspect.html
@@ -2,6 +2,5 @@
SET bodyclass = 'mappage with-actions';
SET two_column_sidebar = 1;
PROCESS 'report/_inspect.html';
- SET shown_form = 1 UNLESS problem.get_extra_metadata('inspected');
- INCLUDE 'report/display.html', hide_inspect_button = 1;
+ INCLUDE 'report/display.html'
%]