mirror of
https://github.com/internetee/registry.git
synced 2025-08-12 04:29:33 +02:00
Contact transfer with domain transfer WIP
This commit is contained in:
parent
5cb4b35e0f
commit
568121ddd0
5 changed files with 85 additions and 18 deletions
|
@ -15,7 +15,7 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
validates :name, :phone, :email, :ident, :address, :registrar, :ident_type, presence: true
|
||||
|
||||
# Phone nr validation is very minimam in order to support legacy requirements
|
||||
# # Phone nr validation is very minimam in order to support legacy requirements
|
||||
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/
|
||||
validates :email, format: /@/
|
||||
validates :ident,
|
||||
|
|
|
@ -20,6 +20,8 @@ class Domain < ActiveRecord::Base
|
|||
-> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) },
|
||||
through: :domain_contacts, source: :contact
|
||||
|
||||
has_many :contacts, through: :domain_contacts, source: :contact
|
||||
|
||||
has_many :nameservers, dependent: :delete_all
|
||||
|
||||
accepts_nested_attributes_for :nameservers, allow_destroy: true,
|
||||
|
|
|
@ -51,16 +51,4 @@ class DomainTransfer < ActiveRecord::Base
|
|||
domain.save(validate: false)
|
||||
end
|
||||
end
|
||||
|
||||
def approve_as_server
|
||||
transaction do
|
||||
self.status = DomainTransfer::SERVER_APPROVED
|
||||
self.transferred_at = Time.zone.now
|
||||
save
|
||||
|
||||
domain.generate_auth_info
|
||||
domain.registrar = transfer_to
|
||||
domain.save(validate: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -399,6 +399,28 @@ class Epp::Domain < Domain
|
|||
end
|
||||
add_epp_error('2303', nil, nil, I18n.t('pending_transfer_was_not_found'))
|
||||
end
|
||||
|
||||
def transfer_contacts(current_user)
|
||||
if owner_contact.domains.count > 1
|
||||
# create new
|
||||
else
|
||||
# transfer contact
|
||||
# TODO: This is a workaround so Bullet won't complain about n+1 query
|
||||
# The problem appears in automatic status callback when doing normal save!
|
||||
owner_contact.update_column(:registrar_id, current_user.registrar_id)
|
||||
end
|
||||
|
||||
domain_contacts.includes(:contact).each do |dc|
|
||||
c = dc.contact
|
||||
if c.domains.count > 1
|
||||
# create new contact
|
||||
else
|
||||
# transfer contact
|
||||
c.registrar_id = current_user.registrar_id
|
||||
c.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
|
||||
|
@ -423,6 +445,7 @@ class Epp::Domain < Domain
|
|||
end
|
||||
|
||||
if dt.approved?
|
||||
transfer_contacts(current_user)
|
||||
generate_auth_info
|
||||
self.registrar = current_user.registrar
|
||||
end
|
||||
|
|
|
@ -870,6 +870,60 @@ describe 'EPP Domain', epp: true do
|
|||
end
|
||||
end
|
||||
|
||||
it 'transfers domain with contacts' do
|
||||
original_oc_id = domain.owner_contact.id
|
||||
|
||||
pw = domain.auth_info
|
||||
xml = domain_transfer_xml({
|
||||
name: { value: domain.name },
|
||||
authInfo: { pw: { value: pw } }
|
||||
})
|
||||
|
||||
login_as :registrar2 do
|
||||
response = epp_plain_request(xml, :xml)
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
end
|
||||
|
||||
# all domain contacts should be under registrar2 now
|
||||
domain.owner_contact.reload
|
||||
domain.owner_contact.registrar_id.should == @registrar2.id
|
||||
domain.owner_contact.id.should == original_oc_id
|
||||
|
||||
domain.contacts.pluck(:registrar_id).each do |reg_id|
|
||||
reg_id.should == @registrar2.id
|
||||
end
|
||||
|
||||
#
|
||||
end
|
||||
|
||||
it 'transfers domain by creating new contacts' do
|
||||
Fabricate(:domain, owner_contact: domain.owner_contact)
|
||||
original_oc_id = domain.owner_contact.id
|
||||
|
||||
pw = domain.auth_info
|
||||
xml = domain_transfer_xml({
|
||||
name: { value: domain.name },
|
||||
authInfo: { pw: { value: pw } }
|
||||
})
|
||||
|
||||
login_as :registrar2 do
|
||||
response = epp_plain_request(xml, :xml)
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
end
|
||||
|
||||
# all domain contacts should be under registrar2 now
|
||||
domain.owner_contact.reload
|
||||
domain.owner_contact.registrar_id.should == @registrar2.id
|
||||
# owner_contact should be a new record
|
||||
domain.owner_contact.id.should_not == original_oc_id
|
||||
|
||||
domain.contacts.pluck(:registrar_id).each do |reg_id|
|
||||
reg_id.should == @registrar2.id
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not creates transfer without password' do
|
||||
xml = domain_transfer_xml({
|
||||
name: { value: domain.name }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue