mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 21:57:36 +08:00
26 lines
795 B
Ruby
26 lines
795 B
Ruby
require_dependency 'screening_model'
|
|
|
|
# A ScreenedEmail record represents an email address that is being watched,
|
|
# typically when creating a new User account. If the email of the signup form
|
|
# (or some other form) matches a ScreenedEmail record, an action can be
|
|
# performed based on the action_type.
|
|
class ScreenedEmail < ActiveRecord::Base
|
|
|
|
include ScreeningModel
|
|
|
|
default_action :block
|
|
|
|
validates :email, presence: true, uniqueness: true
|
|
|
|
def self.block(email, opts={})
|
|
find_by_email(email) || create(opts.slice(:action_type).merge({email: email}))
|
|
end
|
|
|
|
def self.should_block?(email)
|
|
screened_email = ScreenedEmail.where(email: email).first
|
|
screened_email.record_match! if screened_email
|
|
screened_email && screened_email.action_type == actions[:block]
|
|
end
|
|
|
|
end
|