mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 14:36:22 +02:00
Merge pull request #2418 from internetee/2413-force-delete-lift-bug
Fix check force delete lift bug
This commit is contained in:
commit
4a0dc8e159
4 changed files with 50 additions and 39 deletions
|
@ -3,41 +3,9 @@ class CheckForceDeleteJob < ApplicationJob
|
|||
contacts = Contact.find(contact_ids)
|
||||
|
||||
contacts.each do |contact|
|
||||
email = contact.email
|
||||
next unless contact.need_to_start_force_delete?
|
||||
|
||||
if contact.need_to_start_force_delete?
|
||||
Domains::ForceDeleteEmail::Base.run(email: email)
|
||||
elsif contact.need_to_lift_force_delete?
|
||||
domain_list(email).each { |domain| refresh_status_notes(contact, domain) }
|
||||
end
|
||||
Domains::ForceDeleteEmail::Base.run(email: contact.email)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def refresh_status_notes(contact, domain)
|
||||
force_delete_emails = domain.status_notes[DomainStatus::FORCE_DELETE]
|
||||
return unless force_delete_emails
|
||||
|
||||
force_delete_emails.slice!(contact.email_history)
|
||||
force_delete_emails.lstrip!
|
||||
domain.save(validate: false)
|
||||
|
||||
notify_registrar(domain) unless force_delete_emails.empty?
|
||||
end
|
||||
|
||||
def domain_list(email)
|
||||
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]))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,10 @@ class CheckForceDeleteLift < ApplicationJob
|
|||
queue_as :default
|
||||
|
||||
def perform
|
||||
domains = Domain.where("(status_notes->'serverForceDelete') is not null")
|
||||
.select { |d| d.registrant.need_to_lift_force_delete? }
|
||||
|
||||
handle_refresh_status(domains) if domains.present?
|
||||
domains = Domain.where("force_delete_data->'template_name' = ?", 'invalid_email')
|
||||
.where("force_delete_data->'force_delete_type' = ?", 'soft')
|
||||
|
||||
|
@ -9,4 +13,41 @@ class CheckForceDeleteLift < ApplicationJob
|
|||
Domains::ForceDeleteLift::Base.run(domain: domain)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def handle_refresh_status(domains)
|
||||
domains.each do |domain|
|
||||
registrant = domain.registrant
|
||||
event = registrant.validation_events.last
|
||||
next if event.blank?
|
||||
|
||||
domain_list(event).each { |d| refresh_status_notes(d, registrant) }
|
||||
end
|
||||
end
|
||||
|
||||
def domain_list(event)
|
||||
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, registrant)
|
||||
return unless domain.status_notes[DomainStatus::FORCE_DELETE]
|
||||
|
||||
domain.status_notes[DomainStatus::FORCE_DELETE].slice!(registrant.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
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
desc 'Check Force Delete'
|
||||
task check_force_delete: :environment do
|
||||
validations = ValidationEvent.failed.where(validation_eventable_type: 'Contact').uniq(&:validation_eventable_id)
|
||||
return if validations.blank?
|
||||
|
||||
invalid_contact_ids = validations.select do |validation|
|
||||
contact = validation.validation_eventable
|
||||
next if contact.nil?
|
||||
next unless contact
|
||||
|
||||
contact.need_to_start_force_delete? || contact.need_to_lift_force_delete?
|
||||
contact.need_to_start_force_delete?
|
||||
end.pluck(:validation_eventable_id)
|
||||
|
||||
CheckForceDeleteJob.perform_later(invalid_contact_ids) if invalid_contact_ids.present?
|
||||
|
|
|
@ -453,12 +453,13 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
travel_to Time.zone.parse('2010-07-05 0:00:03')
|
||||
contact_first.verify_email
|
||||
|
||||
perform_check_force_delete_job(contact_first.id)
|
||||
perform_enqueued_jobs { CheckForceDeleteLift.perform_now }
|
||||
domain.reload
|
||||
|
||||
assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_email
|
||||
notification = domain.registrar.notifications.last
|
||||
assert_nil domain.status_notes[DomainStatus::FORCE_DELETE]
|
||||
notification = domain.registrar.notifications.last(2).first
|
||||
assert notification.text.include? asserted_text
|
||||
assert_not domain.force_delete_scheduled?
|
||||
end
|
||||
|
||||
def test_domain_should_have_several_bounced_emails
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue