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.
This commit is contained in:
Dan Ungureanu 2021-06-17 10:45:40 +03:00 committed by GitHub
parent aa4f0aee67
commit c893b20298
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -16,6 +16,7 @@ module Jobs
def make_anonymous def make_anonymous
anonymize_ips(@anonymize_ip) if @anonymize_ip anonymize_ips(@anonymize_ip) if @anonymize_ip
Invite.where(email: @prev_email).destroy_all
InvitedUser.where(user_id: @user_id).destroy_all InvitedUser.where(user_id: @user_id).destroy_all
EmailToken.where(user_id: @user_id).destroy_all EmailToken.where(user_id: @user_id).destroy_all
EmailLog.where(user_id: @user_id).delete_all EmailLog.where(user_id: @user_id).delete_all

View File

@ -368,4 +368,17 @@ describe UserAnonymizer do
end 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 end