mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
parent
cbccb6b497
commit
51243c5983
6 changed files with 79 additions and 25 deletions
13
app/models/concerns/contact/transferable.rb
Normal file
13
app/models/concerns/contact/transferable.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
module Concerns::Contact::Transferable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def transfer(new_registrar)
|
||||
new_contact = self.dup
|
||||
new_contact.registrar = new_registrar
|
||||
new_contact.generate_code
|
||||
new_contact.original = self
|
||||
new_contact.remove_address unless self.class.address_processing?
|
||||
new_contact.save!
|
||||
new_contact
|
||||
end
|
||||
end
|
|
@ -17,7 +17,7 @@ module Concerns::Domain::Transferable
|
|||
transfer_to: new_registrar
|
||||
)
|
||||
|
||||
transfer_contacts(new_registrar.id)
|
||||
transfer_contacts(new_registrar)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -26,25 +26,25 @@ module Concerns::Domain::Transferable
|
|||
self.transfer_code = SecureRandom.hex
|
||||
end
|
||||
|
||||
def transfer_contacts(registrar_id)
|
||||
transfer_registrant(registrar_id)
|
||||
transfer_domain_contacts(registrar_id)
|
||||
def transfer_contacts(new_registrar)
|
||||
transfer_registrant(new_registrar)
|
||||
transfer_domain_contacts(new_registrar)
|
||||
end
|
||||
|
||||
def transfer_registrant(registrar_id)
|
||||
return if registrant.registrar_id == registrar_id
|
||||
self.registrant_id = copy_and_transfer_contact(registrant_id, registrar_id).id
|
||||
def transfer_registrant(new_registrar)
|
||||
return if registrant.registrar == new_registrar
|
||||
self.registrant = registrant.transfer(new_registrar)
|
||||
end
|
||||
|
||||
def transfer_domain_contacts(registrar_id)
|
||||
def transfer_domain_contacts(new_registrar)
|
||||
copied_ids = []
|
||||
contacts.each do |c|
|
||||
next if copied_ids.include?(c.id) || c.registrar_id == registrar_id
|
||||
next if copied_ids.include?(c.id) || c.registrar == new_registrar
|
||||
|
||||
if registrant_id_was == c.id # registrant was copied previously, do not copy it again
|
||||
oc = OpenStruct.new(id: registrant_id)
|
||||
else
|
||||
oc = copy_and_transfer_contact(c.id, registrar_id)
|
||||
oc = c.transfer(new_registrar)
|
||||
end
|
||||
|
||||
domain_contacts.where(contact_id: c.id).update_all({ contact_id: oc.id }) # n+1 workaround
|
||||
|
@ -52,17 +52,5 @@ module Concerns::Domain::Transferable
|
|||
end
|
||||
end
|
||||
|
||||
def copy_and_transfer_contact(contact_id, registrar_id)
|
||||
c = Contact.find(contact_id) # n+1 workaround
|
||||
oc = c.deep_clone
|
||||
oc.code = nil
|
||||
oc.registrar_id = registrar_id
|
||||
oc.original = c
|
||||
oc.generate_code
|
||||
oc.remove_address unless Contact.address_processing?
|
||||
oc.save!(validate: false)
|
||||
oc
|
||||
end
|
||||
|
||||
alias_method :regenerate_transfer_code, :generate_transfer_code
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@ class Contact < ActiveRecord::Base
|
|||
include Versions # version/contact_version.rb
|
||||
include EppErrors
|
||||
include UserEvents
|
||||
include Concerns::Contact::Transferable
|
||||
|
||||
belongs_to :original, class_name: self.name
|
||||
belongs_to :registrar, required: true
|
||||
|
|
|
@ -679,7 +679,7 @@ class Epp::Domain < Domain
|
|||
end
|
||||
|
||||
if dt.approved?
|
||||
transfer_contacts(current_user.registrar_id)
|
||||
transfer_contacts(current_user.registrar)
|
||||
dt.notify_losing_registrar(old_contact_codes, old_registrant_code)
|
||||
regenerate_transfer_code
|
||||
self.registrar = current_user.registrar
|
||||
|
@ -709,7 +709,7 @@ class Epp::Domain < Domain
|
|||
transferred_at: Time.zone.now
|
||||
)
|
||||
|
||||
transfer_contacts(pt.transfer_to_id)
|
||||
transfer_contacts(pt.transfer_to)
|
||||
regenerate_transfer_code
|
||||
self.registrar = pt.transfer_to
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue