aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm9
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm6
-rw-r--r--t/app/controller/report_new_anon.t72
-rw-r--r--templates/web/base/report/form/user.html5
-rw-r--r--templates/web/base/report/new/form_user.html2
-rw-r--r--templates/web/base/report/update/form_user.html2
-rw-r--r--templates/web/bromley/report/update/form_user.html2
7 files changed, 92 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 8dd2d5a09..bea2250fd 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -803,7 +803,9 @@ sub process_user : Private {
# Report form includes two username fields: #form_username_register and #form_username_sign_in
$params{username} = (first { $_ } $c->get_param_list('username')) || '';
- if ( $c->cobrand->allow_anonymous_reports && !$c->user_exists && !$params{username} ) {
+ my $anon_button = $c->cobrand->allow_anonymous_reports eq 'button' && $c->get_param('report_anonymously');
+ my $anon_fallback = $c->cobrand->allow_anonymous_reports eq '1' && !$c->user_exists && !$params{username};
+ if ($anon_button || $anon_fallback) {
my $anon_details = $c->cobrand->anonymous_account;
my $user = $c->model('DB::User')->find_or_new({ email => $anon_details->{email} });
$user->name($anon_details->{name});
@@ -943,6 +945,11 @@ sub process_report : Private {
$c->stash->{contributing_as_body} = $user->contributing_as('body', $c, $c->stash->{bodies});
$c->stash->{contributing_as_anonymous_user} = $user->contributing_as('anonymous_user', $c, $c->stash->{bodies});
}
+ # This is also done in process_user, but is needed here for anonymous() just below
+ my $anon_button = $c->cobrand->allow_anonymous_reports eq 'button' && $c->get_param('report_anonymously');
+ if ($anon_button) {
+ $c->stash->{contributing_as_anonymous_user} = 1;
+ }
# set some simple bool values (note they get inverted)
if ($c->stash->{contributing_as_body}) {
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 0da60b77e..d7bec65cd 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -1058,8 +1058,10 @@ sub never_confirm_reports { 0; }
=item allow_anonymous_reports
-If true then can have reports that are truly anonymous - i.e with no email or
-name. You need to also put details in the anonymous_account function too.
+If true then a report submission with no user details will default to the user
+given via the anonymous_account function, and create it anonymously. If set to
+'button', then this will happen only when a report_anonymously button is
+pressed in the front end, rather than whenever a username is not provided.
=cut
diff --git a/t/app/controller/report_new_anon.t b/t/app/controller/report_new_anon.t
index 5a4f35f5d..e9ce23c44 100644
--- a/t/app/controller/report_new_anon.t
+++ b/t/app/controller/report_new_anon.t
@@ -3,6 +3,11 @@ use parent 'FixMyStreet::Cobrand::FixMyStreet';
sub allow_anonymous_reports { 1 }
sub anonymous_account { { email => 'anon@example.org', name => 'Anonymous' } }
+package FixMyStreet::Cobrand::AnonAllowedByButton;
+use parent 'FixMyStreet::Cobrand::FixMyStreet';
+sub allow_anonymous_reports { 'button' }
+sub anonymous_account { { email => 'anonbutton@example.org', name => 'Anonymous Button' } }
+
package main;
use FixMyStreet::TestMech;
@@ -89,4 +94,71 @@ subtest "test report creation anonymously" => sub {
};
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'anonallowedbybutton',
+ MAPIT_URL => 'http://mapit.uk/',
+}, sub {
+
+subtest "test report creation anonymously by button" => sub {
+ $mech->get_ok('/around');
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" );
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
+ $mech->submit_form_ok(
+ {
+ button => 'submit_register',
+ with_fields => {
+ title => 'Test Report',
+ detail => 'Test report details.',
+ name => 'Joe Bloggs',
+ may_show_name => '1',
+ category => 'Street lighting',
+ }
+ },
+ "submit good details"
+ );
+
+ is_deeply $mech->page_errors, [
+ 'Please enter your email'
+ ], "check there were no errors";
+
+ $mech->get_ok('/around');
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" );
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
+ $mech->submit_form_ok(
+ {
+ button => 'report_anonymously',
+ with_fields => {
+ title => 'Test Report',
+ detail => 'Test report details.',
+ category => 'Street lighting',
+ }
+ },
+ "submit good details"
+ );
+ $mech->content_contains('Thank you');
+
+ is_deeply $mech->page_errors, [], "check there were no errors";
+
+ my $report = FixMyStreet::DB->resultset("Problem")->search({}, { order_by => { -desc => 'id' } })->first;
+ ok $report, "Found the report";
+
+ is $report->state, 'confirmed', "report confirmed";
+ $mech->get_ok( '/report/' . $report->id );
+
+ is $report->bodies_str, $body->id;
+ is $report->name, 'Anonymous Button';
+ is $report->anonymous, 1; # Doesn't change behaviour here, but uses anon account's name always
+
+ my $alert = FixMyStreet::App->model('DB::Alert')->find( {
+ user => $report->user,
+ alert_type => 'new_updates',
+ parameter => $report->id,
+ } );
+ is $alert, undef, "no alert created";
+
+ $mech->not_logged_in_ok;
+};
+
+};
+
done_testing();
diff --git a/templates/web/base/report/form/user.html b/templates/web/base/report/form/user.html
index ca78d93bc..25d252e58 100644
--- a/templates/web/base/report/form/user.html
+++ b/templates/web/base/report/form/user.html
@@ -26,5 +26,10 @@
[% END %]
<button type="button" class="btn btn--block hidden-nojs js-new-report-user-show">[% loc('Log in with email') %]</button>
[% END %]
+[% IF type == 'report' AND c.cobrand.allow_anonymous_reports == 'button' %]
+ <small id="or">[% loc('or') %]</small>
+ <button name="report_anonymously" value="yes" class="btn btn--block js-new-report-submit">[% loc('Report anonymously') %]</button>
+ <small>[% loc('No personal details will be stored, and you will not receive updates about this report.') %]</small>
+[% END %]
</div>
<!-- /report/form/user.html -->
diff --git a/templates/web/base/report/new/form_user.html b/templates/web/base/report/new/form_user.html
index ca4e2e58b..49ef70abd 100644
--- a/templates/web/base/report/new/form_user.html
+++ b/templates/web/base/report/new/form_user.html
@@ -1,7 +1,7 @@
<!-- report/new/form_user.html -->
<div class="js-hide-if-invalid-category">
- [% PROCESS 'report/form/user.html' %]
+ [% PROCESS 'report/form/user.html' type='report' %]
<div class="hidden-js js-new-report-user-shown">
<div class="hidden-nojs form-section-preview">
diff --git a/templates/web/base/report/update/form_user.html b/templates/web/base/report/update/form_user.html
index bfa227293..92120271f 100644
--- a/templates/web/base/report/update/form_user.html
+++ b/templates/web/base/report/update/form_user.html
@@ -1,5 +1,5 @@
<!-- report/update/form_user.html -->
-[% PROCESS 'report/form/user.html' %]
+[% PROCESS 'report/form/user.html' type='update' %]
<div class="hidden-js js-new-report-user-shown">
<div class="hidden-nojs form-section-preview">
diff --git a/templates/web/bromley/report/update/form_user.html b/templates/web/bromley/report/update/form_user.html
index e003298c5..de151d91b 100644
--- a/templates/web/bromley/report/update/form_user.html
+++ b/templates/web/bromley/report/update/form_user.html
@@ -1,5 +1,5 @@
<!-- report/update/form_user.html -->
-[% PROCESS 'report/form/user.html' %]
+[% PROCESS 'report/form/user.html' type='update' %]
<div class="hidden-js js-new-report-user-shown">
<div class="hidden-nojs form-section-preview">