From f0c1e25cd4774996d6e523bdad73ae3d8f6cabae Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 19 Mar 2014 12:26:18 +0000 Subject: Allow comments to be confirmed with no confirmation Add never_confirm_updates setting to cobrand that, when set to 0 means that comments are confirmed with no confirmation step. Essentially behaves as it would if the user was logged in. Also add a flag to the flash that indicates the comment was accepted to you can display a message on the report page if required --- t/app/controller/report_updates.t | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 't/app/controller') 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 ); -- cgit v1.2.3 From 5c871b7093ac2fd137b980979bb210cc1cad59a7 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 21 Mar 2014 17:30:07 +0000 Subject: Add Cobrand config to include update date in email alerts This is useful for sites where the updates aren't published on the site so you need a bit more context in the email alerts. Add inlude_time_in_update_alerts to default cobrand, off as default If this is set then the date is added after the name string in the email, passing in 'alert' as the type to dt_prettify in order to allow the cobrand to format it accordingly. This does require pulling out the alert confirmed time from the database in the send_alerts code where it wasn't before. --- t/app/controller/alert_new.t | 91 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 532b071eb..594d4c7a6 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -683,4 +683,95 @@ subtest 'check new updates alerts for non public reports only go to report owner $mech->delete_user( $user3 ); }; +subtest 'check setting inlude dates in new updates cobrand option' => sub { + my $include_date_in_alert_override= Sub::Override->new( + "FixMyStreet::Cobrand::Default::include_time_in_update_alerts", + sub { return 1; } + ); + $mech->delete_user( 'reporter@example.com' ); + $mech->delete_user( 'alerts@example.com' ); + + my $user1 = FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } ); + ok $user1, "created test user"; + + my $user2 = FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'alerts@example.com', name => 'Alert User' } ); + ok $user2, "created test user"; + + my $user3 = FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'updates@example.com', name => 'Update User' } ); + ok $user3, "created test user"; + + my $dt = DateTime->now->add( minutes => -30 ); + my $r_dt = $dt->clone->add( minutes => 20 ); + + my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser; + + my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { + postcode => 'EH1 1BB', + bodies_str => '2651', + areas => ',11808,135007,14419,134935,2651,20728,', + category => 'Street lighting', + title => 'Alert test for non public reports', + detail => 'Testing Detail', + used_map => 1, + name => $user2->name, + anonymous => 0, + state => 'confirmed', + confirmed => $dt_parser->format_datetime($r_dt), + lastupdate => $dt_parser->format_datetime($r_dt), + whensent => $dt_parser->format_datetime($r_dt->clone->add( minutes => 5 )), + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 1, + latitude => '55.951963', + longitude => '-3.189944', + user_id => $user2->id, + } ); + + my $update = FixMyStreet::App->model('DB::Comment')->create( { + problem_id => $report->id, + user_id => $user3->id, + name => 'Anonymous User', + mark_fixed => 'false', + text => 'This is some more update text', + state => 'confirmed', + confirmed => $r_dt->clone->add( minutes => 8 ), + anonymous => 't', + } ); + + my $alert_user1 = FixMyStreet::App->model('DB::Alert')->create( { + user => $user1, + alert_type => 'new_updates', + parameter => $report->id, + confirmed => 1, + whensubscribed => $dt, + } ); + ok $alert_user1, "alert created"; + + + $mech->clear_emails_ok; + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + $mech->email_count_is(1); + + # if we don't do this then we're applying the date inflation code and + # it's timezone munging to the DateTime object above and not the DateTime + # object that's inflated from the database value and these turn out to be + # different as the one above has a UTC timezone and not the floating one + # that those from the DB do. + $update->discard_changes(); + + my $date_in_alert = Utils::prettify_dt( $update->confirmed ); + my $email = $mech->get_email; + like $email->body, qr/$date_in_alert/, 'alert contains date'; + + $mech->delete_user( $user1 ); + $mech->delete_user( $user2 ); + $mech->delete_user( $user3 ); + $include_date_in_alert_override->restore(); +}; + done_testing(); -- cgit v1.2.3