diff options
-rw-r--r-- | perllib/FixMyStreet/Script/Reports.pm | 9 | ||||
-rw-r--r-- | t/app/sendreport/inspection_required.t | 32 |
2 files changed, 40 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm index 8d3b2ddbc..7d614bc30 100644 --- a/perllib/FixMyStreet/Script/Reports.pm +++ b/perllib/FixMyStreet/Script/Reports.pm @@ -145,9 +145,16 @@ sub send(;$) { my $inspection_required = $sender_info->{contact}->get_extra_metadata('inspection_required') if $sender_info->{contact}; if ( $inspection_required ) { + my $reputation_threshold = $sender_info->{contact}->get_extra_metadata('reputation_threshold') || 0; + my $reputation_threshold_met = 0; + if ( $reputation_threshold > 0 ) { + my $user_reputation = $row->user->get_extra_metadata('reputation') || 0; + $reputation_threshold_met = $user_reputation >= $reputation_threshold; + } unless ( $row->get_extra_metadata('inspected') || - $row->user->has_permission_to( trusted => $row->bodies_str_ids ) + $row->user->has_permission_to( trusted => $row->bodies_str_ids ) || + $reputation_threshold_met ) { $skip = 1; debug_print("skipped because not yet inspected", $row->id) if $debug_mode; diff --git a/t/app/sendreport/inspection_required.t b/t/app/sendreport/inspection_required.t index 88a48e991..f9d40d39f 100644 --- a/t/app/sendreport/inspection_required.t +++ b/t/app/sendreport/inspection_required.t @@ -69,6 +69,38 @@ subtest 'Uninspected report is sent when made by trusted user' => sub { $report->discard_changes; $mech->email_count_is( 1 ); ok $report->whensent, 'Report marked as sent'; + is $report->get_extra_metadata('inspected'), undef, 'Report not marked as inspected'; +}; + +subtest 'Uninspected report isn’t sent when user rep is too low' => sub { + $mech->clear_emails_ok; + $report->whensent( undef ); + $report->update; + + $user->user_body_permissions->delete; + $user->set_extra_metadata(reputation => 15); + $user->update; + + $contact->set_extra_metadata(reputation_threshold => 20); + $contact->update; + + FixMyStreet::DB->resultset('Problem')->send_reports(); + + $report->discard_changes; + $mech->email_count_is( 0 ); + is $report->whensent, undef, 'Report hasn’t been sent'; +}; + +subtest 'Uninspected report is sent when user rep is high enough' => sub { + $user->set_extra_metadata(reputation => 21); + $user->update; + + FixMyStreet::DB->resultset('Problem')->send_reports(); + + $report->discard_changes; + $mech->email_count_is( 1 ); + ok $report->whensent, 'Report marked as sent'; + is $report->get_extra_metadata('inspected'), undef, 'Report not marked as inspected'; }; done_testing(); |