mirror of
https://github.com/internetee/registry.git
synced 2025-08-12 12:39:34 +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,15 +15,15 @@ class Contact < ActiveRecord::Base
|
||||||
|
|
||||||
validates :name, :phone, :email, :ident, :address, :registrar, :ident_type, presence: true
|
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 :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/
|
||||||
validates :email, format: /@/
|
validates :email, format: /@/
|
||||||
validates :ident,
|
validates :ident,
|
||||||
format: { with: /\d{4}-\d{2}-\d{2}/, message: :invalid_birthday_format },
|
format: { with: /\d{4}-\d{2}-\d{2}/, message: :invalid_birthday_format },
|
||||||
if: proc { |c| c.ident_type == 'birthday' }
|
if: proc { |c| c.ident_type == 'birthday' }
|
||||||
validates :ident_country_code, presence: true, if: proc { |c| %w(bic priv).include? c.ident_type }
|
validates :ident_country_code, presence: true, if: proc { |c| %w(bic priv).include? c.ident_type }
|
||||||
validates :code,
|
validates :code,
|
||||||
uniqueness: { message: :epp_id_taken },
|
uniqueness: { message: :epp_id_taken },
|
||||||
format: { with: /\A[\w\-\:]*\Z/i },
|
format: { with: /\A[\w\-\:]*\Z/i },
|
||||||
length: { maximum: 100 }
|
length: { maximum: 100 }
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ class Contact < ActiveRecord::Base
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: refactor, it should not allow to destroy with normal destroy,
|
# TODO: refactor, it should not allow to destroy with normal destroy,
|
||||||
# no need separate method
|
# no need separate method
|
||||||
# should use only in transaction
|
# should use only in transaction
|
||||||
def destroy_and_clean
|
def destroy_and_clean
|
||||||
|
@ -157,7 +157,7 @@ class Contact < ActiveRecord::Base
|
||||||
return true unless ident_country_code_changed? && ident_country_code.present?
|
return true unless ident_country_code_changed? && ident_country_code.present?
|
||||||
code = Country.new(ident_country_code)
|
code = Country.new(ident_country_code)
|
||||||
if code
|
if code
|
||||||
self.ident_country_code = code.alpha2
|
self.ident_country_code = code.alpha2
|
||||||
else
|
else
|
||||||
errors.add(:ident_country_code, 'is not following ISO_3166-1 alpha 2 format')
|
errors.add(:ident_country_code, 'is not following ISO_3166-1 alpha 2 format')
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,6 +20,8 @@ class Domain < ActiveRecord::Base
|
||||||
-> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) },
|
-> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) },
|
||||||
through: :domain_contacts, source: :contact
|
through: :domain_contacts, source: :contact
|
||||||
|
|
||||||
|
has_many :contacts, through: :domain_contacts, source: :contact
|
||||||
|
|
||||||
has_many :nameservers, dependent: :delete_all
|
has_many :nameservers, dependent: :delete_all
|
||||||
|
|
||||||
accepts_nested_attributes_for :nameservers, allow_destroy: true,
|
accepts_nested_attributes_for :nameservers, allow_destroy: true,
|
||||||
|
|
|
@ -51,16 +51,4 @@ class DomainTransfer < ActiveRecord::Base
|
||||||
domain.save(validate: false)
|
domain.save(validate: false)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -399,6 +399,28 @@ class Epp::Domain < Domain
|
||||||
end
|
end
|
||||||
add_epp_error('2303', nil, nil, I18n.t('pending_transfer_was_not_found'))
|
add_epp_error('2303', nil, nil, I18n.t('pending_transfer_was_not_found'))
|
||||||
end
|
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/PerceivedComplexity
|
||||||
# rubocop: enable Metrics/CyclomaticComplexity
|
# rubocop: enable Metrics/CyclomaticComplexity
|
||||||
|
|
||||||
|
@ -423,6 +445,7 @@ class Epp::Domain < Domain
|
||||||
end
|
end
|
||||||
|
|
||||||
if dt.approved?
|
if dt.approved?
|
||||||
|
transfer_contacts(current_user)
|
||||||
generate_auth_info
|
generate_auth_info
|
||||||
self.registrar = current_user.registrar
|
self.registrar = current_user.registrar
|
||||||
end
|
end
|
||||||
|
|
|
@ -870,6 +870,60 @@ describe 'EPP Domain', epp: true do
|
||||||
end
|
end
|
||||||
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
|
it 'should not creates transfer without password' do
|
||||||
xml = domain_transfer_xml({
|
xml = domain_transfer_xml({
|
||||||
name: { value: domain.name }
|
name: { value: domain.name }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue