diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 8 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 79 |
3 files changed, 96 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index dbfd57e78..bc79cafd3 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -312,7 +312,14 @@ sub save_update : Private { my $update = $c->stash->{update}; - if ( !$update->user->in_storage ) { + if ( $c->cobrand->never_confirm_updates ) { + if ( $update->user->in_storage() ) { + $update->user->update(); + } else { + $update->user->insert(); + } + $update->confirm(); + } elsif ( !$update->user->in_storage ) { # User does not exist. # Store changes in token for when token is validated. $c->stash->{token_data} = { @@ -370,6 +377,7 @@ sub redirect_or_confirm_creation : Private { $c->forward( 'signup_for_alerts' ); my $report_uri = $c->cobrand->base_url_for_report( $update->problem ) . $update->problem->url; + $c->flash->{comment_created} = 1; $c->res->redirect($report_uri); $c->detach; } diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 2de3eae5f..60ed216d7 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -829,6 +829,14 @@ sub show_unconfirmed_reports { 0; } +=head2 never_confirm_updates + +If true then we never send an email to confirm an update + +=cut + +sub never_confirm_updates { 0; } + =head2 prettify_dt my $date = $c->prettify_dt( $datetime ); diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 3356867bb..e84755650 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -407,6 +407,85 @@ for my $test ( $report->state('confirmed'); $report->update; +for my $test ( + { + desc => 'overriding email confirmation allows report confirmation with no email sent', + initial_values => { + name => '', + rznvy => '', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + remember_me => undef, + password_register => '', + password_sign_in => '', + }, + form_values => { + submit_update => 1, + rznvy => 'unregistered@example.com', + update => "update no email confirm", + add_alert => 1, + name => 'Unreg User', + may_show_name => undef, + }, + changes => { + update => "Update no email confirm", + }, + } +) { + subtest $test->{desc} => sub { + my $send_confirmation_mail_override = Sub::Override->new( + "FixMyStreet::Cobrand::Default::never_confirm_updates", + sub { return 1; } + ); + $mech->log_out_ok(); + $mech->clear_emails_ok(); + + $mech->get_ok("/report/$report_id"); + + my $values = $mech->visible_form_values('updateForm'); + + is_deeply $values, $test->{initial_values}, 'initial form values'; + + $mech->submit_form_ok( + { + with_fields => $test->{form_values} + }, + 'submit update' + ); + + $mech->content_contains('Test 2'); + $mech->content_contains('Update no email confirm'); + + my $email = $mech->email_count_is(0); + + my $update = + FixMyStreet::App->model('DB::Comment')->find( { problem_id => $report_id, text => 'Update no email confirm' } ); + my $update_id = $update->id; + + $mech->content_contains('name="update_' . $update_id . '"'); + + my $details = { + %{ $test->{form_values} }, + %{ $test->{changes} } + }; + + ok $update, 'found update in database'; + is $update->state, 'confirmed', 'update confirmed'; + is $update->user->email, $details->{rznvy}, 'update email'; + is $update->text, $details->{update}, 'update text'; + + my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => $details->{rznvy} } ); + + ok $unreg_user, 'found user'; + + $mech->delete_user( $unreg_user ); + $send_confirmation_mail_override->restore(); + }; +} + subtest 'check non authority user cannot change set state' => sub { $mech->log_in_ok( $user->email ); $user->from_body( undef ); |