mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 00:43:39 +08:00
FIX: Ensure normalized_email gets anonymized (#29720)
This commit is contained in:
parent
0394df524a
commit
d51a9373b4
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user