Skip to content

Commit

Permalink
[FMS] Allow users to opt out of questionnaires
Browse files Browse the repository at this point in the history
  • Loading branch information
nephila-nacrea committed Dec 11, 2023
1 parent 824a22d commit 6807d24
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Improve handling cache expiry for front page statistics.
- Add geolocation button to centre map at user's location. #4671
- WasteWorks PWA can now have a separate name from the FixMyStreet PWA.
- Users can now opt out of questionnaires.
- Include reference in report list emails. #4760
- Bugfixes:
- Stop map panning breaking after long press. #4423
Expand Down
2 changes: 2 additions & 0 deletions perllib/FixMyStreet/App/Controller/My.pm
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,12 @@ sub notify_preference : Local : Args(0) {

my $update_notify = $c->get_param('update_notify');
my $alert_notify = $c->get_param('alert_notify');
my $questionnaire_notify = $c->get_param('questionnaire_notify');

$c->user->set_extra_metadata(
update_notify => $update_notify,
alert_notify => $alert_notify,
questionnaire_notify => $questionnaire_notify,
);
$c->user->update;
$c->res->redirect('/my');
Expand Down
6 changes: 6 additions & 0 deletions perllib/FixMyStreet/DB/Result/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ sub alert_updates_by {
return 'email';
}

# Whether user has opted to receive questionnaires.
# Defaults to true if not set in extra metadata.
sub questionnaire_notify {
return $_[0]->get_extra_metadata('questionnaire_notify') // 1;
}

sub latest_anonymity {
my $self = shift;
my $p = $self->problems->search(undef, { rows => 1, order_by => { -desc => 'id' } } )->first;
Expand Down
9 changes: 6 additions & 3 deletions perllib/FixMyStreet/Script/Questionnaires.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ sub send_questionnaires_period {
# 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->is_closed
) {
if ( $row->is_from_abuser
|| !$row->user->email_verified
|| !$row->user->questionnaire_notify
|| !$cobrand_send
|| $row->is_closed )
{
$row->update( { send_questionnaire => 0 } );
next;
}
Expand Down
16 changes: 16 additions & 0 deletions t/app/controller/my.t
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ subtest 'test setting of notification preferences' => sub {
$mech->content_contains('id="update_notify_phone" value="phone" checked');
$mech->content_lacks('id="alert_notify_email" value="email"');
$mech->content_contains('id="alert_notify_none" value="none" checked');

# questionnaire_notify setting
$mech->content_contains('id="questionnaire_notify_yes" value="1" checked');
$mech->content_lacks('id="questionnaire_notify_no" value="0" checked');

$mech->submit_form_ok(
{ with_fields => { questionnaire_notify => 0 } } );
$mech->get_ok('/my');
$mech->content_lacks('id="questionnaire_notify_yes" value="1" checked');
$mech->content_contains('id="questionnaire_notify_no" value="0" checked');

$mech->submit_form_ok(
{ with_fields => { questionnaire_notify => 1 } } );
$mech->get_ok('/my');
$mech->content_contains('id="questionnaire_notify_yes" value="1" checked');
$mech->content_lacks('id="questionnaire_notify_no" value="0" checked');
};
};

Expand Down
32 changes: 32 additions & 0 deletions t/app/controller/questionnaire.t
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,38 @@ foreach my $state (
$report->update( { send_questionnaire => 1, state => 'confirmed' } );
$report->questionnaires->delete;

subtest "user's questionnaire_notify setting" => sub {
# Set to true by default
is $user->get_extra_metadata('questionnaire_notify'), undef,
'extra_metadata returns undef';
is $user->questionnaire_notify, 1, 'method returns true';

# Set to false and try to send
$user->set_extra_metadata( questionnaire_notify => 0 );
$user->update;
is $user->questionnaire_notify, 0, 'method returns false';
FixMyStreet::DB->resultset('Questionnaire')
->send_questionnaires( { site => 'fixmystreet' } );
note 'questionnaire should not be sent';
$mech->email_count_is(0);
$report->discard_changes;
is $report->send_questionnaire, 0,
'report->send_questionnaire should have been set to 0';

# Set to true
$user->set_extra_metadata( questionnaire_notify => 1 );
$user->update;
is $user->questionnaire_notify, 1, 'method returns true';
FixMyStreet::DB->resultset('Questionnaire')
->send_questionnaires( { site => 'fixmystreet' } );
note
'questionnaire should not be sent because report->send_questionnaire was set to 0 earlier';
$mech->email_count_is(0);

# Reset send_questionnaire to allow tests below to pass
$report->update( { send_questionnaire => 1 } );
};

# Call the questionaire sending function...
FixMyStreet::DB->resultset('Questionnaire')->send_questionnaires( {
site => 'fixmystreet'
Expand Down
2 changes: 1 addition & 1 deletion templates/web/base/admin/reports/_edit_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<li>[% loc('Cobrand:') %] [% problem.cobrand %]
<br><small>[% loc('Cobrand data:') %] [% problem.cobrand_data OR '<em>' _ loc('None') _ '</em>' %]</small>
</li>
<li>[% loc('Going to send questionnaire?') %] [% IF problem.send_questionnaire %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %]</li>
<li>[% loc('Going to send questionnaire?') %] [% IF problem.send_questionnaire && problem.user.questionnaire_notify %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %]</li>

<li><label for="external_id">[% loc('External ID') %]:</label>
<input type="text" class="form-control" name="external_id" id="external_id" value="[% problem.external_id | html %]">
Expand Down
13 changes: 13 additions & 0 deletions templates/web/base/my/my.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ <h1>[% loc('Your account') %]</h1>
<label class="btn" for="alert_notify_none">[% loc('None') %]</label>
</p>
</fieldset>
</li>
[% current_pref = c.user.questionnaire_notify %]
<li>
<fieldset>
<legend>[% loc('Receive questionnaires') %]:</legend>
<p class="segmented-control segmented-control--radio">
<input type="radio" name="questionnaire_notify" id="questionnaire_notify_yes" value="1"[% ' checked' IF current_pref %]>
<label class="btn" for="questionnaire_notify_yes">[% loc('Yes') %]</label>

<input type="radio" name="questionnaire_notify" id="questionnaire_notify_no" value="0"[% ' checked' IF !current_pref %]>
<label class="btn" for="questionnaire_notify_no">[% loc('No') %]</label>
</p>
</fieldset>
<p>
<input class="btn btn--block" type="submit" value="[% loc('Update') %]">
</p>
Expand Down
1 change: 1 addition & 0 deletions templates/web/fixmystreet-uk-councils/about/privacy.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ <h2>What to expect</h2>
We <b>send you a questionnaire email</b> four weeks after you submit a problem, asking
for a status update. You can then opt in or out of subsequent status update
questionnaires.
You can choose to opt out of questionnaires altogether via <a href="/my">your account page</a>.
</li>
[% END %]
<li>
Expand Down
1 change: 1 addition & 0 deletions templates/web/fixmystreet.com/about/privacy.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ <h2>
We <b>send you a questionnaire email</b> four weeks after you submit a problem, asking
for a status update. You can then opt in or out of subsequent status update
questionnaires.
You can choose to opt out of questionnaires altogether via <a href="/my">your account page</a>.
</li>
<li>
If your report is particularly interesting, our Communications Manager may get in
Expand Down

0 comments on commit 6807d24

Please sign in to comment.