diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 19 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 14 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Reports.pm | 3 | ||||
-rw-r--r-- | t/app/controller/report_as_other.t | 31 |
5 files changed, 56 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a0e8bb1d6..c2df3cbbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Inspectors can set non_public status of reports. #1992 - Default start date is shown on the dashboard. - Users with 'user_edit' permission can search for users/reports. #2027 + - Don't send sent-report emails to as-body/as-anonymous reports. - Development improvements: - Add HTML email previewer. diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index e4e82f091..a41aeb6ea 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -1300,9 +1300,17 @@ sub save_user_and_report : Private { if ( $c->cobrand->never_confirm_reports ) { $report->user->update_or_insert; $report->confirm(); - } elsif ( $c->forward('created_as_someone_else', [ $c->stash->{bodies} ]) ) { - # If created on behalf of someone else, we automatically confirm it, - # but we don't want to update the user account + # If created on behalf of someone else, we automatically confirm it, + # but we don't want to update the user account + } elsif ($c->stash->{contributing_as_another_user}) { + $report->set_extra_metadata( contributed_as => 'another_user'); + $report->set_extra_metadata( contributed_by => $c->user->id ); + $report->confirm(); + } elsif ($c->stash->{contributing_as_body}) { + $report->set_extra_metadata( contributed_as => 'body' ); + $report->confirm(); + } elsif ($c->stash->{contributing_as_anonymous_user}) { + $report->set_extra_metadata( contributed_as => 'anonymous_user' ); $report->confirm(); } elsif ( !$report->user->in_storage ) { # User does not exist. @@ -1342,11 +1350,6 @@ sub save_user_and_report : Private { return 1; } -sub created_as_someone_else : Private { - my ($self, $c, $bodies) = @_; - return $c->stash->{contributing_as_another_user} || $c->stash->{contributing_as_body} || $c->stash->{contributing_as_anonymous_user}; -} - =head2 generate_map Add the html needed to for the map to the stash. diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 99eae8659..9d97688c5 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -444,9 +444,17 @@ sub save_update : Private { if ( $c->cobrand->never_confirm_updates ) { $update->user->update_or_insert; $update->confirm(); - } elsif ( $c->forward('/report/new/created_as_someone_else', [ $update->problem->bodies_str ]) ) { - # If created on behalf of someone else, we automatically confirm it, - # but we don't want to update the user account + # If created on behalf of someone else, we automatically confirm it, + # but we don't want to update the user account + } elsif ($c->stash->{contributing_as_another_user}) { + $update->set_extra_metadata( contributed_as => 'another_user'); + $update->set_extra_metadata( contributed_by => $c->user->id ); + $update->confirm(); + } elsif ($c->stash->{contributing_as_body}) { + $update->set_extra_metadata( contributed_as => 'body' ); + $update->confirm(); + } elsif ($c->stash->{contributing_as_anonymous_user}) { + $update->set_extra_metadata( contributed_as => 'anonymous_user' ); $update->confirm(); } elsif ( !$update->user->in_storage ) { # User does not exist. diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm index b8c3d6d0d..1d19ee283 100644 --- a/perllib/FixMyStreet/Script/Reports.pm +++ b/perllib/FixMyStreet/Script/Reports.pm @@ -294,6 +294,9 @@ sub _send_report_sent_email { # Don't send 'report sent' text return unless $row->user->email_verified; + my $contributed_as = $row->get_extra_metadata('contributed_as') || ''; + return if $contributed_as eq 'body' || $contributed_as eq 'anonymous_user'; + FixMyStreet::Email::send_cron( $row->result_source->schema, 'confirm_report_sent.txt', diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t index e8f65eb7b..367d9a1d4 100644 --- a/t/app/controller/report_as_other.t +++ b/t/app/controller/report_as_other.t @@ -1,5 +1,6 @@ use FixMyStreet::TestMech; use FixMyStreet::App; +use FixMyStreet::Script::Reports; # disable info logs for this test run FixMyStreet::App->log->disable('info'); @@ -15,7 +16,7 @@ my $test_email = 'body-user@example.net'; my $user = $mech->log_in_ok($test_email); $user->update({ from_body => $body->id, name => 'Body User' }); -my ($report_to_update) = $mech->create_problems_for_body(1, $body->id, 'Title'); +my ($report_to_update) = $mech->create_problems_for_body(1, $body->id, 'Title', { category => 'Potholes' }); subtest "Body user, no permissions, no special reporting tools shown" => sub { start_report(); @@ -100,6 +101,9 @@ subtest "Body user, has permission to add report as another user with landline n }; subtest "Body user, has permission to add report as another (existing) user with email" => sub { + FixMyStreet::Script::Reports::send(); + $mech->clear_emails_ok; + $mech->create_user_ok('existing@example.net', name => 'Existing User'); my $report = add_report( 'contribute_as_another_user', @@ -116,6 +120,15 @@ subtest "Body user, has permission to add report as another (existing) user with isnt $report->user->id, $user->id, 'user does not match'; like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/; push @users, $report->user; + + my $send_confirmation_mail_override = Sub::Override->new( + "FixMyStreet::Cobrand::Default::report_sent_confirmation_email", + sub { return 1; } + ); + FixMyStreet::Script::Reports::send(); + $mech->email_count_is(2); + $mech->clear_emails_ok; + $send_confirmation_mail_override->restore(); }; subtest "Body user, has permission to add report as another (existing) user with phone" => sub { @@ -138,6 +151,9 @@ subtest "Body user, has permission to add report as another (existing) user with }; subtest "Body user, has permission to add report as anonymous user" => sub { + FixMyStreet::Script::Reports::send(); + $mech->clear_emails_ok; + my $report = add_report( 'contribute_as_anonymous_user', form_as => 'anonymous_user', @@ -149,6 +165,19 @@ subtest "Body user, has permission to add report as anonymous user" => sub { is $report->user->name, 'Body User', 'user name unchanged'; is $report->user->id, $user->id, 'user matches'; is $report->anonymous, 1, 'report anonymous'; + + my $send_confirmation_mail_override = Sub::Override->new( + "FixMyStreet::Cobrand::Default::report_sent_confirmation_email", + sub { return 1; } + ); + + FixMyStreet::Script::Reports::send(); + # No report sent email is sent + $mech->email_count_is(1); + my $email = $mech->get_email; + like $email->header('Subject'), qr/Problem Report: Test Report/, 'report email title correct'; + $mech->clear_emails_ok; + $send_confirmation_mail_override->restore(); }; subtest "Body user, has permission to add update as council" => sub { |