Commit 23afb02a authored by Patricio Cano's avatar Patricio Cano

Refactor `match_domain` to a predicate: `domain_matches?`

parent c71e658c
...@@ -865,7 +865,7 @@ class User < ActiveRecord::Base ...@@ -865,7 +865,7 @@ class User < ActiveRecord::Base
if current_application_settings.domain_blacklist_enabled? if current_application_settings.domain_blacklist_enabled?
blocked_domains = current_application_settings.domain_blacklist blocked_domains = current_application_settings.domain_blacklist
if match_domain(blocked_domains, self.email) if domain_matches?(blocked_domains, self.email)
error = 'is not from an allowed domain.' error = 'is not from an allowed domain.'
valid = false valid = false
end end
...@@ -873,7 +873,7 @@ class User < ActiveRecord::Base ...@@ -873,7 +873,7 @@ class User < ActiveRecord::Base
allowed_domains = current_application_settings.domain_whitelist allowed_domains = current_application_settings.domain_whitelist
unless allowed_domains.blank? unless allowed_domains.blank?
if match_domain(allowed_domains, self.email) if domain_matches?(allowed_domains, self.email)
valid = true valid = true
else else
error = "is not whitelisted. Email domains valid for registration are: #{allowed_domains.join(', ')}" error = "is not whitelisted. Email domains valid for registration are: #{allowed_domains.join(', ')}"
...@@ -886,7 +886,7 @@ class User < ActiveRecord::Base ...@@ -886,7 +886,7 @@ class User < ActiveRecord::Base
valid valid
end end
def match_domain(email_domains, email) def domain_matches?(email_domains, email)
signup_domain = Mail::Address.new(email).domain signup_domain = Mail::Address.new(email).domain
email_domains.any? do |domain| email_domains.any? do |domain|
escaped = Regexp.escape(domain).gsub('\*', '.*?') escaped = Regexp.escape(domain).gsub('\*', '.*?')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment