mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 01:36:02 +02:00
Move apply_pending_update! method from model to interactor
This commit is contained in:
parent
4b7cffbb57
commit
8ef748fc7d
6 changed files with 56 additions and 30 deletions
|
@ -20,6 +20,9 @@ plugins:
|
|||
channel: eslint-5
|
||||
fixme:
|
||||
enabled: true
|
||||
checks:
|
||||
TODO:
|
||||
enabled: false
|
||||
rubocop:
|
||||
enabled: true
|
||||
channel: rubocop-0-74
|
||||
|
|
|
@ -12,11 +12,18 @@ module DomainUpdateConfirmInteraction
|
|||
RegistrantVerification::REJECTED] }
|
||||
|
||||
def raise_errors!(domain)
|
||||
if domain.errors.any?
|
||||
message = "domain #{domain.name} failed with errors #{domain.errors.full_messages}"
|
||||
throw message
|
||||
end
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,17 +4,49 @@ module DomainUpdateConfirmInteraction
|
|||
ActiveRecord::Base.transaction do
|
||||
domain.is_admin = true
|
||||
old_registrant = domain.registrant
|
||||
domain.notify_registrar(:poll_pending_update_confirmed_by_registrant)
|
||||
notify_registrar(:poll_pending_update_confirmed_by_registrant)
|
||||
|
||||
domain.apply_pending_update!
|
||||
raise_errors!(domain)
|
||||
|
||||
domain.clean_pendings!
|
||||
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
|
||||
|
||||
def preclean_pendings
|
||||
domain.registrant_verification_token = nil
|
||||
domain.registrant_verification_asked_at = nil
|
||||
end
|
||||
|
||||
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.update(frame, user, false)
|
||||
end
|
||||
|
||||
def clean_pendings!
|
||||
domain.up_date = Time.zone.now
|
||||
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
|
||||
|
|
|
@ -6,7 +6,7 @@ module DomainUpdateConfirmInteraction
|
|||
registrar: domain.registrar,
|
||||
registrant: domain.registrant).deliver_now
|
||||
|
||||
domain.notify_registrar(:poll_pending_update_rejected_by_registrant)
|
||||
notify_registrar(:poll_pending_update_rejected_by_registrant)
|
||||
|
||||
domain.preclean_pendings
|
||||
domain.clean_pendings!
|
||||
|
|
|
@ -327,6 +327,7 @@ class Domain < ApplicationRecord
|
|||
end
|
||||
|
||||
def notify_registrar(message_key)
|
||||
# TODO: To be deleted with DomainDeleteConfirm refactoring
|
||||
registrar.notifications.create!(
|
||||
text: "#{I18n.t(message_key)}: #{name}",
|
||||
attached_obj_id: id,
|
||||
|
@ -335,11 +336,13 @@ class Domain < ApplicationRecord
|
|||
end
|
||||
|
||||
def preclean_pendings
|
||||
# TODO: To be deleted with refactoring
|
||||
self.registrant_verification_token = nil
|
||||
self.registrant_verification_asked_at = nil
|
||||
end
|
||||
|
||||
def clean_pendings!
|
||||
# TODO: To be deleted with refactoring
|
||||
preclean_pendings
|
||||
self.pending_json = {}
|
||||
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
||||
|
|
|
@ -508,25 +508,6 @@ class Epp::Domain < Domain
|
|||
errors.empty? && super(at)
|
||||
end
|
||||
|
||||
def apply_pending_update!
|
||||
preclean_pendings
|
||||
user = ApiUser.find(pending_json['current_user_id'])
|
||||
frame = Nokogiri::XML(pending_json['frame'])
|
||||
|
||||
self.statuses.delete(DomainStatus::PENDING_UPDATE)
|
||||
self.upid = user.registrar.id if user.registrar
|
||||
self.up_date = Time.zone.now
|
||||
|
||||
return unless update(frame, user, false)
|
||||
clean_pendings!
|
||||
|
||||
save!
|
||||
|
||||
WhoisRecord.find_by(domain_id: id).save # need to reload model
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def apply_pending_delete!
|
||||
preclean_pendings
|
||||
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue