-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate force delete refresh status notes to a job
- Loading branch information
1 parent
7328ea2
commit 929ccf6
Showing
4 changed files
with
41 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
2 changes: 1 addition & 1 deletion
2
app/jobs/check_force_delete_lift.rb → app/jobs/force_delete_lift_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: '[email protected]', 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: '[email protected]') | ||
@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? | ||
|