diff options
author | Struan Donald <struan@exo.org.uk> | 2020-05-07 15:10:46 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2020-05-12 15:36:52 +0100 |
commit | c80f13eeac448e99873b690411d7f6e83b07dd06 (patch) | |
tree | abf43a53330728a1a7a02f462a8173f5e499048c | |
parent | 08f4e0171579f77165ce074e88086d1caeb7a243 (diff) |
admin interface for per category anonymous reporting
Add an interface to enable a category to accept anonymous reports, plus
the code to handle permitting this.
It's only available on single body cobrand sites in the default
configuration.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Bodies.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 17 | ||||
-rw-r--r-- | t/app/controller/admin/bodies.t | 34 | ||||
-rw-r--r-- | t/app/controller/report_new_anon.t | 75 | ||||
-rw-r--r-- | templates/web/base/admin/bodies/contact-form.html | 8 |
6 files changed, 134 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b53ca270..c576808d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix issue with dashboard report CSV export. #3026 - Admin improvements: - Display user name/email for contributed as reports. #2990 + - Interface for enabling anonymous reports for certain categories. #2989 * v3.0.1 (6th May 2020) - New features: diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm index 7b060f2ca..52306af24 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm @@ -271,7 +271,7 @@ sub update_contact : Private { $contact->send_method( $c->get_param('send_method') ); # Set flags in extra to the appropriate values - foreach (qw(photo_required open311_protect updates_disallowed reopening_disallowed assigned_users_only)) { + foreach (qw(photo_required open311_protect updates_disallowed reopening_disallowed assigned_users_only anonymous_allowed)) { if ( $c->get_param($_) ) { $contact->set_extra_metadata( $_ => 1 ); } else { diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index df7e333fb..c8e11f93d 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -1123,7 +1123,22 @@ pressed in the front end, rather than whenever a username is not provided. =cut -sub allow_anonymous_reports { 0; } +sub allow_anonymous_reports { + my ($self, $category_name) = @_; + + $category_name ||= $self->{c}->stash->{category}; + if ( $category_name && $self->can('body') and $self->body ) { + my $category_rs = FixMyStreet::DB->resultset("Contact")->search({ + body_id => $self->body->id, + category => $category_name + }); + if ( my $category = $category_rs->first ) { + return 'button' if $category->get_extra_metadata('anonymous_allowed'); + } + } + + return 0; +} =item anonymous_account diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t index 9f7b18cde..80ee22630 100644 --- a/t/app/controller/admin/bodies.t +++ b/t/app/controller/admin/bodies.t @@ -1,3 +1,13 @@ +package FixMyStreet::Cobrand::AnonAllowedByCategory; +use parent 'FixMyStreet::Cobrand::UKCouncils'; +sub council_url { 'anonbycategory' } +sub council_name { 'Aberdeen City Council' } +sub council_area { 'Aberdeen' } +sub council_area_id { 2650 } +sub anonymous_account { { email => 'anoncategory@example.org', name => 'Anonymous Category' } } + +package main; + use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -295,8 +305,32 @@ subtest 'reopen disabling' => sub { is $contact->get_extra_metadata('reopening_disallowed'), 1, 'Reopening disallowed flag set'; }; +subtest 'allow anonymous reporting' => sub { + $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); + $mech->content_lacks('Allow anonymous reports'); +}; }; # END of override wrap +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + MAPIT_TYPES => [ 'UTA' ], + BASE_URL => 'http://www.example.org', + ALLOWED_COBRANDS => [ "fixmystreet", "anonallowedbycategory" ], +}, sub { + +subtest 'allow anonymous reporting' => sub { + $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); + $mech->submit_form_ok( { with_fields => { + anonymous_allowed => 1, + note => 'Anonymous Allowed', + } } ); + $mech->content_contains('Values updated'); + my $contact = $body->contacts->find({ category => 'test category' }); + is $contact->get_extra_metadata('anonymous_allowed'), 1, 'Anonymous reports allowed flag set'; +}; + +}; + FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', diff --git a/t/app/controller/report_new_anon.t b/t/app/controller/report_new_anon.t index d86bc8134..cba360f05 100644 --- a/t/app/controller/report_new_anon.t +++ b/t/app/controller/report_new_anon.t @@ -17,6 +17,14 @@ sub allow_anonymous_reports { } sub anonymous_account { { email => 'anoncategory@example.org', name => 'Anonymous Category' } } +package FixMyStreet::Cobrand::AnonAllowedByCategory; +use parent 'FixMyStreet::Cobrand::UKCouncils'; +sub council_url { 'anonbycategory' } +sub council_name { 'Edinburgh City Council' } +sub council_area { 'Edinburgh' } +sub council_area_id { 2651 } +sub anonymous_account { { email => 'anoncategory@example.org', name => 'Anonymous Category' } } + package main; use FixMyStreet::TestMech; @@ -269,4 +277,71 @@ subtest "test report creation anonymously by button, per category" => sub { }; +$contact2->set_extra_metadata( anonymous_allowed => 1 ); +$contact2->update; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => 'anonallowedbycategory', + MAPIT_URL => 'http://mapit.uk/', +}, sub { + +subtest "test report creation anonymously by button, per category from metadata" => 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('Your issue is on its way to the council'); + + 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'; +}; + +}; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + BASE_URL => 'https://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.uk/', +}, sub { +subtest "test anonymously by button, per category from metadata limited to cobrand" => 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 => 'Trees', + } + }, "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 +}; + +}; + done_testing(); diff --git a/templates/web/base/admin/bodies/contact-form.html b/templates/web/base/admin/bodies/contact-form.html index 65000942b..21b69fdcd 100644 --- a/templates/web/base/admin/bodies/contact-form.html +++ b/templates/web/base/admin/bodies/contact-form.html @@ -74,8 +74,14 @@ <span class='form-hint'>[% loc('Use this where you do not want problem reporters to be able to reopen their fixed or closed reports when leaving an update.') %]</span> </p> - [% IF contact.sent_by_open311 %] + [% IF body.get_cobrand_handler.anonymous_account %] + <p class="form-check"> + <input type="checkbox" name="anonymous_allowed" value="1" id="anonymous_allowed" [% ' checked' IF contact.get_extra_metadata('anonymous_allowed') %]> + <label for="anonymous_allowed">[% loc('Allow anonymous reports on this category') %]</label> + </p> + [% END %] + [% IF contact.sent_by_open311 %] <p class="form-check"> <input type="checkbox" name="open311_protect" value="1" id="open311_protect"[% ' checked' IF contact.get_extra_metadata('open311_protect') %]> <label for="open311_protect">[% loc("Protect this category's name and group(s) from Open311 changes") %]</label> |