mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 01:11:43 +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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue