diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-01-08 17:37:12 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-01-09 17:31:44 +0000 |
commit | c38ca476d282c8e369ae6788b3400c4cc41f3e20 (patch) | |
tree | 871b24adb74a00bb61dd09d76621abfa61df4661 | |
parent | 0cbcf9e9a1153f3463abc01268891658b2853e12 (diff) |
[Inactive] Ignore already anonymized users.
-rw-r--r-- | perllib/FixMyStreet/Script/Inactive.pm | 1 | ||||
-rw-r--r-- | t/script/inactive.t | 12 |
2 files changed, 12 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/Script/Inactive.pm b/perllib/FixMyStreet/Script/Inactive.pm index 0468d2a52..02b01b9b1 100644 --- a/perllib/FixMyStreet/Script/Inactive.pm +++ b/perllib/FixMyStreet/Script/Inactive.pm @@ -126,6 +126,7 @@ sub anonymize_users { my $users = FixMyStreet::DB->resultset("User")->search({ last_active => { '<', interval($self->anonymize) }, + email => { -not_like => 'removed-%@' . FixMyStreet->config('EMAIL_DOMAIN') }, }); while (my $user = $users->next) { diff --git a/t/script/inactive.t b/t/script/inactive.t index 489ff55ca..60cf3ecb5 100644 --- a/t/script/inactive.t +++ b/t/script/inactive.t @@ -1,4 +1,5 @@ use FixMyStreet::TestMech; +use Test::Output; use_ok 'FixMyStreet::Script::Inactive'; @@ -60,10 +61,19 @@ subtest 'Closing updates on inactive fixed/closed reports' => sub { }; subtest 'Anonymization of inactive users' => sub { - $in->users; + my $in = FixMyStreet::Script::Inactive->new( anonymize => 6, email => 3, verbose => 1 ); + stdout_is { $in->users } "Anonymizing user #" . $user->id . "\nEmailing user #" . $user_inactive->id . "\n", 'users dealt with first time'; my $email = $mech->get_email; like $email->as_string, qr/inactive\@example.com/, 'Inactive email sent'; + $mech->clear_emails_ok; + + $user->discard_changes; + is $user->email, 'removed-' . $user->id . '@example.org', 'User has been anonymized'; + + stdout_is { $in->users } '', 'No output second time'; + + $mech->email_count_is(0); # No further email sent $user->discard_changes; is $user->email, 'removed-' . $user->id . '@example.org', 'User has been anonymized'; |