diff --git a/app/jobs/check_force_delete_lift_job.rb b/app/jobs/check_force_delete_lift_job.rb new file mode 100644 index 0000000000..78e586d1e1 --- /dev/null +++ b/app/jobs/check_force_delete_lift_job.rb @@ -0,0 +1,35 @@ +class CheckForceDeleteLiftJob < ApplicationJob + def perform(validation_event_id, contact_id) + @event = ValidationEvent.find(validation_event_id) + @contact = Contact.find(contact_id) + + return unless @contact.need_to_lift_force_delete? + + domain_list.each { |domain| refresh_status_notes(domain) } + end + + def domain_list + domain_contacts = Contact.where(email: @event.email).map(&:domain_contacts).flatten + registrant_ids = Registrant.where(email: @event.email).pluck(:id) + + (domain_contacts.map(&:domain).flatten + Domain.where(registrant_id: registrant_ids)).uniq + end + + def refresh_status_notes(domain) + return unless domain.status_notes[DomainStatus::FORCE_DELETE] + + domain.status_notes[DomainStatus::FORCE_DELETE].slice!(@contact.email_history) + domain.status_notes[DomainStatus::FORCE_DELETE].lstrip! + domain.save(validate: false) + + notify_registrar(domain) unless domain.status_notes[DomainStatus::FORCE_DELETE].empty? + end + + def notify_registrar(domain) + domain.registrar.notifications.create!(text: I18n.t('force_delete_auto_email', + domain_name: domain.name, + outzone_date: domain.outzone_date, + purge_date: domain.purge_date, + email: domain.status_notes[DomainStatus::FORCE_DELETE])) + end +end diff --git a/app/jobs/check_force_delete_lift.rb b/app/jobs/force_delete_lift_job.rb similarity index 87% rename from app/jobs/check_force_delete_lift.rb rename to app/jobs/force_delete_lift_job.rb index 43c2666b40..631e906e61 100644 --- a/app/jobs/check_force_delete_lift.rb +++ b/app/jobs/force_delete_lift_job.rb @@ -1,4 +1,4 @@ -class CheckForceDeleteLift < ApplicationJob +class ForceDeleteLiftJob < ApplicationJob queue_as :default def perform diff --git a/app/models/validation_event.rb b/app/models/validation_event.rb index 0c1753d635..60dba31290 100644 --- a/app/models/validation_event.rb +++ b/app/models/validation_event.rb @@ -63,33 +63,6 @@ def object private def check_force_delete_lift - return unless object.need_to_lift_force_delete? - - domain_list.each { |domain| refresh_status_notes(domain) } - end - - def refresh_status_notes(domain) - return unless domain.status_notes[DomainStatus::FORCE_DELETE] - - domain.status_notes[DomainStatus::FORCE_DELETE].slice!(object.email_history) - domain.status_notes[DomainStatus::FORCE_DELETE].lstrip! - domain.save(validate: false) - - notify_registrar(domain) unless domain.status_notes[DomainStatus::FORCE_DELETE].empty? - end - - def domain_list - domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten - registrant_ids = Registrant.where(email: email).pluck(:id) - - (domain_contacts.map(&:domain).flatten + Domain.where(registrant_id: registrant_ids)).uniq - end - - def notify_registrar(domain) - domain.registrar.notifications.create!(text: I18n.t('force_delete_auto_email', - domain_name: domain.name, - outzone_date: domain.outzone_date, - purge_date: domain.purge_date, - email: domain.status_notes[DomainStatus::FORCE_DELETE])) + CheckForceDeleteLiftJob.perform_later(id, object.id) if object.need_to_lift_force_delete? end end diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index e19d6f65d5..2e0bed5fd6 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -453,6 +453,7 @@ def test_remove_invalid_email_from_domain_status_notes travel_to Time.zone.parse('2010-07-05 0:00:03') contact_first.verify_email + perform_enqueued_jobs perform_check_force_delete_job(contact_first.id) domain.reload @@ -511,7 +512,7 @@ def test_lifts_force_delete_after_bounce_changes @domain.registrant.update(email: 'aaa@bbb.com', email_history: email) @domain.registrant.verify_email assert @domain.registrant.need_to_lift_force_delete? - CheckForceDeleteLift.perform_now + ForceDeleteLiftJob.perform_now @domain.reload assert_not @domain.force_delete_scheduled? @@ -530,11 +531,12 @@ def test_lifts_force_delete_after_changing_to_valid_email @domain.registrant.update(email: 'aaa@bbb.ee') @domain.registrant.verify_email + perform_enqueued_jobs @domain.reload assert @domain.registrant.need_to_lift_force_delete? - perform_enqueued_jobs { CheckForceDeleteLift.perform_now } + perform_enqueued_jobs { ForceDeleteLiftJob.perform_now } @domain.reload assert_not @domain.force_delete_scheduled?