aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm4
-rw-r--r--perllib/FixMyStreet/Script/Reports.pm2
-rw-r--r--t/app/controller/report_new_anon.t53
-rw-r--r--templates/web/base/report/form/user.html14
-rw-r--r--templates/web/westminster/report/form/user_loggedout.html2
-rw-r--r--web/cobrands/fixmystreet/fixmystreet.js5
6 files changed, 76 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 6f6428089..a3df4aa82 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -272,9 +272,11 @@ sub by_category_ajax_data : Private {
}
my $non_public = $c->stash->{non_public_categories}->{$category};
+ my $anon_button = ($c->cobrand->allow_anonymous_reports($category) eq 'button');
my $body = {
bodies => [ map { $_->name } @bodies ],
$non_public ? ( non_public => JSON->true ) : (),
+ $anon_button ? ( allow_anonymous => JSON->true ) : (),
};
if ( $c->stash->{category_extras}->{$category} && @{ $c->stash->{category_extras}->{$category} } >= 1 ) {
@@ -984,7 +986,7 @@ sub process_report : Private {
$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');
+ my $anon_button = $c->cobrand->allow_anonymous_reports($params{category}) eq 'button' && $c->get_param('report_anonymously');
if ($anon_button) {
$c->stash->{contributing_as_anonymous_user} = 1;
$c->stash->{contributing_as_body} = undef;
diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm
index 73c179751..aa46a5c43 100644
--- a/perllib/FixMyStreet/Script/Reports.pm
+++ b/perllib/FixMyStreet/Script/Reports.pm
@@ -107,7 +107,7 @@ sub send(;$) {
$h{osm_url} .= '?m';
}
- if ( $cobrand->allow_anonymous_reports &&
+ if ( $cobrand->allow_anonymous_reports($row->category) &&
$row->user->email eq $cobrand->anonymous_account->{'email'}
) {
$h{anonymous_report} = 1;
diff --git a/t/app/controller/report_new_anon.t b/t/app/controller/report_new_anon.t
index b14814f59..d86bc8134 100644
--- a/t/app/controller/report_new_anon.t
+++ b/t/app/controller/report_new_anon.t
@@ -8,6 +8,15 @@ use parent 'FixMyStreet::Cobrand::FixMyStreet';
sub allow_anonymous_reports { 'button' }
sub anonymous_account { { email => 'anonbutton@example.org', name => 'Anonymous Button' } }
+package FixMyStreet::Cobrand::AnonAllowedForCategory;
+use parent 'FixMyStreet::Cobrand::FixMyStreet';
+sub allow_anonymous_reports {
+ my ($self, $category) = @_;
+ $category ||= $self->{c}->stash->{category};
+ return 'button' if $category eq 'Trees';
+}
+sub anonymous_account { { email => 'anoncategory@example.org', name => 'Anonymous Category' } }
+
package main;
use FixMyStreet::TestMech;
@@ -216,4 +225,48 @@ subtest "test report creation anonymously by staff user" => sub {
};
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'anonallowedforcategory',
+ MAPIT_URL => 'http://mapit.uk/',
+}, sub {
+
+subtest "test report creation anonymously by button, per category" => 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_category_part_only',
+ with_fields => {
+ category => 'Street lighting',
+ }
+ }, "submit category with no anonymous reporting");
+ $mech->content_lacks('<button name="report_anonymously" value="yes" class="btn btn--block">'); # non-JS button, JS button always there
+ $mech->submit_form_ok({
+ button => 'submit_register',
+ with_fields => {
+ category => 'Trees',
+ }
+ }, "submit category with anonymous reporting");
+
+ $mech->submit_form_ok({
+ button => 'report_anonymously',
+ with_fields => {
+ title => 'Test Report',
+ detail => 'Test report details.',
+ }
+ }, "submit good details");
+ $mech->content_contains('Thank you');
+
+ my $report = FixMyStreet::DB->resultset("Problem")->search({}, { order_by => { -desc => 'id' } })->first;
+ ok $report, "Found the report";
+
+ is $report->state, 'confirmed', "report confirmed";
+ is $report->bodies_str, $body->id;
+ is $report->name, 'Anonymous Category';
+ is $report->anonymous, 1; # Doesn't change behaviour here, but uses anon account's name always
+ is $report->get_extra_metadata('contributed_as'), 'anonymous_user';
+};
+
+};
+
done_testing();
diff --git a/templates/web/base/report/form/user.html b/templates/web/base/report/form/user.html
index 25d252e58..1c941a302 100644
--- a/templates/web/base/report/form/user.html
+++ b/templates/web/base/report/form/user.html
@@ -26,10 +26,20 @@
[% 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' %]
+ <div class="js-show-if-anonymous
+ [%~ ' hidden-js' UNLESS 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>
</div>
+
+[% IF (c.user_exists OR NOT c.cobrand.social_auth_enabled) AND type == 'report' AND c.cobrand.allow_anonymous_reports == 'button' %]
+<div class="form-section-preview form-section-preview--next hidden-js">
+ <button name="report_anonymously" value="yes" class="btn btn--block">[% loc('Report anonymously') %]</button>
+ <small>[% loc('No personal details will be stored, and you will not receive updates about this report.') %]</small>
+ <small id="or">[% loc('or') %]</small>
+</div>
+[% END %]
+
<!-- /report/form/user.html -->
diff --git a/templates/web/westminster/report/form/user_loggedout.html b/templates/web/westminster/report/form/user_loggedout.html
new file mode 100644
index 000000000..71a68f216
--- /dev/null
+++ b/templates/web/westminster/report/form/user_loggedout.html
@@ -0,0 +1,2 @@
+<!-- user_loggedout.html -->
+<!-- /user_loggedout.html -->
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js
index 32eb24a8b..15ba18df4 100644
--- a/web/cobrands/fixmystreet/fixmystreet.js
+++ b/web/cobrands/fixmystreet/fixmystreet.js
@@ -458,6 +458,11 @@ $.extend(fixmystreet.set_up, {
$(".js-hide-if-private-category").show();
$(".js-hide-if-public-category").hide();
}
+ if (data && data.allow_anonymous) {
+ $('.js-show-if-anonymous').removeClass('hidden-js');
+ } else {
+ $('.js-show-if-anonymous').addClass('hidden-js');
+ }
if (fixmystreet.message_controller && data && data.disable_form && data.disable_form.questions) {
$.each(data.disable_form.questions, function(_, question) {