|
|
|
@ -4,11 +4,12 @@
|
|
|
|
|
#
|
|
|
|
|
# Table name: email_domain_blocks
|
|
|
|
|
#
|
|
|
|
|
# id :bigint(8) not null, primary key
|
|
|
|
|
# domain :string default(""), not null
|
|
|
|
|
# created_at :datetime not null
|
|
|
|
|
# updated_at :datetime not null
|
|
|
|
|
# parent_id :bigint(8)
|
|
|
|
|
# id :bigint(8) not null, primary key
|
|
|
|
|
# domain :string default(""), not null
|
|
|
|
|
# created_at :datetime not null
|
|
|
|
|
# updated_at :datetime not null
|
|
|
|
|
# parent_id :bigint(8)
|
|
|
|
|
# allow_with_approval :boolean default(FALSE), not null
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
class EmailDomainBlock < ApplicationRecord
|
|
|
|
@ -42,8 +43,8 @@ class EmailDomainBlock < ApplicationRecord
|
|
|
|
|
@attempt_ip = attempt_ip
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def match?
|
|
|
|
|
blocking? || invalid_uri?
|
|
|
|
|
def match?(...)
|
|
|
|
|
blocking?(...) || invalid_uri?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
@ -52,8 +53,8 @@ class EmailDomainBlock < ApplicationRecord
|
|
|
|
|
@uris.any?(&:nil?)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def blocking?
|
|
|
|
|
blocks = EmailDomainBlock.where(domain: domains_with_variants).order(Arel.sql('char_length(domain) desc'))
|
|
|
|
|
def blocking?(allow_with_approval: false)
|
|
|
|
|
blocks = EmailDomainBlock.where(domain: domains_with_variants, allow_with_approval: allow_with_approval).order(Arel.sql('char_length(domain) desc'))
|
|
|
|
|
blocks.each { |block| block.history.add(@attempt_ip) } if @attempt_ip.present?
|
|
|
|
|
blocks.any?
|
|
|
|
|
end
|
|
|
|
@ -86,4 +87,8 @@ class EmailDomainBlock < ApplicationRecord
|
|
|
|
|
def self.block?(domain_or_domains, attempt_ip: nil)
|
|
|
|
|
Matcher.new(domain_or_domains, attempt_ip: attempt_ip).match?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.requires_approval?(domain_or_domains, attempt_ip: nil)
|
|
|
|
|
Matcher.new(domain_or_domains, attempt_ip: attempt_ip).match?(allow_with_approval: true)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|