mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Move interactor to the Domains namespace
This commit is contained in:
parent
6f0b8b15a3
commit
42012863e2
9 changed files with 125 additions and 117 deletions
|
@ -1,49 +0,0 @@
|
||||||
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)
|
|
||||||
return unless domain.errors.any?
|
|
||||||
|
|
||||||
message = "domain #{domain.name} failed with errors #{domain.errors.full_messages}"
|
|
||||||
throw message
|
|
||||||
end
|
|
||||||
|
|
||||||
def notify_registrar(message_key)
|
|
||||||
domain.registrar.notifications.create!(
|
|
||||||
text: "#{I18n.t(message_key)}: #{domain.name}",
|
|
||||||
attached_obj_id: domain.id,
|
|
||||||
attached_obj_type: domain.class.to_s
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def preclean_pendings
|
|
||||||
domain.registrant_verification_token = nil
|
|
||||||
domain.registrant_verification_asked_at = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def clean_pendings!
|
|
||||||
domain.registrant_verification_token = nil
|
|
||||||
domain.registrant_verification_asked_at = nil
|
|
||||||
domain.pending_json = {}
|
|
||||||
clear_statuses
|
|
||||||
end
|
|
||||||
|
|
||||||
def clear_statuses
|
|
||||||
domain.statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
|
||||||
domain.statuses.delete(DomainStatus::PENDING_UPDATE)
|
|
||||||
domain.statuses.delete(DomainStatus::PENDING_DELETE)
|
|
||||||
domain.status_notes[DomainStatus::PENDING_UPDATE] = ''
|
|
||||||
domain.status_notes[DomainStatus::PENDING_DELETE] = ''
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,15 +0,0 @@
|
||||||
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
|
|
|
@ -1,34 +0,0 @@
|
||||||
module DomainUpdateConfirmInteraction
|
|
||||||
class ProcessUpdateConfirmed < Base
|
|
||||||
def execute
|
|
||||||
ActiveRecord::Base.transaction do
|
|
||||||
domain.is_admin = true
|
|
||||||
old_registrant = domain.registrant
|
|
||||||
notify_registrar(:poll_pending_update_confirmed_by_registrant)
|
|
||||||
|
|
||||||
apply_pending_update!
|
|
||||||
raise_errors!(domain)
|
|
||||||
RegistrantChange.new(domain: domain, old_registrant: old_registrant).confirm
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def apply_pending_update!
|
|
||||||
preclean_pendings
|
|
||||||
update_domain
|
|
||||||
clean_pendings!
|
|
||||||
domain.save!
|
|
||||||
|
|
||||||
WhoisRecord.find_by(domain_id: domain.id).save # need to reload model
|
|
||||||
end
|
|
||||||
|
|
||||||
# rubocop:disable Metrics/AbcSize
|
|
||||||
def update_domain
|
|
||||||
user = ApiUser.find(domain.pending_json['current_user_id'])
|
|
||||||
frame = Nokogiri::XML(domain.pending_json['frame'])
|
|
||||||
domain.upid = user.registrar.id if user.registrar
|
|
||||||
domain.up_date = Time.zone.now
|
|
||||||
domain.update(frame, user, false)
|
|
||||||
end
|
|
||||||
# rubocop:enable Metrics/AbcSize
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,16 +0,0 @@
|
||||||
module DomainUpdateConfirmInteraction
|
|
||||||
class ProcessUpdateRejected < Base
|
|
||||||
def execute
|
|
||||||
ActiveRecord::Base.transaction do
|
|
||||||
RegistrantChangeMailer.rejected(domain: domain,
|
|
||||||
registrar: domain.registrar,
|
|
||||||
registrant: domain.registrant).deliver_now
|
|
||||||
|
|
||||||
notify_registrar(:poll_pending_update_rejected_by_registrant)
|
|
||||||
|
|
||||||
preclean_pendings
|
|
||||||
clean_pendings!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
51
app/interactions/domains/update_confirm/base.rb
Normal file
51
app/interactions/domains/update_confirm/base.rb
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
module Domains
|
||||||
|
module UpdateConfirm
|
||||||
|
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)
|
||||||
|
return unless domain.errors.any?
|
||||||
|
|
||||||
|
message = "domain #{domain.name} failed with errors #{domain.errors.full_messages}"
|
||||||
|
throw message
|
||||||
|
end
|
||||||
|
|
||||||
|
def notify_registrar(message_key)
|
||||||
|
domain.registrar.notifications.create!(
|
||||||
|
text: "#{I18n.t(message_key)}: #{domain.name}",
|
||||||
|
attached_obj_id: domain.id,
|
||||||
|
attached_obj_type: domain.class.to_s
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def preclean_pendings
|
||||||
|
domain.registrant_verification_token = nil
|
||||||
|
domain.registrant_verification_asked_at = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def clean_pendings!
|
||||||
|
domain.registrant_verification_token = nil
|
||||||
|
domain.registrant_verification_asked_at = nil
|
||||||
|
domain.pending_json = {}
|
||||||
|
clear_statuses
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_statuses
|
||||||
|
domain.statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
||||||
|
domain.statuses.delete(DomainStatus::PENDING_UPDATE)
|
||||||
|
domain.statuses.delete(DomainStatus::PENDING_DELETE)
|
||||||
|
domain.status_notes[DomainStatus::PENDING_UPDATE] = ''
|
||||||
|
domain.status_notes[DomainStatus::PENDING_DELETE] = ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
17
app/interactions/domains/update_confirm/process_action.rb
Normal file
17
app/interactions/domains/update_confirm/process_action.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
module Domains
|
||||||
|
module UpdateConfirm
|
||||||
|
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
|
||||||
|
end
|
|
@ -0,0 +1,36 @@
|
||||||
|
module Domains
|
||||||
|
module UpdateConfirm
|
||||||
|
class ProcessUpdateConfirmed < Base
|
||||||
|
def execute
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
domain.is_admin = true
|
||||||
|
old_registrant = domain.registrant
|
||||||
|
notify_registrar(:poll_pending_update_confirmed_by_registrant)
|
||||||
|
|
||||||
|
apply_pending_update!
|
||||||
|
raise_errors!(domain)
|
||||||
|
RegistrantChange.new(domain: domain, old_registrant: old_registrant).confirm
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def apply_pending_update!
|
||||||
|
preclean_pendings
|
||||||
|
update_domain
|
||||||
|
clean_pendings!
|
||||||
|
domain.save!
|
||||||
|
|
||||||
|
WhoisRecord.find_by(domain_id: domain.id).save # need to reload model
|
||||||
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/AbcSize
|
||||||
|
def update_domain
|
||||||
|
user = ApiUser.find(domain.pending_json['current_user_id'])
|
||||||
|
frame = Nokogiri::XML(domain.pending_json['frame'])
|
||||||
|
domain.upid = user.registrar.id if user.registrar
|
||||||
|
domain.up_date = Time.zone.now
|
||||||
|
domain.update(frame, user, false)
|
||||||
|
end
|
||||||
|
# rubocop:enable Metrics/AbcSize
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,18 @@
|
||||||
|
module Domains
|
||||||
|
module UpdateConfirm
|
||||||
|
class ProcessUpdateRejected < Base
|
||||||
|
def execute
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
RegistrantChangeMailer.rejected(domain: domain,
|
||||||
|
registrar: domain.registrar,
|
||||||
|
registrant: domain.registrant).deliver_now
|
||||||
|
|
||||||
|
notify_registrar(:poll_pending_update_rejected_by_registrant)
|
||||||
|
|
||||||
|
preclean_pendings
|
||||||
|
clean_pendings!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,8 +3,8 @@ class DomainUpdateConfirmJob < ApplicationJob
|
||||||
|
|
||||||
def perform(domain_id, action, initiator = nil)
|
def perform(domain_id, action, initiator = nil)
|
||||||
domain = Epp::Domain.find(domain_id)
|
domain = Epp::Domain.find(domain_id)
|
||||||
DomainUpdateConfirmInteraction::ProcessAction.run(domain: domain,
|
Domains::UpdateConfirm::ProcessAction.run(domain: domain,
|
||||||
action: action,
|
action: action,
|
||||||
initiator: initiator)
|
initiator: initiator)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue