Replace email_blacklist_regexp with email_domains_blacklist site setting
This commit is contained in:
parent
d9d2565c25
commit
aaf96f1e29
|
@ -30,6 +30,7 @@ class SiteSetting < ActiveRecord::Base
|
|||
client_setting(:max_topic_title_length, 255)
|
||||
client_setting(:flush_timings_secs, 5)
|
||||
client_setting(:supress_reply_directly_below, true)
|
||||
client_setting(:email_domains_blacklist, 'mailinator.com')
|
||||
|
||||
# settings only available server side
|
||||
setting(:auto_track_topics_after, 60000)
|
||||
|
@ -134,13 +135,8 @@ class SiteSetting < ActiveRecord::Base
|
|||
setting(:body_min_entropy, 7)
|
||||
setting(:max_word_length, 30)
|
||||
|
||||
# Ways to catch griefers and other nasties
|
||||
setting(:email_blacklist_regexp, '')
|
||||
|
||||
setting(:new_user_period_days, 10)
|
||||
|
||||
|
||||
|
||||
def self.call_mothership?
|
||||
self.enforce_global_nicknames? and self.discourse_org_access_key.present?
|
||||
end
|
||||
|
|
|
@ -486,8 +486,9 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def email_validator
|
||||
if (setting = SiteSetting.email_blacklist_regexp.try(:strip)).present?
|
||||
regexp = Regexp.new(setting, true)
|
||||
if (setting = SiteSetting.email_domains_blacklist).present?
|
||||
domains = setting.gsub('.', '\.')
|
||||
regexp = Regexp.new("@(#{domains})", true)
|
||||
if self.email =~ regexp
|
||||
return errors.add(:email, I18n.t(:'user.email.not_allowed'))
|
||||
end
|
||||
|
|
|
@ -261,6 +261,7 @@ en:
|
|||
send_welcome_message: "Do new users get a welcome private message?"
|
||||
supress_reply_directly_below: "Don't show replies button below a post when the reply is directly below"
|
||||
allow_index_in_robots_txt: "Site should be indexed by search engines (update robots.txt)"
|
||||
email_domains_blacklist: "A pipe-delimited list of email domains that are not allowed. Example: mailinator.com|trashmail.net"
|
||||
|
||||
port: "If you'd like to specify a port in the URL. Useful in development mode. Leave blank for none."
|
||||
force_hostname: "If you'd like to specify a hostname in the URL. Useful in development mode. Leave blank for none."
|
||||
|
@ -312,8 +313,6 @@ en:
|
|||
title_min_entropy: "The minimum entropy for a topic title"
|
||||
body_min_entropy: "The minimum entropy for post body"
|
||||
|
||||
email_blacklist_regexp: "A regexp that finds email addresses to block"
|
||||
|
||||
new_user_period_days: "How long a user is highlighted as being new, in days."
|
||||
|
||||
# This section is exported to the javascript for i18n in the admin section
|
||||
|
|
|
@ -456,22 +456,27 @@ describe User do
|
|||
user.should be_valid
|
||||
end
|
||||
|
||||
it 'should reject some emails based on the email_blacklist_regexp site setting' do
|
||||
SiteSetting.stubs(:email_blacklist_regexp).returns('@mailinator')
|
||||
it 'should reject some emails based on the email_domains_blacklist site setting' do
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('mailinator.com')
|
||||
Fabricate.build(:user, email: 'notgood@mailinator.com').should_not be_valid
|
||||
Fabricate.build(:user, email: 'mailinator@gmail.com').should be_valid
|
||||
end
|
||||
|
||||
it 'should reject some emails based on the email_blacklist_regexp site setting' do
|
||||
SiteSetting.stubs(:email_blacklist_regexp).returns('@(mailinator|aol)\.com')
|
||||
it 'should reject some emails based on the email_domains_blacklist site setting' do
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('mailinator.com|trashmail.net')
|
||||
Fabricate.build(:user, email: 'notgood@mailinator.com').should_not be_valid
|
||||
Fabricate.build(:user, email: 'notgood@aol.com').should_not be_valid
|
||||
Fabricate.build(:user, email: 'aol+mailinator@gmail.com').should be_valid
|
||||
Fabricate.build(:user, email: 'notgood@trashmail.net').should_not be_valid
|
||||
Fabricate.build(:user, email: 'mailinator.com@gmail.com').should be_valid
|
||||
end
|
||||
|
||||
it 'should reject some emails based on the email_blacklist_regexp site setting ignoring case' do
|
||||
SiteSetting.stubs(:email_blacklist_regexp).returns('@mailinator')
|
||||
Fabricate.build(:user, email: 'notgood@MAILINATOR.COM').should_not be_valid
|
||||
it 'should reject some emails based on the email_domains_blacklist site setting ignoring case' do
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('trashmail.net')
|
||||
Fabricate.build(:user, email: 'notgood@TRASHMAIL.NET').should_not be_valid
|
||||
end
|
||||
|
||||
it 'should not interpret a period as a wildcard' do
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('trashmail.net')
|
||||
Fabricate.build(:user, email: 'good@trashmailinet.com').should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue