aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Report/Update.pm
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
committerMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
commit09dacfc6b8bf62addeee16c20b1d90c2a256da96 (patch)
tree7caa2bf9e92227ab74448f9b746dd28bbcb81b2a /perllib/FixMyStreet/App/Controller/Report/Update.pm
parent585e57484f9c6332668bf1ac0a6a3b39dbe32223 (diff)
parentcea89fb87a96943708a1db0f646492fbfaaf000f (diff)
Merge tag 'v3.1' into fiksgatami-devfiksgatami-dev
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm52
1 files changed, 39 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 41c42b8a1..2acafc654 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -6,7 +6,6 @@ BEGIN { extends 'Catalyst::Controller'; }
use utf8;
use Path::Class;
-use List::Util 'first';
use Utils;
=head1 NAME
@@ -103,8 +102,14 @@ sub process_user : Private {
my %params = map { $_ => $c->get_param($_) }
( 'name', 'password_register', 'fms_extra_title' );
- # Update form includes two username fields: #form_username_register and #form_username_sign_in
- $params{username} = (first { $_ } $c->get_param_list('username')) || '';
+ if ($c->user_exists) {
+ $params{username} = $c->get_param('username');
+ } elsif ($c->get_param('submit_sign_in') || $c->get_param('password_sign_in')) {
+ $params{username} = $c->get_param('username');
+ } else {
+ $params{username} = $c->get_param('username_register');
+ }
+ $params{username} ||= '';
my $anon_button = $c->cobrand->allow_anonymous_reports eq 'button' && $c->get_param('report_anonymously');
if ($anon_button) {
@@ -121,7 +126,7 @@ sub process_user : Private {
if ( $c->user_exists ) { {
my $user = $c->user->obj;
- if ($c->stash->{contributing_as_another_user} = $user->contributing_as('another_user', $c, $update->problem->bodies_str_ids)) {
+ if ($c->stash->{contributing_as_another_user} = $user->contributing_as('another_user', $c, $c->stash->{problem}->bodies_str_ids)) {
# Act as if not logged in (and it will be auto-confirmed later on)
last;
}
@@ -145,8 +150,7 @@ sub process_user : Private {
my $parsed = FixMyStreet::SMS->parse_username($params{username});
my $type = $parsed->{type} || 'email';
$type = 'email' unless FixMyStreet->config('SMS_AUTHENTICATION') || $c->stash->{contributing_as_another_user};
- $update->user( $c->model('DB::User')->find_or_new( { $type => $parsed->{username} } ) )
- unless $update->user;
+ $update->user( $c->model('DB::User')->find_or_new( { $type => $parsed->{username} } ) );
$c->stash->{phone_may_be_mobile} = $type eq 'phone' && $parsed->{may_be_mobile};
@@ -248,7 +252,7 @@ sub load_problem : Private {
# Problem ID could come from existing update in token, or from query parameter
my $problem_id = $update->problem_id || $c->get_param('id');
$c->forward( '/report/load_problem_or_display_error', [ $problem_id ] );
- $update->problem($c->stash->{problem});
+ $update->problem_id($c->stash->{problem}->id);
}
=head2 check_form_submitted
@@ -282,7 +286,8 @@ sub process_update : Private {
my $name = Utils::trim_text( $params{name} );
- $params{reopen} = 0 unless $c->user && $c->user->id == $c->stash->{problem}->user->id;
+ my $problem = $c->stash->{problem};
+ $params{reopen} = 0 unless $c->user && $c->user->id == $problem->user->id;
my $update = $c->stash->{update};
$update->text($params{update});
@@ -290,11 +295,11 @@ sub process_update : Private {
$update->mark_fixed($params{fixed} ? 1 : 0);
$update->mark_open($params{reopen} ? 1 : 0);
- $c->stash->{contributing_as_body} = $c->user_exists && $c->user->contributing_as('body', $c, $update->problem->bodies_str_ids);
- $c->stash->{contributing_as_anonymous_user} = $c->user_exists && $c->user->contributing_as('anonymous_user', $c, $update->problem->bodies_str_ids);
+ $c->stash->{contributing_as_body} = $c->user_exists && $c->user->contributing_as('body', $c, $problem->bodies_str_ids);
+ $c->stash->{contributing_as_anonymous_user} = $c->user_exists && $c->user->contributing_as('anonymous_user', $c, $problem->bodies_str_ids);
# This is also done in process_user, but is needed here for anonymous() just below
- my $anon_button = $c->cobrand->allow_anonymous_reports($update->problem->category) eq 'button' && $c->get_param('report_anonymously');
+ my $anon_button = $c->cobrand->allow_anonymous_reports($problem->category) eq 'button' && $c->get_param('report_anonymously');
if ($anon_button) {
$c->stash->{contributing_as_anonymous_user} = 1;
$c->stash->{contributing_as_body} = undef;
@@ -323,7 +328,6 @@ sub process_update : Private {
# then we are not changing the state of the problem so can use the current
# problem state
} else {
- my $problem = $c->stash->{problem} || $update->problem;
$update->problem_state( $problem->state );
}
}
@@ -332,7 +336,7 @@ sub process_update : Private {
my @extra; # Next function fills this, but we don't need it here.
# This is just so that the error checking for these extra fields runs.
# TODO Use extra here as it is used on reports.
- my $body = (values %{$update->problem->bodies})[0];
+ my $body = (values %{$problem->bodies})[0];
$c->cobrand->process_open311_extras( $c, $body, \@extra );
if ( $c->get_param('fms_extra_title') ) {
@@ -404,6 +408,16 @@ sub check_for_errors : Private {
$field_errors{photo} = $photo_error;
}
+ # Now assign the username error according to where it came from
+ if ($field_errors{username}) {
+ if ($c->get_param('submit_sign_in') || $c->get_param('password_sign_in')) {
+ $field_errors{username_sign_in} = $field_errors{username};
+ } else {
+ $field_errors{username_register} = $field_errors{username};
+ }
+ delete $field_errors{username};
+ }
+
# all good if no errors
return 1
unless ( scalar keys %field_errors
@@ -484,6 +498,13 @@ sub save_update : Private {
$update->confirm();
} elsif ($c->stash->{contributing_as_anonymous_user}) {
$update->set_extra_metadata( contributed_as => 'anonymous_user' );
+ if ( $c->user_exists && $c->user->from_body ) {
+ # If a staff user has clicked the 'report anonymously' button then
+ # there would be no record of who that staff member was as we've
+ # used the cobrand's anonymous_account for the report. In this case
+ # record the staff user ID in the report metadata.
+ $update->set_extra_metadata( contributed_by => $c->user->id );
+ }
$update->confirm();
} elsif ( !$update->user->in_storage ) {
# User does not exist.
@@ -571,6 +592,11 @@ sub send_confirmation_text : Private {
my ( $self, $c ) = @_;
my $update = $c->stash->{update};
$c->forward('/auth/phone/send_token', [ $c->stash->{token_data}, 'comment', $update->user->phone ]);
+ my $error = $c->render_fragment( 'auth/_username_error.html', { default => 'phone' });
+ if ($error) {
+ $c->stash->{field_errors}{username_register} = $error;
+ $c->go( '/report/display', [ $c->stash->{problem}->id ], [] );
+ }
$c->stash->{submit_url} = '/report/update/text';
}