FIX: Allow merging users when email domains are restricted
This commit is contained in:
parent
a3cf1cf6ff
commit
ae6c4cd237
|
@ -1200,7 +1200,7 @@ class User < ActiveRecord::Base
|
||||||
if primary_email
|
if primary_email
|
||||||
new_record? ? primary_email.email = new_email : primary_email.update(email: new_email)
|
new_record? ? primary_email.email = new_email : primary_email.update(email: new_email)
|
||||||
else
|
else
|
||||||
self.primary_email = UserEmail.new(email: new_email, user: self, primary: true)
|
self.primary_email = UserEmail.new(email: new_email, user: self, primary: true, skip_validate_email: !should_validate_email_address?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -358,6 +358,8 @@ class UserMerger
|
||||||
|
|
||||||
def delete_source_user
|
def delete_source_user
|
||||||
@source_user.reload
|
@source_user.reload
|
||||||
|
|
||||||
|
@source_user.skip_email_validation = true
|
||||||
@source_user.update(
|
@source_user.update(
|
||||||
admin: false,
|
admin: false,
|
||||||
email: "#{@source_user.username}_#{SecureRandom.hex}@no-email.invalid"
|
email: "#{@source_user.username}_#{SecureRandom.hex}@no-email.invalid"
|
||||||
|
|
|
@ -990,6 +990,15 @@ describe UserMerger do
|
||||||
expect(User.find_by_username(source_user.username)).to be_nil
|
expect(User.find_by_username(source_user.username)).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "works even when email domains are restricted" do
|
||||||
|
SiteSetting.email_domains_whitelist = "example.com|work.com"
|
||||||
|
source_user.update_attribute(:admin, true)
|
||||||
|
|
||||||
|
expect(User.find_by_username(source_user.username)).to be_present
|
||||||
|
merge_users!
|
||||||
|
expect(User.find_by_username(source_user.username)).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
it "deletes external auth infos of source user" do
|
it "deletes external auth infos of source user" do
|
||||||
UserAssociatedAccount.create(user_id: source_user.id, provider_name: "facebook", provider_uid: "1234")
|
UserAssociatedAccount.create(user_id: source_user.id, provider_name: "facebook", provider_uid: "1234")
|
||||||
GithubUserInfo.create(user_id: source_user.id, screen_name: "example", github_user_id: "examplel123123")
|
GithubUserInfo.create(user_id: source_user.id, screen_name: "example", github_user_id: "examplel123123")
|
||||||
|
|
Loading…
Reference in New Issue