From 730d25ae7218d731590b322d4f419a7df6d4e4fb Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 30 Apr 2020 13:56:31 +0100 Subject: Add ability to disallow updates in a category. Add a tickbox to the category admin, and do not allow updates on reports made in those selected categories. --- t/app/controller/admin/bodies.t | 11 +++++++++++ t/app/controller/report_updates.t | 33 +++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 12 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t index c73a90da1..7ec7aed75 100644 --- a/t/app/controller/admin/bodies.t +++ b/t/app/controller/admin/bodies.t @@ -261,6 +261,17 @@ subtest 'open311 protection editing' => sub { is $contact->get_extra_metadata('open311_protect'), 1, 'Open311 protect flag set'; }; +subtest 'updates disabling' => sub { + $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); + $mech->submit_form_ok( { with_fields => { + updates_disallowed => 1, + note => 'Disabling updates', + } } ); + $mech->content_contains('Values updated'); + my $contact = $body->contacts->find({ category => 'test category' }); + is $contact->get_extra_metadata('updates_disallowed'), 1, 'Updates disallowed flag set'; +}; + }; # END of override wrap diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 07ee48587..e8ab1cc85 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -22,6 +22,8 @@ my $user2 = $mech->create_user_ok('commenter@example.com', name => 'Commenter'); my $body = $mech->create_body_ok(2504, 'Westminster City Council'); +my $contact = $mech->create_contact_ok( body_id => $body->id, category => 'Other', email => 'other' ); + my $dt = DateTime->new( year => 2011, month => 04, @@ -1893,6 +1895,18 @@ for my $test ( }; } +$mech->log_in_ok( $report->user->email ); + +my %standard_fields = ( + name => $report->user->name, + update => 'update text', + photo1 => '', + photo2 => '', + photo3 => '', + may_show_name => 1, + add_alert => 1, +); + for my $test ( { desc => 'update confirmed without marking as fixed leaves state unchanged', @@ -2094,18 +2108,6 @@ for my $test ( }, ) { subtest $test->{desc} => sub { - $mech->log_in_ok( $report->user->email ); - - my %standard_fields = ( - name => $report->user->name, - update => 'update text', - photo1 => '', - photo2 => '', - photo3 => '', - may_show_name => 1, - add_alert => 1, - ); - my %expected_fields = ( %standard_fields, %{ $test->{expected_form_fields} }, @@ -2178,4 +2180,11 @@ FixMyStreet::override_config { }; }; +subtest 'check disabling of updates per category' => sub { + $contact->set_extra_metadata( updates_disallowed => 1 ); + $contact->update; + $mech->get_ok("/report/$report_id"); + $mech->content_lacks('Provide an update'); +}; + done_testing(); -- cgit v1.2.3 From f6d807fd5217a19ac488f652d1f0853a7891231f Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 1 May 2020 15:42:01 +0100 Subject: Add way to disallow report reopening in a category Add a tickbox to the category admin, and do not allow reopening on reports made in the selected categories. --- t/app/controller/admin/bodies.t | 11 +++++++++++ t/app/controller/report_updates.t | 11 +++++++++++ 2 files changed, 22 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t index 7ec7aed75..d3e4074f9 100644 --- a/t/app/controller/admin/bodies.t +++ b/t/app/controller/admin/bodies.t @@ -272,6 +272,17 @@ subtest 'updates disabling' => sub { is $contact->get_extra_metadata('updates_disallowed'), 1, 'Updates disallowed flag set'; }; +subtest 'reopen disabling' => sub { + $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); + $mech->submit_form_ok( { with_fields => { + reopening_disallowed => 1, + note => 'Disabling reopening', + } } ); + $mech->content_contains('Values updated'); + my $contact = $body->contacts->find({ category => 'test category' }); + is $contact->get_extra_metadata('reopening_disallowed'), 1, 'Reopening disallowed flag set'; +}; + }; # END of override wrap diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index e8ab1cc85..e97b04f12 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -2145,6 +2145,17 @@ for my $test ( }; } +subtest 'check disabling of reopening' => sub { + $report->state('fixed - council'); + $report->update; + $mech->get_ok("/report/$report_id"); + $mech->content_contains('This problem has not been fixed'); + $contact->set_extra_metadata( reopening_disallowed => 1 ); + $contact->update; + $mech->get_ok("/report/$report_id"); + $mech->content_lacks('This problem has not been fixed'); +}; + subtest 'check have to be logged in for creator fixed questionnaire' => sub { $mech->log_out_ok(); -- cgit v1.2.3 From 5ce552af2b66613272dc9cfe2d46532e057f44f7 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 7 May 2020 12:44:23 +0100 Subject: Fix dashboard report CSV export. The change to join in e16054150 did not include a collapse that the previous prefetch was doing, so multiple rows per result were being returned. --- t/app/controller/dashboard.t | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 72fc00128..c62ada89a 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -70,6 +70,7 @@ foreach my $problem (@fixed_problems) { foreach my $problem (@closed_problems) { $problem->update({ state => 'closed' }); + $mech->create_comment_for_problem($problem, $counciluser, 'Name', 'in progress text', 0, 'confirmed', 'in progress'); $mech->create_comment_for_problem($problem, $counciluser, 'Title', 'text', 0, 'confirmed', 'closed'); } @@ -214,7 +215,7 @@ FixMyStreet::override_config { subtest 'export updates as csv' => sub { $mech->get_ok('/dashboard?updates=1&export=1'); my @rows = $mech->content_as_csv; - is scalar @rows, 15, '1 (header) + 14 (updates) = 15 lines'; + is scalar @rows, 18, '1 (header) + 17 (updates) = 18 lines'; is scalar @{$rows[0]}, 8, '8 columns present'; is_deeply $rows[0], -- cgit v1.2.3 From ecc5a7b9ca20418f1bdb45cdc3ce5b41a11f3593 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 15 Apr 2020 19:12:31 +0100 Subject: Add assigned_(users|categories)_only functionality Users with assigned_categories_only will only see staff features on a report page in their assigned categories. Users will only see staff features on a report page in a category with assigned_users_only if it is in their assigned categories. --- t/app/controller/admin/bodies.t | 10 ++++++++ t/app/controller/admin/users.t | 10 +++++++- t/app/controller/report_inspect.t | 52 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 68 insertions(+), 4 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t index d3e4074f9..883386380 100644 --- a/t/app/controller/admin/bodies.t +++ b/t/app/controller/admin/bodies.t @@ -261,6 +261,16 @@ subtest 'open311 protection editing' => sub { is $contact->get_extra_metadata('open311_protect'), 1, 'Open311 protect flag set'; }; +subtest 'test assigned_users_only setting' => sub { + $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); + $mech->submit_form_ok( { with_fields => { + assigned_users_only => 1, + } } ); + $mech->content_contains('Values updated'); + my $contact = $body->contacts->find({ category => 'test category' }); + is $contact->get_extra_metadata('assigned_users_only'), 1; +}; + subtest 'updates disabling' => sub { $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); $mech->submit_form_ok( { with_fields => { diff --git a/t/app/controller/admin/users.t b/t/app/controller/admin/users.t index 4f0298103..bc8d28e2d 100644 --- a/t/app/controller/admin/users.t +++ b/t/app/controller/admin/users.t @@ -299,6 +299,7 @@ FixMyStreet::override_config { flagged => undef, is_superuser => undef, area_ids => undef, + assigned_categories_only => undef, %default_perms, roles => $role->id, }, @@ -320,6 +321,7 @@ FixMyStreet::override_config { flagged => undef, is_superuser => undef, area_ids => undef, + assigned_categories_only => undef, %default_perms, roles => $role->id, }, @@ -341,6 +343,7 @@ FixMyStreet::override_config { flagged => undef, is_superuser => undef, area_ids => undef, + assigned_categories_only => undef, %default_perms, roles => $role->id, }, @@ -365,6 +368,7 @@ FixMyStreet::override_config { flagged => undef, is_superuser => undef, area_ids => undef, + assigned_categories_only => undef, %default_perms, }, changes => { @@ -385,6 +389,7 @@ FixMyStreet::override_config { flagged => 'on', is_superuser => undef, area_ids => undef, + assigned_categories_only => undef, %default_perms, }, changes => { @@ -394,7 +399,7 @@ FixMyStreet::override_config { log_entries => [qw/edit edit edit edit/], }, { - desc => 'edit user add is_superuser', + desc => 'edit user add is_superuser and assigned_categories_only', fields => { name => 'Changed User', email => 'changed@example.com', @@ -405,10 +410,12 @@ FixMyStreet::override_config { flagged => undef, is_superuser => undef, area_ids => undef, + assigned_categories_only => undef, %default_perms, }, changes => { is_superuser => 'on', + assigned_categories_only => 'on', }, removed => [ keys %default_perms, @@ -428,6 +435,7 @@ FixMyStreet::override_config { flagged => undef, is_superuser => 'on', area_ids => undef, + assigned_categories_only => 'on', }, changes => { is_superuser => undef, diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index 8deb2667e..2852f8d18 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -822,7 +822,53 @@ FixMyStreet::override_config { }; }; +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + ALLOWED_COBRANDS => 'oxfordshire', +}, sub { + subtest 'test relevant staff user display' => sub { + $user->user_body_permissions->create({ body => $oxon, permission_type => 'planned_reports' }); + $user->user_body_permissions->create({ body => $oxon, permission_type => 'moderate' }); + $mech->log_in_ok('body@example.com'); -END { - done_testing(); -} + # First, check user can see staff things on reports 2 and 3 + $mech->get_ok("/report/$report2_id"); + $mech->content_contains(''); + $mech->content_contains('
'); + + # User's categories are ["Cows"], which is currently report 2 + # So should be able to see staff things on 2, but no longer on 3 + $user->set_extra_metadata(assigned_categories_only => 1); + $user->update; + $mech->get_ok("/report/$report2_id"); + $mech->content_contains(''); + $mech->content_lacks('
'); + $mech->content_lacks('Moderate this report'); + $mech->content_lacks('shortlist'); + $user->unset_extra_metadata('assigned_categories_only'); + $user->update; + + # Contact 2 is "Sheep", which is currently report 3 + # So again, should be able to see staff things on 2, but no longer on 3 + $contact2->set_extra_metadata(assigned_users_only => 1); + $contact2->update; + $mech->get_ok("/report/$report2_id"); + $mech->content_contains(''); + $mech->content_lacks('
'); + $mech->content_lacks('Moderate this report'); + $mech->content_lacks('shortlist'); + $contact2->unset_extra_metadata('assigned_users_only'); + $contact2->update; + }; +}; + +done_testing(); -- cgit v1.2.3 From d1622dc20c1623e3f7fb54d72d99370af796c197 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 17 Apr 2020 14:07:32 +0100 Subject: Extend assigned_*_only to report lists. Shortlist buttons and extended print information will not appear where not allowed. --- t/app/controller/around.t | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 186b833fd..6e49c6f29 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -150,7 +150,7 @@ subtest 'check missing body message not shown when it does not need to be' => su }; for my $permission ( qw/ report_inspect report_mark_private/ ) { - subtest 'check non public reports are displayed on around page with $permission permission' => sub { + subtest "check non public reports are displayed on around page with $permission permission" => sub { my $body = FixMyStreet::DB->resultset('Body')->find( $body_edin_id ); my $body2 = FixMyStreet::DB->resultset('Body')->find( $body_west_id ); my $user = $mech->log_in_ok( 'test@example.com' ); @@ -218,6 +218,29 @@ for my $permission ( qw/ report_inspect report_mark_private/ ) { }; } +subtest 'check assigned-only list items do not display shortlist buttons' => sub { + my $body = FixMyStreet::DB->resultset('Body')->find( $body_edin_id ); + my $contact = $mech->create_contact_ok( category => 'Horses', body_id => $body->id, email => "horses\@example.org" ); + $edinburgh_problems[4]->update({ category => 'Horses' }); + + my $user = $mech->log_in_ok( 'test@example.com' ); + $user->set_extra_metadata(assigned_categories_only => 1); + $user->user_body_permissions->delete(); + $user->set_extra_metadata(categories => [ $contact->id ]); + $user->update({ from_body => $body }); + $user->user_body_permissions->find_or_create({ body => $body, permission_type => 'planned_reports' }); + + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'fixmystreet', + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $mech->get_ok('/around?pc=EH1+1BB'); + }; + $mech->content_contains('shortlist-add-' . $edinburgh_problems[4]->id); + $mech->content_lacks('shortlist-add-' . $edinburgh_problems[3]->id); + $mech->content_lacks('shortlist-add-' . $edinburgh_problems[1]->id); +}; + my $body = $mech->create_body_ok(2237, "Oxfordshire"); subtest 'check category, status and extra filtering works on /around' => sub { -- cgit v1.2.3 From 37306b9f6f4cb9b58c5e4a7bdc12e90dff879481 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 24 Apr 2020 17:35:50 +0100 Subject: Disable rename on unprotected Open311 categories. If you rename an Open311 category when it is not protected, it will only get reinstated/deleted by the Open311 populate script shortly after, and can cause issues due to the problem category renaming that occurs. --- t/app/controller/admin/bodies.t | 2 ++ 1 file changed, 2 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t index d3e4074f9..74084afbf 100644 --- a/t/app/controller/admin/bodies.t +++ b/t/app/controller/admin/bodies.t @@ -210,6 +210,7 @@ subtest 'check open311 configuring' => sub { subtest 'check open311 devolved editing' => sub { $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); + $mech->content_contains("name=\"category\"\n size=\"30\" value=\"test category\"\n readonly>", 'Cannot edit Open311 category name'); $mech->submit_form_ok( { with_fields => { send_method => 'Email', email => 'testing@example.org', @@ -217,6 +218,7 @@ subtest 'check open311 devolved editing' => sub { } } ); $mech->content_contains('Values updated'); $mech->get_ok('/admin/body/' . $body->id . '/test%20category'); + $mech->content_contains("name=\"category\"\n size=\"30\" value=\"test category\"\n required>", 'Can edit as now devolved'); $mech->submit_form_ok( { with_fields => { send_method => '', email => 'open311-code', -- cgit v1.2.3 From 538a26498c3516b5bc24636414911b955333f934 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 6 May 2020 17:14:10 +0100 Subject: display user detail for contributed_by in report_edit Include name, email and body rather than just user id. --- t/app/controller/admin/report_edit.t | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/admin/report_edit.t b/t/app/controller/admin/report_edit.t index 438bcc241..01f091412 100644 --- a/t/app/controller/admin/report_edit.t +++ b/t/app/controller/admin/report_edit.t @@ -9,6 +9,7 @@ my $user2 = $mech->create_user_ok('test2@example.com', name => 'Test User 2'); my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1); my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council'); +my $user3 = $mech->create_user_ok('body_user@example.com', name => 'Body User', from_body => $oxfordshire); my $oxfordshirecontact = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Potholes', email => 'potholes@example.com' ); $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Traffic lights', email => 'lights@example.com' ); @@ -707,4 +708,20 @@ subtest "Test display of fields extra data" => sub { $mech->content_contains('Report URL (report_url): http://example.com'); }; +subtest "Test display of contributed_as data" => sub { + $report->update( { extra => undef } ); + $mech->get_ok("/admin/report_edit/$report_id"); + $mech->content_contains('Extra data: No'); + + $report->set_extra_metadata( contributed_as => 'another_user' ); + $report->set_extra_metadata( contributed_by => $user3->id ); + $report->update; + + $report->discard_changes; + + $mech->get_ok("/admin/report_edit/$report_id"); + $mech->content_like(qr!Created By: ]*>Body User \(@{[ $user3->email ]}!); + $mech->content_contains('Created Body: Oxfordshire County Council'); +}; + done_testing(); -- cgit v1.2.3 From c80f13eeac448e99873b690411d7f6e83b07dd06 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 7 May 2020 15:10:46 +0100 Subject: 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. --- t/app/controller/admin/bodies.t | 34 +++++++++++++++++ t/app/controller/report_new_anon.t | 75 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) (limited to 't/app/controller') 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('