2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-10-03 17:21:20 +08:00

FIX: Ensure normalized_email gets anonymized (#29719)

This commit is contained in:
Roman Rizzi 2024-11-12 14:36:17 -03:00 committed by GitHub
parent d7503a6153
commit d97d48ead1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 0 deletions

View file

@ -40,7 +40,9 @@ class UserAnonymizer
end

@user.save!

@user.primary_email.update_attribute(:email, "#{@user.username}#{EMAIL_SUFFIX}")
@user.primary_email.update_attribute(:normalized_email, "#{@user.username}#{EMAIL_SUFFIX}")

options = @user.user_option
options.mailing_list_mode = false

View file

@ -0,0 +1,14 @@
# frozen_string_literal: true
class AnonymizeNormalizedEmailColumn < ActiveRecord::Migration[7.1]
def up
execute <<~SQL
UPDATE user_emails
SET normalized_email = email
WHERE SPLIT_PART(email, '@', 2) = 'anonymized.invalid'
SQL
end

def down
raise ActiveRecord::IrreversibleMigration
end
end

View file

@ -39,6 +39,14 @@ RSpec.describe UserAnonymizer do
expect(user.reload.email).to eq("#{user.username}@anonymized.invalid")
end

it "changes the primary email normalized email address" do
make_anonymous

primary_email = user.reload.primary_email

expect(primary_email.normalized_email).to eq("#{user.username}@anonymized.invalid")
end

it "changes the primary email address when there is an email domain allowlist" do
SiteSetting.allowed_email_domains = "example.net|wayne.com|discourse.org"