diff --git a/app/interactions/domains/force_delete_lift/base.rb b/app/interactions/domains/force_delete_lift/base.rb index 37826dfe1..2aaa8930c 100644 --- a/app/interactions/domains/force_delete_lift/base.rb +++ b/app/interactions/domains/force_delete_lift/base.rb @@ -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 diff --git a/app/jobs/check_force_delete_lift.rb b/app/jobs/check_force_delete_lift.rb new file mode 100644 index 000000000..43c2666b4 --- /dev/null +++ b/app/jobs/check_force_delete_lift.rb @@ -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 diff --git a/app/models/concerns/email_verifable.rb b/app/models/concerns/email_verifable.rb index 457555b44..1da52dcf3 100644 --- a/app/models/concerns/email_verifable.rb +++ b/app/models/concerns/email_verifable.rb @@ -2,16 +2,14 @@ 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, - domain: domain(billing_email)) + EmailAddressVerification.find_or_create_by(email: unicode_billing_email, + domain: domain(billing_email)) end def email_verification_failed? diff --git a/app/models/email_address_verification.rb b/app/models/email_address_verification.rb index abb1ef423..c54cd4224 100644 --- a/app/models/email_address_verification.rb +++ b/app/models/email_address_verification.rb @@ -42,11 +42,9 @@ class EmailAddressVerification < ApplicationRecord end def check_force_delete - if failed? - Domains::ForceDeleteEmail::Base.run(email: email) - else - Domains::ForceDeleteLift::Base.run(email: email) - end + return unless failed? + + Domains::ForceDeleteEmail::Base.run(email: email) end def verify diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 837ad3adc..ca9f3b24f 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -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