internetee-registry/app/interactions/domains/force_delete_email/base.rb
2021-03-22 14:54:24 +05:00

27 lines
879 B
Ruby

module Domains
module ForceDeleteEmail
class Base < ActiveInteraction::Base
string :email,
description: 'Bounced email to set ForceDelete from'
def execute
domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
registrant_ids = Registrant.where(email: email).pluck(:id)
domains = domain_contacts.map(&:domain).flatten +
Domain.where(registrant_id: registrant_ids)
domains.each { |domain| process_force_delete(domain) unless domain.force_delete_scheduled? }
end
private
def process_force_delete(domain)
domain.schedule_force_delete(type: :soft,
notify_by_email: true,
reason: 'invalid_email',
email: email)
end
end
end
end