diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-05-11 15:40:56 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-05-23 18:55:09 +0100 |
commit | 110a80eff22e852974bc5a6f90295803ef7e0de6 (patch) | |
tree | 01372412d0d65fb2c0dec99c56ba7867d480af80 | |
parent | a3c182e75b022b3002eb4801fd446c891391b675 (diff) |
Factor anonymize function to User model.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 19 |
2 files changed, 20 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 8f8d7cc47..0d897e71e 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -1911,20 +1911,7 @@ sub user_hide_everywhere : Private { sub user_remove_account : Private { my ( $self, $c, $user ) = @_; $c->forward('user_logout_everywhere', [ $user ]); - $user->problems->update({ anonymous => 1, name => '', send_questionnaire => 0 }); - $user->comments->update({ anonymous => 1, name => '' }); - $user->alerts->update({ whendisabled => \'current_timestamp' }); - $user->password('', 1); - $user->update({ - email => 'removed-' . $user->id . '@' . FixMyStreet->config('EMAIL_DOMAIN'), - email_verified => 0, - name => '', - phone => '', - phone_verified => 0, - title => undef, - twitter_id => undef, - facebook_id => undef, - }); + $user->anonymize_account; $c->stash->{status_message} = _('That user’s personal details have been removed.'); } diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index c624a2efe..3ec6ae92c 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -456,6 +456,25 @@ sub adopt { $other->delete; } +sub anonymize_account { + my $self = shift; + + $self->problems->update({ anonymous => 1, name => '', send_questionnaire => 0 }); + $self->comments->update({ anonymous => 1, name => '' }); + $self->alerts->update({ whendisabled => \'current_timestamp' }); + $self->password('', 1); + $self->update({ + email => 'removed-' . $self->id . '@' . FixMyStreet->config('EMAIL_DOMAIN'), + email_verified => 0, + name => '', + phone => '', + phone_verified => 0, + title => undef, + twitter_id => undef, + facebook_id => undef, + }); +} + # Planned reports / shortlist # Override the default auto-created function as we only want one live entry so |