about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorEugen <eugen@zeonfederated.com>2017-04-05 03:27:38 +0200
committerGitHub <noreply@github.com>2017-04-05 03:27:38 +0200
commit4c92f156645f62bd6170df1ce966374574e44ef1 (patch)
tree8ba55a55df75046b4f0a06151418453d06672f13 /app/lib
parent5af0ecbcd9cfd757c4d5bd541d83ca11e44d14ef (diff)
parent94d00f278819d34ef97d59d17eb289e9be217dfe (diff)
Merge branch 'master' into add_more_tests_to_models
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/email_validator.rb17
-rw-r--r--app/lib/feed_manager.rb2
2 files changed, 16 insertions, 3 deletions
diff --git a/app/lib/email_validator.rb b/app/lib/email_validator.rb
index 856b8b1f7..06e9375f6 100644
--- a/app/lib/email_validator.rb
+++ b/app/lib/email_validator.rb
@@ -2,17 +2,30 @@
 
 class EmailValidator < ActiveModel::EachValidator
   def validate_each(record, attribute, value)
-    return if Rails.configuration.x.email_domains_blacklist.empty?
-
     record.errors.add(attribute, I18n.t('users.invalid_email')) if blocked_email?(value)
   end
 
   private
 
   def blocked_email?(value)
+    on_blacklist?(value) || not_on_whitelist?(value)
+  end
+
+  def on_blacklist?(value)
+    return false if Rails.configuration.x.email_domains_blacklist.blank?
+
     domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.')
     regexp  = Regexp.new("@(.+\\.)?(#{domains})", true)
 
     value =~ regexp
   end
+
+  def not_on_whitelist?(value)
+    return false if Rails.configuration.x.email_domains_whitelist.blank?
+
+    domains = Rails.configuration.x.email_domains_whitelist.gsub('.', '\.')
+    regexp  = Regexp.new("@(.+\\.)?(#{domains})", true)
+
+    value !~ regexp
+  end
 end
diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb
index 28e712704..2cca1cefe 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -118,7 +118,7 @@ class FeedManager
 
   def filter_from_mentions?(status, receiver_id)
     check_for_blocks = [status.account_id]
-    check_for_blocks.concat(status.mentions.select('account_id').map(&:account_id))
+    check_for_blocks.concat(status.mentions.pluck(:account_id))
     check_for_blocks.concat([status.in_reply_to_account]) if status.reply? && !status.in_reply_to_account_id.nil?
 
     should_filter   = receiver_id == status.account_id                                                                                   # Filter if I'm mentioning myself