From d4063349264a9ac3c5d19b4b1af3c6fdd1fe7465 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 25 Nov 2020 14:26:53 +0500 Subject: [PATCH] Move DomainDelete to interactor design pattern --- .../domain_delete_interaction/base.rb | 7 +++++++ .../domain_delete_interaction/delete.rb | 11 ++++++++++ .../nofity_registrar.rb | 12 +++++++++++ app/jobs/domain_delete_job.rb | 21 ++++++++++--------- 4 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 app/interactions/domain_delete_interaction/base.rb create mode 100644 app/interactions/domain_delete_interaction/delete.rb create mode 100644 app/interactions/domain_delete_interaction/nofity_registrar.rb diff --git a/app/interactions/domain_delete_interaction/base.rb b/app/interactions/domain_delete_interaction/base.rb new file mode 100644 index 000000000..b2895e1d1 --- /dev/null +++ b/app/interactions/domain_delete_interaction/base.rb @@ -0,0 +1,7 @@ +module DomainDeleteInteraction + class Base < ActiveInteraction::Base + object :domain, + class: Domain, + description: 'Domain to delete' + end +end diff --git a/app/interactions/domain_delete_interaction/delete.rb b/app/interactions/domain_delete_interaction/delete.rb new file mode 100644 index 000000000..181431ca1 --- /dev/null +++ b/app/interactions/domain_delete_interaction/delete.rb @@ -0,0 +1,11 @@ +module DomainDeleteInteraction + class Delete < :Base + def execute + ::PaperTrail.request.whodunnit = "interaction - #{self.class.name}" + WhoisRecord.where(domain_id: domain.id).destroy_all + + domain.destroy + compose(NotifyRegistrar, inputs) + end + end +end diff --git a/app/interactions/domain_delete_interaction/nofity_registrar.rb b/app/interactions/domain_delete_interaction/nofity_registrar.rb new file mode 100644 index 000000000..81a66e6b0 --- /dev/null +++ b/app/interactions/domain_delete_interaction/nofity_registrar.rb @@ -0,0 +1,12 @@ +module DomainDeleteInteraction + class NotifyRegistrar < Delete + def execute + bye_bye = domain.versions.last + domain.registrar.notifications.create!( + text: "#{I18n.t(:domain_deleted)}: #{domain.name}", + attached_obj_id: bye_bye.id, + attached_obj_type: bye_bye.class.to_s + ) + end + end +end diff --git a/app/jobs/domain_delete_job.rb b/app/jobs/domain_delete_job.rb index 43e0bb844..a41a27f05 100644 --- a/app/jobs/domain_delete_job.rb +++ b/app/jobs/domain_delete_job.rb @@ -3,15 +3,16 @@ class DomainDeleteJob < Que::Job def run(domain_id) domain = Domain.find(domain_id) - ::PaperTrail.request.whodunnit = "job - #{self.class.name}" - WhoisRecord.where(domain_id: domain.id).destroy_all - - domain.destroy - bye_bye = domain.versions.last - domain.registrar.notifications.create!( - text: "#{I18n.t(:domain_deleted)}: #{domain.name}", - attached_obj_id: bye_bye.id, - attached_obj_type: bye_bye.class.to_s - ) + DomainDeleteInteraction::Delete.run(domain: domain) + # ::PaperTrail.request.whodunnit = "job - #{self.class.name}" + # WhoisRecord.where(domain_id: domain.id).destroy_all + # + # domain.destroy + # bye_bye = domain.versions.last + # domain.registrar.notifications.create!( + # text: "#{I18n.t(:domain_deleted)}: #{domain.name}", + # attached_obj_id: bye_bye.id, + # attached_obj_type: bye_bye.class.to_s + # ) end end