diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-01-17 17:50:50 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-01-31 11:18:53 +0000 |
commit | 7c49ea4a87bb8b98f1c14e28dc4859c05205f9b7 (patch) | |
tree | ba947a7f9d542eda2434ad7c29c6a671505a9038 | |
parent | 736984870d4b1eaf645d2ad3d23058d9abbf4333 (diff) |
Admin ability to make user anonymous.
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 13 | ||||
-rw-r--r-- | t/app/controller/admin.t | 12 | ||||
-rw-r--r-- | templates/web/base/admin/user-form.html | 10 | ||||
-rw-r--r-- | web/cobrands/sass/_admin.scss | 4 |
5 files changed, 38 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d863cc9a..6ae7b2852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ - Change text on /reports to match lower down (fix translation). - Ensure all reports graph can't dip downward. #1956 - Fix error sending `requires_inspection` reports. #1961 + - Admin improvements: + - Admin can anonymize all a user's reports. #1942 - UK: - Lazy load images in the footer. diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 9c63a890f..25fdd2db5 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -1426,11 +1426,13 @@ sub user_edit : Path('user_edit') : Args(1) { '<p><em>' . $c->flash->{status_message} . '</em></p>'; } + $c->forward('/auth/check_csrf_token') if $c->get_param('submit'); + if ( $c->get_param('submit') and $c->get_param('unban') ) { - $c->forward('/auth/check_csrf_token'); $c->forward('unban_user', [ $user ]); + } elsif ( $c->get_param('submit') and $c->get_param('anon_everywhere') ) { + $c->forward('user_anon_everywhere', [ $user ]); } elsif ( $c->get_param('submit') ) { - $c->forward('/auth/check_csrf_token'); my $edited = 0; @@ -1759,6 +1761,13 @@ sub ban_user : Private { return 1; } +sub user_anon_everywhere : Private { + my ( $self, $c, $user ) = @_; + $user->problems->update({anonymous => 1}); + $user->comments->update({anonymous => 1}); + $c->stash->{status_message} = _('That user has been made anonymous on all reports and updates.'); +} + sub unban_user : Private { my ( $self, $c, $user ) = @_; diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 398ce8ea6..bebbb7806 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -1556,6 +1556,18 @@ FixMyStreet::override_config { }; +subtest "Anonymizing user from admin" => sub { + my $user = $mech->create_user_ok('existing@example.com', name => 'Existing User'); + my $count_p = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id })->count; + my $count_u = FixMyStreet::DB->resultset('Comment')->search({ user_id => $user->id })->count; + $mech->get_ok( '/admin/user_edit/' . $user->id ); + $mech->submit_form_ok({ button => 'anon_everywhere' }); + my $c = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id, anonymous => 1 })->count; + is $c, $count_p; + $c = FixMyStreet::DB->resultset('Comment')->search({ user_id => $user->id, anonymous => 1 })->count; + is $c, $count_u; +}; + subtest "Test setting a report from unconfirmed to something else doesn't cause a front end error" => sub { $report->update( { confirmed => undef, state => 'unconfirmed', non_public => 0 } ); $mech->get_ok("/admin/report_edit/$report_id"); diff --git a/templates/web/base/admin/user-form.html b/templates/web/base/admin/user-form.html index f04663727..5a5077e40 100644 --- a/templates/web/base/admin/user-form.html +++ b/templates/web/base/admin/user-form.html @@ -195,5 +195,13 @@ [% END %] [% TRY %][% INCLUDE 'admin/user-form-extra-fields.html' %][% CATCH file %][% END %] </ul> - <input type="submit" class="btn" name="Submit changes" value="[% loc('Submit changes') %]" > + <p> + <input type="submit" class="btn" name="Submit changes" value="[% loc('Submit changes') %]" > + </p> + [% IF user AND NOT user.from_body %] + <p class="danger-zone"> + <input class="btn-danger" type="submit" name="anon_everywhere" value="[% loc('Make anonymous on all reports and updates') %]"> + </p> + [% END %] + </form> diff --git a/web/cobrands/sass/_admin.scss b/web/cobrands/sass/_admin.scss index 8a16b3f00..11536882b 100644 --- a/web/cobrands/sass/_admin.scss +++ b/web/cobrands/sass/_admin.scss @@ -201,3 +201,7 @@ $button_bg_col: #a1a1a1; // also search bar (tables) right: 0.25em; } } + +.danger-zone { + text-align: right; +} |