diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 22 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 12 | ||||
-rw-r--r-- | t/app/controller/admin.t | 54 | ||||
-rw-r--r-- | t/app/controller/report_inspect.t | 36 |
5 files changed, 98 insertions, 27 deletions
@@ -74,6 +74,7 @@ web-based cross-browser testing tools for this project. - Hide confirmed column on body page if all categories confirmed. #1565 - Show any waiting reports on admin index page. #1382 - Allow user's phone number to be edited, and a report's category. #400 + - Resend report if changing category changes body. #1560. - New user system: - /admin requires a user with the `is_superuser` flag. #1463 - `createsuperuser` command for creating superusers. diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 07a6e7f3c..f0a1fa95b 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -8,10 +8,10 @@ use Path::Class; use POSIX qw(strftime strcoll); use Digest::SHA qw(sha1_hex); use mySociety::EmailUtil qw(is_valid_email); +use mySociety::ArrayUtils; use DateTime::Format::Strptime; use List::Util 'first'; - use FixMyStreet::SendReport; =head1 NAME @@ -837,23 +837,15 @@ Handles changing a problem's category and the complexity that comes with it. sub report_edit_category : Private { my ($self, $c, $problem) = @_; - # TODO: It's possible to assign a category belonging to a district - # council, meaning a 404 when the page is reloaded because the - # problem is no longer included in the current cobrand's - # problem_restriction. - # See mysociety/fixmystreetforcouncils#44 - # We could - # a) only allow the current body's categories to be chosen, - # b) show a warning about the impending change of body - # c) bounce the user to the report page on fms.com - # Not too worried about this right now, as it forms part of a bigger - # concern outlined in the above ticket and - # mysociety/fixmystreetforcouncils#17 if ((my $category = $c->get_param('category')) ne $problem->category) { $problem->category($category); my @contacts = grep { $_->category eq $problem->category } @{$c->stash->{contacts}}; - my $bs = join( ',', map { $_->body_id } @contacts ); - $problem->bodies_str($bs); + my @new_body_ids = map { $_->body_id } @contacts; + # If the report has changed bodies we need to resend it + if (scalar @{mySociety::ArrayUtils::symmetric_diff($problem->bodies_str_ids, \@new_body_ids)}) { + $problem->whensent(undef); + } + $problem->bodies_str(join( ',', @new_body_ids )); } } diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index f69bdc8c0..73479c584 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -390,7 +390,17 @@ sub inspect : Private { anonymous => 0, } ); } - $c->res->redirect( $c->uri_for( '/report', $problem->id ) ); + # This problem might no longer be visible on the current cobrand, + # if its body has changed (e.g. by virtue of the category changing) + # so redirect to a cobrand where it can be seen if necessary + my $redirect_uri; + if ( $c->cobrand->is_council && !$c->cobrand->owns_problem($problem) ) { + $redirect_uri = $c->cobrand->base_url_for_report( $problem ) . $problem->url; + } else { + $redirect_uri = $c->uri_for( $problem->url ); + } + $c->log->debug( "Redirecting to: " . $redirect_uri ); + $c->res->redirect( $redirect_uri ); } } }; diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index a0e013459..6086cf3ac 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -16,8 +16,12 @@ my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super Us my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council', id => 2237); 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' ); my $oxfordshireuser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $oxfordshire); +my $oxford = $mech->create_body_ok(2421, 'Oxford City Council'); +$mech->create_contact_ok( body_id => $oxford->id, category => 'Graffiti', email => 'graffiti@example.net' ); + my $bromley = $mech->create_body_ok(2482, 'Bromley Council', id => 2482); my $user3 = $mech->create_user_ok('test3@example.com', name => 'Test User 2'); @@ -575,6 +579,34 @@ foreach my $test ( }; } +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + ALLOWED_COBRANDS => 'fixmystreet', +}, sub { + +subtest 'change report category' => sub { + my ($ox_report) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Unsure', { + category => 'Potholes', + areas => ',2237,2421,', # Cached used by categories_for_point... + latitude => 51.7549262252, + longitude => -1.25617899435, + whensent => \'current_timestamp', + }); + $mech->get_ok("/admin/report_edit/" . $ox_report->id); + + $mech->submit_form_ok( { with_fields => { category => 'Traffic lights' } }, 'form_submitted' ); + $ox_report->discard_changes; + is $ox_report->category, 'Traffic lights'; + isnt $ox_report->whensent, undef; + + $mech->submit_form_ok( { with_fields => { category => 'Graffiti' } }, 'form_submitted' ); + $ox_report->discard_changes; + is $ox_report->category, 'Graffiti'; + is $ox_report->whensent, undef; +}; + +}; + subtest 'change email to new user' => sub { $log_entries->delete; $mech->get_ok("/admin/report_edit/$report_id"); @@ -1512,13 +1544,15 @@ subtest "response priorities can't be viewed across councils" => sub { }; }; - -$mech->delete_user( $user ); -$mech->delete_user( $user2 ); -$mech->delete_user( $user3 ); -$mech->delete_user( $superuser ); -$mech->delete_user( 'test4@example.com' ); -$mech->delete_body( $oxfordshire ); -$mech->delete_body( $bromley ); - -done_testing(); +END { + $mech->delete_user( $user ); + $mech->delete_user( $user2 ); + $mech->delete_user( $user3 ); + $mech->delete_user( $superuser ); + $mech->delete_user( 'test4@example.com' ); + $mech->delete_body( $oxfordshire ); + $mech->delete_body( $oxford ); + $mech->delete_body( $bromley ); + $mech->delete_body( $westminster ); + done_testing(); +} diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index f2047b8e5..efb32d116 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -17,9 +17,15 @@ FixMyStreet::DB->resultset("ContactResponsePriority")->create({ contact => $contact, response_priority => $rp, }); +my $wodc = $mech->create_body_ok(2420, 'West Oxfordshire District Council', id => 2420); +$mech->create_contact_ok( body_id => $wodc->id, category => 'Horses', email => 'horses@example.net' ); + my ($report) = $mech->create_problems_for_body(1, $oxon->id, 'Test', { - category => 'Cows', cobrand => 'fixmystreet', areas => ',2237,' }); + category => 'Cows', cobrand => 'fixmystreet', areas => ',2237,2420', + whensent => \'current_timestamp', + latitude => 51.847693, longitude => -1.355908, +}); my $report_id = $report->id; my $user = $mech->log_in_ok('test@example.com'); @@ -127,6 +133,34 @@ FixMyStreet::override_config { }; }; +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + ALLOWED_COBRANDS => [ 'oxfordshire', 'fixmystreet' ], + BASE_URL => 'http://fixmystreet.site', +}, sub { + subtest "test category/body changes" => sub { + $mech->host('oxfordshire.fixmystreet.site'); + $report->update({ state => 'confirmed' }); + $mech->get_ok("/report/$report_id"); + # Then change the category to the other council in this location, + # which should cause it to be resent. We clear the host because + # otherwise testing stays on host() above. + $mech->clear_host; + $mech->submit_form(button => 'save', with_fields => { category => 'Horses' }); + + $report->discard_changes; + is $report->category, "Horses", "Report in correct category"; + is $report->whensent, undef, "Report marked as unsent"; + is $report->bodies_str, $wodc->id, "Reported to WODC"; + + is $mech->uri->path, "/report/$report_id", "redirected to correct page"; + is $mech->res->code, 200, "got 200 for final destination"; + is $mech->res->previous->code, 302, "got 302 for redirect"; + # Extra check given host weirdness + is $mech->res->previous->header('Location'), "http://fixmystreet.site/report/$report_id"; + }; +}; + END { $mech->delete_body($oxon); |