aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Moderate.pm25
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm97
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm10
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm4
7 files changed, 80 insertions, 67 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index d757cec9a..75684c773 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -2211,13 +2211,14 @@ sub check_page_allowed : Private {
sub fetch_all_bodies : Private {
my ($self, $c ) = @_;
- my @bodies = $c->cobrand->call_hook('admin_fetch_all_bodies') || do {
+ my @bodies = $c->cobrand->call_hook('admin_fetch_all_bodies');
+ if (!@bodies) {
my $bodies = $c->model('DB::Body')->search(undef, {
columns => [ "id", "name", "deleted", "parent" ],
})->with_parent_name;
$bodies = $bodies->with_defect_type_count if $c->stash->{with_defect_type_count};
- $bodies->translated->all_sorted;
- };
+ @bodies = $bodies->translated->all_sorted;
+ }
$c->stash->{bodies} = \@bodies;
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
index 4b43be081..7979f31f6 100644
--- a/perllib/FixMyStreet/App/Controller/Dashboard.pm
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -446,7 +446,7 @@ sub generate_csv : Private {
split ',', $hashref->{areas};
}
- if ($obj->can('local_coords')) {
+ if ($obj->can('local_coords') && $asked_for{local_coords_x}) {
($hashref->{local_coords_x}, $hashref->{local_coords_y}) =
$obj->local_coords;
}
diff --git a/perllib/FixMyStreet/App/Controller/Moderate.pm b/perllib/FixMyStreet/App/Controller/Moderate.pm
index c47c34f37..d8fc38211 100644
--- a/perllib/FixMyStreet/App/Controller/Moderate.pm
+++ b/perllib/FixMyStreet/App/Controller/Moderate.pm
@@ -69,19 +69,40 @@ sub report : Chained('moderate') : PathPart('report') : CaptureArgs(1) {
sub moderate_report : Chained('report') : PathPart('') : Args(0) {
my ($self, $c) = @_;
+ my $problem = $c->stash->{problem};
+
# Make sure user can moderate this report
- $c->detach unless $c->user->can_moderate($c->stash->{problem});
+ $c->detach unless $c->user->can_moderate($problem);
$c->forward('report_moderate_hide');
my @types = grep $_,
- ($c->user->can_moderate_title($c->stash->{problem}, 1)
+ ($c->user->can_moderate_title($problem, 1)
? $c->forward('moderate_text', [ 'title' ])
: ()),
$c->forward('moderate_text', [ 'detail' ]),
$c->forward('moderate_boolean', [ 'anonymous', 'show_name' ]),
$c->forward('moderate_boolean', [ 'photo' ]);
+ # Deal with possible photo changes. If a moderate form uses a standard
+ # photo upload field (with upload_fileid, label and file upload handlers),
+ # this will allow photos to be changed, not just switched on/off. You will
+ # probably want a hidden field with problem_photo=1 to skip that check.
+ my $photo_edit_form = defined $c->get_param('photo1');
+ if ($photo_edit_form) {
+ $c->forward('/photo/process_photo');
+ if ( my $photo_error = delete $c->stash->{photo_error} ) {
+ $c->flash->{photo_error} = $photo_error;
+ } else {
+ my $fileid = $c->stash->{upload_fileid};
+ if ($fileid ne $problem->photo) {
+ $problem->get_photoset->delete_cached;
+ $problem->update({ photo => $fileid || undef });
+ push @types, 'photo';
+ }
+ }
+ }
+
$c->detach( 'report_moderate_audit', \@types )
}
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index 9a2a4f470..ed890ad82 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -210,7 +210,7 @@ sub planned_change : Path('planned/change') {
$c->res->content_type('application/json; charset=utf-8');
$c->res->body(encode_json({ outcome => $add ? 'add' : 'remove' }));
} else {
- $c->res->redirect( $c->uri_for_action('report/display', $id) );
+ $c->res->redirect( $c->uri_for_action('report/display', [ $id ]) );
}
}
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 854dbf3ea..d4ff0a2ca 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -20,8 +20,8 @@ Show a report
=head2 index
-Redirect to homepage unless C<id> parameter in query, in which case redirect to
-'/report/$id'.
+Redirect to homepage unless we have a homepage template,
+in which case show that.
=cut
@@ -35,13 +35,13 @@ sub index : Path('') : Args(0) {
}
}
-=head2 report_display
+=head2 id
-Display a report.
+Load in ID, for use by chained pages.
=cut
-sub display : Path('') : Args(1) {
+sub id :PathPart('report') :Chained :CaptureArgs(1) {
my ( $self, $c, $id ) = @_;
if (
@@ -49,15 +49,17 @@ sub display : Path('') : Args(1) {
|| $id =~ m{ ^(\d+) \D .* $ }x # trailing garbage
)
{
- return $c->res->redirect( $c->uri_for($1), 301 );
+ $c->res->redirect( $c->uri_for($1), 301 );
+ $c->detach;
}
- $c->forward( '_display', [ $id ] );
+ $c->forward( 'load_problem_or_display_error', [ $id ] );
}
=head2 ajax
-Return JSON formatted details of a report
+Return JSON formatted details of a report.
+URL used by mobile app so remains /report/ajax/N.
=cut
@@ -65,14 +67,20 @@ sub ajax : Path('ajax') : Args(1) {
my ( $self, $c, $id ) = @_;
$c->stash->{ajax} = 1;
- $c->forward( '_display', [ $id ] );
+ $c->forward('load_problem_or_display_error', [ $id ]);
+ $c->forward('display');
}
-sub _display : Private {
- my ( $self, $c, $id ) = @_;
+=head2 display
+
+Display a report.
+
+=cut
+
+sub display :PathPart('') :Chained('id') :Args(0) {
+ my ( $self, $c ) = @_;
$c->forward('/auth/get_csrf_token');
- $c->forward( 'load_problem_or_display_error', [ $id ] );
$c->forward( 'load_updates' );
$c->forward( 'format_problem_for_display' );
@@ -84,21 +92,14 @@ sub _display : Private {
}
}
-sub support : Path('support') : Args(0) {
+sub support :Chained('id') :Args(0) {
my ( $self, $c ) = @_;
- my $id = $c->get_param('id');
-
- my $uri =
- $id
- ? $c->uri_for( '/report', $id )
- : $c->uri_for('/');
-
- if ( $id && $c->cobrand->can_support_problems && $c->user && $c->user->from_body ) {
- $c->forward( 'load_problem_or_display_error', [ $id ] );
+ if ( $c->cobrand->can_support_problems && $c->user && $c->user->from_body ) {
$c->stash->{problem}->update( { interest_count => \'interest_count +1' } );
}
- $c->res->redirect( $uri );
+
+ $c->res->redirect($c->stash->{problem}->url);
}
sub load_problem_or_display_error : Private {
@@ -193,7 +194,7 @@ sub load_updates : Private {
$c->stash->{updates} = \@combined;
if ($c->sessionid) {
- foreach (qw(alert_to_reporter anonymized)) {
+ foreach (qw(alert_to_reporter anonymized photo_error)) {
$c->stash->{$_} = $c->flash->{$_} if $c->flash->{$_};
}
}
@@ -206,6 +207,9 @@ sub format_problem_for_display : Private {
my $problem = $c->stash->{problem};
+ # upload_fileid is used by the update form on this page
+ $c->stash->{problem_upload_fileid} = $problem->get_photoset->data;
+
( $c->stash->{latitude}, $c->stash->{longitude} ) =
map { Utils::truncate_coordinate($_) }
( $problem->latitude, $problem->longitude );
@@ -271,22 +275,18 @@ users too about this change, at which point we can delete:
=cut
-sub delete :Local :Args(1) {
- my ( $self, $c, $id ) = @_;
+sub delete :Chained('id') :Args(0) {
+ my ($self, $c) = @_;
$c->forward('/auth/check_csrf_token');
- $c->forward( 'load_problem_or_display_error', [ $id ] );
my $p = $c->stash->{problem};
- my $uri = $c->uri_for( '/report', $id );
-
- return $c->res->redirect($uri) unless $c->user_exists;
+ return $c->res->redirect($p->url) unless $c->user_exists;
my $body = $c->user->obj->from_body;
- return $c->res->redirect($uri) unless $body;
-
- return $c->res->redirect($uri) unless $p->bodies->{$body->id};
+ return $c->res->redirect($p->url) unless $body;
+ return $c->res->redirect($p->url) unless $p->bodies->{$body->id};
$p->state('hidden');
$p->lastupdate( \'current_timestamp' );
@@ -299,26 +299,10 @@ sub delete :Local :Args(1) {
admin_user => $c->user->from_body->name,
object_type => 'problem',
action => 'state_change',
- object_id => $id,
+ object_id => $p->id,
} );
- return $c->res->redirect($uri);
-}
-
-=head2 action_router
-
-A router for dispatching handlers for sub-actions on a particular report,
-e.g. /report/1/inspect
-
-=cut
-
-sub action_router : Path('') : Args(2) {
- my ( $self, $c, $id, $action ) = @_;
-
- $c->go( 'map', [ $id ] ) if $action eq 'map';
- $c->go( 'nearby_json', [ $id ] ) if $action eq 'nearby.json';
-
- $c->detach( '/page_error_404_not_found', [] );
+ return $c->res->redirect($p->url);
}
sub inspect : Private {
@@ -539,10 +523,8 @@ sub inspect : Private {
}
};
-sub map : Private {
- my ( $self, $c, $id ) = @_;
-
- $c->forward( 'load_problem_or_display_error', [ $id ] );
+sub map :Chained('id') :Args(0) {
+ my ($self, $c) = @_;
my $image = $c->stash->{problem}->static_map;
$c->res->content_type($image->{content_type});
@@ -550,10 +532,9 @@ sub map : Private {
}
-sub nearby_json : Private {
- my ( $self, $c, $id ) = @_;
+sub nearby_json :PathPart('nearby.json') :Chained('id') :Args(0) {
+ my ($self, $c) = @_;
- $c->forward( 'load_problem_or_display_error', [ $id ] );
my $p = $c->stash->{problem};
my $dist = 1;
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index f057a31f6..1a1a657a9 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -481,6 +481,9 @@ sub initialize_report : Private {
# save the token to delete at the end
$c->stash->{partial_token} = $token if $report;
+ $c->stash->{email} = $report->user->email;
+ $c->stash->{phone} = $report->user->phone_display;
+
} else {
# no point keeping it if it is done.
$token->delete;
@@ -807,6 +810,9 @@ sub process_user : Private {
$report->user( $user );
$c->forward('update_user', [ \%params ]);
+ $c->stash->{phone} = $report->user->phone_display;
+ $c->stash->{email} = $report->user->email;
+
if ($c->stash->{contributing_as_body} or $c->stash->{contributing_as_anonymous_user}) {
$report->name($user->from_body->name);
$user->name($user->from_body->name) unless $user->name;
@@ -832,6 +838,10 @@ sub process_user : Private {
$c->forward('update_user', [ \%params ]);
+ $c->stash->{phone} = Utils::trim_text( $type eq 'phone' ? $report->user->phone_display : $params{phone} );
+ $c->stash->{email} = Utils::trim_text( $type eq 'email' ? $report->user->email : $params{email} );
+
+
# The user is trying to sign in. We only care about username from the params.
if ( $c->get_param('submit_sign_in') || $c->get_param('password_sign_in') ) {
$c->stash->{tfa_data} = {
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index cb9bbdb67..dc46be61f 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -23,14 +23,14 @@ sub report_update : Path : Args(0) {
$c->forward('initialize_update');
$c->forward('load_problem');
$c->forward('check_form_submitted')
- or $c->go( '/report/display', [ $c->stash->{problem}->id ] );
+ or $c->go( '/report/display', [ $c->stash->{problem}->id ], [] );
$c->forward('/auth/check_csrf_token');
$c->forward('process_update');
$c->forward('process_user');
$c->forward('/photo/process_photo');
$c->forward('check_for_errors')
- or $c->go( '/report/display', [ $c->stash->{problem}->id ] );
+ or $c->go( '/report/display', [ $c->stash->{problem}->id ], [] );
$c->forward('save_update');
$c->forward('redirect_or_confirm_creation');