Add a job to check if domain needs to be fd-lifted

This commit is contained in:
Alex Sherman 2021-04-06 10:15:54 +05:00
parent 6383dede4b
commit 39d392696a
5 changed files with 55 additions and 18 deletions

View file

@ -1,17 +1,14 @@
module Domains
module ForceDeleteLift
class Base < ActiveInteraction::Base
string :email,
description: 'Email to check if ForceDelete needs to be lifted'
object :domain,
class: Domain,
description: 'Domain to check if ForceDelete needs to be listed'
def execute
domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
registrant_ids = Registrant.where(email: email).pluck(:id)
prepare_email_verifications(domain)
domains = domain_contacts.map(&:domain).flatten +
Domain.where(registrant_id: registrant_ids)
domains.each { |domain| lift_force_delete(domain) if force_delete_condition(domain) }
lift_force_delete(domain) if force_delete_condition(domain)
end
private
@ -26,6 +23,11 @@ module Domains
domain.contacts.all? { |contact| contact.email_verification.verified? } &&
domain.registrant.email_verification.verified?
end
def prepare_email_verifications(domain)
domain.registrant.email_verification.verify
domain.contacts.each { |contact| contact.email_verification.verify }
end
end
end
end

View file

@ -0,0 +1,12 @@
class CheckForceDeleteLift < ApplicationJob
queue_as :default
def perform
domains = Domain.where("force_delete_data->'template_name' = ?", 'invalid_email')
.where("force_delete_data->'force_delete_type' = ?", 'soft')
domains.each do |domain|
Domains::ForceDeleteLift::Base.run(domain: domain)
end
end
end

View file

@ -2,15 +2,13 @@ module EmailVerifable
extend ActiveSupport::Concern
def email_verification
@email_verification ||= EmailAddressVerification.find_or_create_by(email: unicode_email,
domain: domain(email))
EmailAddressVerification.find_or_create_by(email: unicode_email, domain: domain(email))
end
def billing_email_verification
return unless attribute_names.include?('billing_email')
@billing_email_verification ||= EmailAddressVerification
.find_or_create_by(email: unicode_billing_email,
EmailAddressVerification.find_or_create_by(email: unicode_billing_email,
domain: domain(billing_email))
end

View file

@ -42,11 +42,9 @@ class EmailAddressVerification < ApplicationRecord
end
def check_force_delete
if failed?
return unless failed?
Domains::ForceDeleteEmail::Base.run(email: email)
else
Domains::ForceDeleteLift::Base.run(email: email)
end
end
def verify

View file

@ -384,6 +384,33 @@ class ForceDeleteTest < ActionMailer::TestCase
assert notification.text.include? asserted_text
end
def test_lifts_force_delete_if_contact_fixed
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
email = 'some@strangesentence@internet.ee'
Truemail.configure.default_validation_type = :regex
contact = @domain.admin_contacts.first
contact.update_attribute(:email, email)
contact.email_verification.verify
assert contact.email_verification_failed?
@domain.reload
assert @domain.force_delete_scheduled?
contact.update_attribute(:email, 'aaa@bbb.com')
contact.email_verification.verify
assert_not contact.email_verification_failed?
CheckForceDeleteLift.perform_now
@domain.reload
assert_not @domain.force_delete_scheduled?
end
def prepare_bounced_email_address(email)
@bounced_mail = BouncedMailAddress.new
@bounced_mail.email = email