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:
parent
c02c6940bb
commit
4ec2c1e9a9
|
@ -363,7 +363,9 @@ class UserMerger
|
|||
|
||||
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)
|
||||
|
||||
|
|
|
@ -848,6 +848,15 @@ describe UserMerger do
|
|||
expect(UserEmail.where(user_id: source_user.id).count).to eq(0)
|
||||
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
|
||||
UserExport.create(file_name: "user-archive-alice1-190218-003249", user_id: source_user.id)
|
||||
|
||||
|
|
Loading…
Reference in New Issue