discourse/app/models/blocked_email.rb

26 lines
543 B
Ruby
Raw Normal View History

class BlockedEmail < ActiveRecord::Base
before_validation :set_defaults
validates :email, presence: true, uniqueness: true
def self.actions
@actions ||= Enum.new(:block, :do_nothing)
end
def self.should_block?(email)
record = BlockedEmail.where(email: email).first
if record
record.match_count += 1
record.last_match_at = Time.zone.now
record.save
end
record && record.action_type == actions[:block]
end
def set_defaults
self.action_type ||= BlockedEmail.actions[:block]
end
end