From c893b20298aa7af3f9303cef1cc71a96d62b4db5 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Thu, 17 Jun 2021 10:45:40 +0300 Subject: [PATCH] FIX: Destroy invites of anonymized emails (#13404) Anonymizing a user changed their email address, destroyed all associated InvitedUser records, but did not destroy the invites associated to user's email. --- app/jobs/regular/anonymize_user.rb | 1 + spec/services/user_anonymizer_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/jobs/regular/anonymize_user.rb b/app/jobs/regular/anonymize_user.rb index 1113476a81b..c078706c044 100644 --- a/app/jobs/regular/anonymize_user.rb +++ b/app/jobs/regular/anonymize_user.rb @@ -16,6 +16,7 @@ module Jobs def make_anonymous anonymize_ips(@anonymize_ip) if @anonymize_ip + Invite.where(email: @prev_email).destroy_all InvitedUser.where(user_id: @user_id).destroy_all EmailToken.where(user_id: @user_id).destroy_all EmailLog.where(user_id: @user_id).delete_all diff --git a/spec/services/user_anonymizer_spec.rb b/spec/services/user_anonymizer_spec.rb index 13079905455..a150d1e1978 100644 --- a/spec/services/user_anonymizer_spec.rb +++ b/spec/services/user_anonymizer_spec.rb @@ -368,4 +368,17 @@ describe UserAnonymizer do end + describe "anonymize_emails" do + it "destroys all associated invites" do + invite = Fabricate(:invite, email: 'test@example.com') + user = invite.redeem + + Jobs.run_immediately! + described_class.make_anonymous(user, admin) + + expect(user.email).not_to eq('test@example.com') + expect(Invite.exists?(id: invite.id)).to eq(false) + end + end + end