mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 20:18:22 +02:00
Move functionality from job to interactor
This commit is contained in:
parent
31bfe19d77
commit
4b7cffbb57
5 changed files with 77 additions and 32 deletions
22
app/interactions/domain_update_confirm_interaction/base.rb
Normal file
22
app/interactions/domain_update_confirm_interaction/base.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
module DomainUpdateConfirmInteraction
|
||||||
|
class Base < ActiveInteraction::Base
|
||||||
|
object :domain,
|
||||||
|
class: Domain,
|
||||||
|
description: 'Domain to confirm update'
|
||||||
|
string :action
|
||||||
|
string :initiator,
|
||||||
|
default: nil
|
||||||
|
|
||||||
|
validates :domain, :action, presence: true
|
||||||
|
validates :action, inclusion: { in: [RegistrantVerification::CONFIRMED,
|
||||||
|
RegistrantVerification::REJECTED] }
|
||||||
|
|
||||||
|
def raise_errors!(domain)
|
||||||
|
if domain.errors.any?
|
||||||
|
message = "domain #{domain.name} failed with errors #{domain.errors.full_messages}"
|
||||||
|
throw message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
module DomainUpdateConfirmInteraction
|
||||||
|
class ProcessAction < Base
|
||||||
|
def execute
|
||||||
|
::PaperTrail.request.whodunnit = "interaction - #{self.class.name} - #{action} by"\
|
||||||
|
" #{initiator}"
|
||||||
|
|
||||||
|
case action
|
||||||
|
when RegistrantVerification::CONFIRMED
|
||||||
|
compose(ProcessUpdateConfirmed, inputs)
|
||||||
|
when RegistrantVerification::REJECTED
|
||||||
|
compose(ProcessUpdateRejected, inputs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,20 @@
|
||||||
|
module DomainUpdateConfirmInteraction
|
||||||
|
class ProcessUpdateConfirmed < Base
|
||||||
|
def execute
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
domain.is_admin = true
|
||||||
|
old_registrant = domain.registrant
|
||||||
|
domain.notify_registrar(:poll_pending_update_confirmed_by_registrant)
|
||||||
|
|
||||||
|
domain.apply_pending_update!
|
||||||
|
raise_errors!(domain)
|
||||||
|
|
||||||
|
domain.clean_pendings!
|
||||||
|
raise_errors!(domain)
|
||||||
|
RegistrantChange.new(domain: domain, old_registrant: old_registrant).confirm
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,16 @@
|
||||||
|
module DomainUpdateConfirmInteraction
|
||||||
|
class ProcessUpdateRejected < Base
|
||||||
|
def execute
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
RegistrantChangeMailer.rejected(domain: domain,
|
||||||
|
registrar: domain.registrar,
|
||||||
|
registrant: domain.registrant).deliver_now
|
||||||
|
|
||||||
|
domain.notify_registrar(:poll_pending_update_rejected_by_registrant)
|
||||||
|
|
||||||
|
domain.preclean_pendings
|
||||||
|
domain.clean_pendings!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,37 +2,9 @@ class DomainUpdateConfirmJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as :default
|
||||||
|
|
||||||
def perform(domain_id, action, initiator = nil)
|
def perform(domain_id, action, initiator = nil)
|
||||||
::PaperTrail.request.whodunnit = "job - #{self.class.name} - #{action} by #{initiator}"
|
domain = Epp::Domain.find(domain_id)
|
||||||
# it's recommended to keep transaction against job table as short as possible.
|
DomainUpdateConfirmInteraction::ProcessAction.run(domain: domain,
|
||||||
ActiveRecord::Base.transaction do
|
action: action,
|
||||||
domain = Epp::Domain.find(domain_id)
|
initiator: initiator)
|
||||||
domain.is_admin = true
|
|
||||||
case action
|
|
||||||
when RegistrantVerification::CONFIRMED
|
|
||||||
old_registrant = domain.registrant
|
|
||||||
domain.notify_registrar(:poll_pending_update_confirmed_by_registrant)
|
|
||||||
raise_errors!(domain)
|
|
||||||
|
|
||||||
domain.apply_pending_update!
|
|
||||||
raise_errors!(domain)
|
|
||||||
|
|
||||||
domain.clean_pendings!
|
|
||||||
raise_errors!(domain)
|
|
||||||
RegistrantChange.new(domain: domain, old_registrant: old_registrant).confirm
|
|
||||||
when RegistrantVerification::REJECTED
|
|
||||||
RegistrantChangeMailer.rejected(domain: domain,
|
|
||||||
registrar: domain.registrar,
|
|
||||||
registrant: domain.registrant).deliver_now
|
|
||||||
|
|
||||||
domain.notify_registrar(:poll_pending_update_rejected_by_registrant)
|
|
||||||
|
|
||||||
domain.preclean_pendings
|
|
||||||
domain.clean_pendings!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def raise_errors!(domain)
|
|
||||||
throw "domain #{domain.name} failed with errors #{domain.errors.full_messages}" if domain.errors.any?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue