mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-14 00:08:46 +00:00
Finish email allow/deny list naming migration (#30530)
This commit is contained in:
@@ -15,7 +15,7 @@ class EmailMxValidator < ActiveModel::Validator
|
||||
|
||||
if resolved_ips.empty?
|
||||
user.errors.add(:email, :unreachable)
|
||||
elsif on_blacklist?(resolved_domains, user.sign_up_ip)
|
||||
elsif email_domain_blocked?(resolved_domains, user.sign_up_ip)
|
||||
user.errors.add(:email, :blocked)
|
||||
end
|
||||
end
|
||||
@@ -34,9 +34,9 @@ class EmailMxValidator < ActiveModel::Validator
|
||||
end
|
||||
|
||||
def on_allowlist?(domain)
|
||||
return false if Rails.configuration.x.email_domains_whitelist.blank?
|
||||
return false if Rails.configuration.x.email_domains_allowlist.blank?
|
||||
|
||||
Rails.configuration.x.email_domains_whitelist.include?(domain)
|
||||
Rails.configuration.x.email_domains_allowlist.include?(domain)
|
||||
end
|
||||
|
||||
def resolve_mx(domain)
|
||||
@@ -58,7 +58,7 @@ class EmailMxValidator < ActiveModel::Validator
|
||||
[ips, records]
|
||||
end
|
||||
|
||||
def on_blacklist?(domains, attempt_ip)
|
||||
def email_domain_blocked?(domains, attempt_ip)
|
||||
EmailDomainBlock.block?(domains, attempt_ip: attempt_ip)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class BlacklistedEmailValidator < ActiveModel::Validator
|
||||
class UserEmailValidator < ActiveModel::Validator
|
||||
def validate(user)
|
||||
return if user.valid_invitation? || user.email.blank?
|
||||
|
||||
@@ -23,18 +23,18 @@ class BlacklistedEmailValidator < ActiveModel::Validator
|
||||
end
|
||||
|
||||
def not_allowed_through_configuration?(email)
|
||||
return false if Rails.configuration.x.email_domains_whitelist.blank?
|
||||
return false if Rails.configuration.x.email_domains_allowlist.blank?
|
||||
|
||||
domains = Rails.configuration.x.email_domains_whitelist.gsub('.', '\.')
|
||||
domains = Rails.configuration.x.email_domains_allowlist.gsub('.', '\.')
|
||||
regexp = Regexp.new("@(.+\\.)?(#{domains})$", true)
|
||||
|
||||
email !~ regexp
|
||||
end
|
||||
|
||||
def disallowed_through_configuration?(email)
|
||||
return false if Rails.configuration.x.email_domains_blacklist.blank?
|
||||
return false if Rails.configuration.x.email_domains_denylist.blank?
|
||||
|
||||
domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.')
|
||||
domains = Rails.configuration.x.email_domains_denylist.gsub('.', '\.')
|
||||
regexp = Regexp.new("@(.+\\.)?(#{domains})", true)
|
||||
|
||||
regexp.match?(email)
|
||||
Reference in New Issue
Block a user