diff options
author | Dave Arter <davea@mysociety.org> | 2020-01-06 11:01:59 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2020-01-06 11:03:13 +0000 |
commit | 64944ca56e310f256536b94065542141f1341a8b (patch) | |
tree | fffd07196d27c5f06ecd9c649874b4de087c27db | |
parent | 9d876bf9829ec3b00240707ff4ba04b1a1265317 (diff) |
Clear any categories from user when unsetting from_body
This was most likely the cause of #2815.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Users.pm | 2 | ||||
-rw-r--r-- | t/app/controller/admin/users.t | 24 |
3 files changed, 27 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4819a1ef8..6ae350b1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ - Fix removal of cached photos on moderation. #2696 - Checking of cached front page details against database. #2696 - Inconsistent display of mark private checkbox for staff users + - Clear user categories when staff access is removed. #2815 - Development improvements: - Upgrade the underlying framework and a number of other packages. #2473 - Add feature cobrand helper function. diff --git a/perllib/FixMyStreet/App/Controller/Admin/Users.pm b/perllib/FixMyStreet/App/Controller/Admin/Users.pm index 1520fe990..046e19126 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Users.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Users.pm @@ -373,6 +373,8 @@ sub edit : Chained('user') : PathPart('') : Args(0) { my @live_contact_ids = map { $_->id } @live_contacts; my @new_contact_ids = grep { $c->get_param("contacts[$_]") } @live_contact_ids; $user->set_extra_metadata('categories', \@new_contact_ids); + } else { + $user->unset_extra_metadata('categories'); } $user->update; diff --git a/t/app/controller/admin/users.t b/t/app/controller/admin/users.t index e732f0edd..2e3ad9e5a 100644 --- a/t/app/controller/admin/users.t +++ b/t/app/controller/admin/users.t @@ -162,6 +162,30 @@ subtest 'user_edit redirects appropriately' => sub { }; }; +subtest 'user categories are cleared when from_body is unset' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'oxfordshire' ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $mech->log_in_ok( $user3->email ); + + my $cat1 = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Traffic lights', email => 'lights@example.com' ); + my $cat2 = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Potholes', email => 'potholes@example.com' ); + $user2->set_extra_metadata('categories', [ $cat1->id, $cat2->id ]); + $user2->from_body($oxfordshire->id); + $user2->update; + + $mech->get_ok('/admin/users/' . $user2->id); + $mech->submit_form_ok( { with_fields => { + body => undef + } } ); + + $user2->discard_changes; + is $user2->from_body, undef, "from_body unset"; + is $user2->get_extra_metadata('categories'), undef, "categories unset"; + }; +}; + $mech->log_in_ok( $superuser->email ); for my $test ( |