diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-09-12 13:25:34 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-09-13 15:12:12 +0100 |
commit | 90da7da99ceddc57f70e678a6f56579f1c89197f (patch) | |
tree | 4b2d9919ea50526f2daa34daabfff4f4b1df506e | |
parent | 847ea6f773ddb5ba921ee1d9f1a0db4799687b1d (diff) |
Add hook for per-row questionnaire override.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Questionnaires.pm | 5 | ||||
-rw-r--r-- | t/app/model/questionnaire.t | 39 |
3 files changed, 42 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b34fb900e..3d158f72c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Do not scan through all problems to show /_dev pages. - Development improvements: - Cobrand hook for disallowing title moderation. #2228 + - Cobrand hook for per-questionnaire sending. #2231 * v2.4 (6th September 2018) - Security diff --git a/perllib/FixMyStreet/Script/Questionnaires.pm b/perllib/FixMyStreet/Script/Questionnaires.pm index 5fc01512d..d89f1bcf8 100644 --- a/perllib/FixMyStreet/Script/Questionnaires.pm +++ b/perllib/FixMyStreet/Script/Questionnaires.pm @@ -50,7 +50,10 @@ sub send_questionnaires_period { # Not all cobrands send questionnaires next unless $cobrand->send_questionnaires; - if ($row->is_from_abuser || !$row->user->email_verified) { + # Cobrands can also override sending per row if they wish + my $cobrand_send = $cobrand->call_hook('send_questionnaire', $row) // 1; + + if ($row->is_from_abuser || !$row->user->email_verified || !$cobrand_send) { $row->update( { send_questionnaire => 0 } ); next; } diff --git a/t/app/model/questionnaire.t b/t/app/model/questionnaire.t index 169895f95..d01185375 100644 --- a/t/app/model/questionnaire.t +++ b/t/app/model/questionnaire.t @@ -1,3 +1,14 @@ +package FixMyStreet::Cobrand::Tester; + +use parent 'FixMyStreet::Cobrand::Default'; + +sub send_questionnaire { + my ($self, $row) = @_; + return $row->latitude == 1; +} + +package main; + use FixMyStreet; use FixMyStreet::TestMech; @@ -27,7 +38,7 @@ my $problem = FixMyStreet::DB->resultset('Problem')->create( my $mech = FixMyStreet::TestMech->new; -for my $test ( +for my $test ( { state => 'unconfirmed', send_email => 0, @@ -89,7 +100,7 @@ for my $test ( send_email => 1, }, ) { - subtest "correct questionnaire behviour for state $test->{state}" => sub { + subtest "correct questionnaire behaviour for state $test->{state}" => sub { $problem->discard_changes; $problem->state( $test->{state} ); $problem->send_questionnaire( 1 ); @@ -108,4 +119,28 @@ for my $test ( } } +for my $test ( + { latitude => 2, emails => 0, }, + { latitude => 1, emails => 1, }, +) { + subtest "test cobrand questionnaire send override, expecting $test->{emails} email" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'tester', + }, sub { + $problem->latitude($test->{latitude}); + $problem->send_questionnaire(1); + $problem->update; + $problem->questionnaires->delete; + + $mech->email_count_is(0); + FixMyStreet::DB->resultset('Questionnaire')->send_questionnaires( { site => 'tester' } ); + $mech->email_count_is($test->{emails}); + $mech->clear_emails_ok(); + + $problem->discard_changes; + is $problem->send_questionnaire, 0; + }; + }; +} + done_testing(); |