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 Domains
module ForceDeleteLift module ForceDeleteLift
class Base < ActiveInteraction::Base class Base < ActiveInteraction::Base
string :email, object :domain,
description: 'Email to check if ForceDelete needs to be lifted' class: Domain,
description: 'Domain to check if ForceDelete needs to be listed'
def execute def execute
domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten prepare_email_verifications(domain)
registrant_ids = Registrant.where(email: email).pluck(:id)
domains = domain_contacts.map(&:domain).flatten + lift_force_delete(domain) if force_delete_condition(domain)
Domain.where(registrant_id: registrant_ids)
domains.each { |domain| lift_force_delete(domain) if force_delete_condition(domain) }
end end
private private
@ -26,6 +23,11 @@ module Domains
domain.contacts.all? { |contact| contact.email_verification.verified? } && domain.contacts.all? { |contact| contact.email_verification.verified? } &&
domain.registrant.email_verification.verified? domain.registrant.email_verification.verified?
end end
def prepare_email_verifications(domain)
domain.registrant.email_verification.verify
domain.contacts.each { |contact| contact.email_verification.verify }
end
end end
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,16 +2,14 @@ module EmailVerifable
extend ActiveSupport::Concern extend ActiveSupport::Concern
def email_verification def email_verification
@email_verification ||= EmailAddressVerification.find_or_create_by(email: unicode_email, EmailAddressVerification.find_or_create_by(email: unicode_email, domain: domain(email))
domain: domain(email))
end end
def billing_email_verification def billing_email_verification
return unless attribute_names.include?('billing_email') return unless attribute_names.include?('billing_email')
@billing_email_verification ||= EmailAddressVerification EmailAddressVerification.find_or_create_by(email: unicode_billing_email,
.find_or_create_by(email: unicode_billing_email, domain: domain(billing_email))
domain: domain(billing_email))
end end
def email_verification_failed? def email_verification_failed?

View file

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

View file

@ -384,6 +384,33 @@ class ForceDeleteTest < ActionMailer::TestCase
assert notification.text.include? asserted_text assert notification.text.include? asserted_text
end 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) def prepare_bounced_email_address(email)
@bounced_mail = BouncedMailAddress.new @bounced_mail = BouncedMailAddress.new
@bounced_mail.email = email @bounced_mail.email = email