DEV: don't merge email address if target user is not human. (#13915)

While merging two user accounts don't merge the source user's email address if the target user is not a human.

Co-authored-by: Alan Guo Xiang Tan <gxtan1990@gmail.com>
This commit is contained in:
Vinoth Kannan 2021-08-03 10:04:35 +05:30 committed by GitHub
parent c02c6940bb
commit 4ec2c1e9a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -363,7 +363,9 @@ class UserMerger
update_user_id(:user_custom_fields, conditions: "x.name = y.name") update_user_id(:user_custom_fields, conditions: "x.name = y.name")
update_user_id(:user_emails, conditions: "x.email = y.email OR y.primary = false", updates: '"primary" = false') if @target_user.human?
update_user_id(:user_emails, conditions: "x.email = y.email OR y.primary = false", updates: '"primary" = false')
end
UserExport.where(user_id: @source_user.id).update_all(user_id: @target_user.id) UserExport.where(user_id: @source_user.id).update_all(user_id: @target_user.id)

View File

@ -848,6 +848,15 @@ describe UserMerger do
expect(UserEmail.where(user_id: source_user.id).count).to eq(0) expect(UserEmail.where(user_id: source_user.id).count).to eq(0)
end end
it "skips merging email addresses when target user is not human" do
target_user = Discourse.system_user
merge_users!(source_user, target_user)
emails = UserEmail.where(user_id: target_user.id).pluck(:email, :primary)
expect(emails).to contain_exactly([target_user.email, true])
expect(UserEmail.exists?(user_id: source_user.id)).to eq(false)
end
it "updates exports" do it "updates exports" do
UserExport.create(file_name: "user-archive-alice1-190218-003249", user_id: source_user.id) UserExport.create(file_name: "user-archive-alice1-190218-003249", user_id: source_user.id)