diff --git a/app/models/user.rb b/app/models/user.rb index 0696a8da1..47d5eb24a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -506,7 +506,7 @@ class User < ActiveRecord::Base end def email_validator - if (setting = SiteSetting.email_domains_blacklist).present? + if new_record? and (setting = SiteSetting.email_domains_blacklist).present? domains = setting.gsub('.', '\.') regexp = Regexp.new("@(#{domains})", true) if self.email =~ regexp diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a5174b503..a8b740340 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -478,6 +478,12 @@ describe User do SiteSetting.stubs(:email_domains_blacklist).returns('trashmail.net') Fabricate.build(:user, email: 'good@trashmailinet.com').should be_valid end + + it 'should not be used to validate existing records' do + u = Fabricate(:user, email: 'in_before_blacklisted@fakemail.com') + SiteSetting.stubs(:email_domains_blacklist).returns('fakemail.com') + u.should be_valid + end end describe 'passwords' do