WIP Interim save

This commit is contained in:
Alex Sherman 2021-06-28 15:44:28 +05:00
parent b0fb2f40cd
commit 7d3f0249dc
6 changed files with 75 additions and 67 deletions

View file

@ -1,15 +1,20 @@
module EmailVerifable
extend ActiveSupport::Concern
included do
has_many :email_address_verifications, as: :email_verifable
end
def email_verification
EmailAddressVerification.find_or_create_by(email: unicode_email, domain: domain(email))
# EmailAddressVerification.find_or_create_by(email: unicode_email, domain: domain(email))
email_address_verification
end
def billing_email_verification
return unless attribute_names.include?('billing_email')
EmailAddressVerification.find_or_create_by(email: unicode_billing_email,
domain: domain(billing_email))
# return unless attribute_names.include?('billing_email')
#
# EmailAddressVerification.find_or_create_by(email: unicode_billing_email,
# domain: domain(billing_email))
end
def email_verification_failed?

View file

@ -25,8 +25,8 @@ class Contact < ApplicationRecord
alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail
scope :email_verification_failed, lambda {
joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email')
.where('success = false and verified_at IS NOT NULL')
# joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email')
# .where('success = false and verified_at IS NOT NULL')
}
NAME_REGEXP = /([\u00A1-\u00B3\u00B5-\u00BF\u0021-\u0026\u0028-\u002C\u003A-\u0040]|

View file

@ -1,50 +1,15 @@
class EmailAddressVerification < ApplicationRecord
RECENTLY_VERIFIED_PERIOD = 1.month
after_save :check_force_delete
belongs_to :email_verifable, polymorphic: true
scope :not_verified_recently, lambda {
where('verified_at IS NULL or verified_at < ?', verification_period)
}
RECENTLY_VERIFIED_PERIOD = 1.year.freeze
SCAN_CYCLES = 3.freeze
# after_save :check_force_delete
scope :verified_recently, lambda {
where('verified_at IS NOT NULL and verified_at >= ?', verification_period).where(success: true)
}
scope :verification_failed, lambda {
where.not(verified_at: nil).where(success: false)
}
scope :by_domain, ->(domain_name) { where(domain: domain_name) }
def recently_verified?
verified_at.present? &&
verified_at > verification_period
end
def verification_period
self.class.verification_period
end
def self.verification_period
Time.zone.now - RECENTLY_VERIFIED_PERIOD
end
def not_verified?
verified_at.blank? && !success
end
def failed?
bounce_present? || (verified_at.present? && !success)
end
def verified?
success
end
def bounce_present?
BouncedMailAddress.find_by(email: email).present?
end
def check_force_delete
return unless failed?