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
|
channel: eslint-5
|
||||||
fixme:
|
fixme:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
checks:
|
||||||
|
TODO:
|
||||||
|
enabled: false
|
||||||
rubocop:
|
rubocop:
|
||||||
enabled: true
|
enabled: true
|
||||||
channel: rubocop-0-74
|
channel: rubocop-0-74
|
||||||
|
|
|
@ -12,11 +12,18 @@ module DomainUpdateConfirmInteraction
|
||||||
RegistrantVerification::REJECTED] }
|
RegistrantVerification::REJECTED] }
|
||||||
|
|
||||||
def raise_errors!(domain)
|
def raise_errors!(domain)
|
||||||
if domain.errors.any?
|
return unless domain.errors.any?
|
||||||
message = "domain #{domain.name} failed with errors #{domain.errors.full_messages}"
|
|
||||||
throw message
|
message = "domain #{domain.name} failed with errors #{domain.errors.full_messages}"
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,17 +4,49 @@ module DomainUpdateConfirmInteraction
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
domain.is_admin = true
|
domain.is_admin = true
|
||||||
old_registrant = domain.registrant
|
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!
|
apply_pending_update!
|
||||||
raise_errors!(domain)
|
|
||||||
|
|
||||||
domain.clean_pendings!
|
|
||||||
raise_errors!(domain)
|
raise_errors!(domain)
|
||||||
RegistrantChange.new(domain: domain, old_registrant: old_registrant).confirm
|
RegistrantChange.new(domain: domain, old_registrant: old_registrant).confirm
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ module DomainUpdateConfirmInteraction
|
||||||
registrar: domain.registrar,
|
registrar: domain.registrar,
|
||||||
registrant: domain.registrant).deliver_now
|
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.preclean_pendings
|
||||||
domain.clean_pendings!
|
domain.clean_pendings!
|
||||||
|
|
|
@ -327,6 +327,7 @@ class Domain < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_registrar(message_key)
|
def notify_registrar(message_key)
|
||||||
|
# TODO: To be deleted with DomainDeleteConfirm refactoring
|
||||||
registrar.notifications.create!(
|
registrar.notifications.create!(
|
||||||
text: "#{I18n.t(message_key)}: #{name}",
|
text: "#{I18n.t(message_key)}: #{name}",
|
||||||
attached_obj_id: id,
|
attached_obj_id: id,
|
||||||
|
@ -335,11 +336,13 @@ class Domain < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def preclean_pendings
|
def preclean_pendings
|
||||||
|
# TODO: To be deleted with refactoring
|
||||||
self.registrant_verification_token = nil
|
self.registrant_verification_token = nil
|
||||||
self.registrant_verification_asked_at = nil
|
self.registrant_verification_asked_at = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_pendings!
|
def clean_pendings!
|
||||||
|
# TODO: To be deleted with refactoring
|
||||||
preclean_pendings
|
preclean_pendings
|
||||||
self.pending_json = {}
|
self.pending_json = {}
|
||||||
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
||||||
|
|
|
@ -508,25 +508,6 @@ class Epp::Domain < Domain
|
||||||
errors.empty? && super(at)
|
errors.empty? && super(at)
|
||||||
end
|
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!
|
def apply_pending_delete!
|
||||||
preclean_pendings
|
preclean_pendings
|
||||||
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue