FIX: User merge should not fail when primary email address is missing

The merge process might move all email addresses of the source user to the target user. Destroying the source user failed in that case.
This commit is contained in:
Gerhard Schlager 2018-06-01 16:23:21 +02:00
parent 313ff264f2
commit b970b072f6
2 changed files with 14 additions and 1 deletions

View File

@ -347,7 +347,11 @@ class UserMerger
def delete_source_user
@source_user.reload
@source_user.update_attribute(:admin, false)
@source_user.update_attributes(
admin: false,
email: "#{@source_user.username}_#{SecureRandom.hex}@no-email.invalid"
)
UserDestroyer.new(Discourse.system_user).destroy(@source_user)
end

View File

@ -953,6 +953,15 @@ describe UserMerger do
expect(User.find_by_username(source_user.username)).to be_nil
end
it "deletes the source user even when it is a member of a group that grants a trust level" do
group = Fabricate(:group, grant_trust_level: 3)
group.bulk_add([source_user.id, target_user.id])
merge_users!
expect(User.find_by_username(source_user.username)).to be_nil
end
it "deletes external auth infos of source user" do
FacebookUserInfo.create(user_id: source_user.id, facebook_user_id: "example")
GithubUserInfo.create(user_id: source_user.id, screen_name: "example", github_user_id: "examplel123123")