diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 280ee4ef6..04f2e9c14 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -413,6 +413,8 @@ class Epp::Domain < Domain end def transfer_owner_contact(registrar_id) + return if owner_contact.registrar_id == registrar_id + is_other_domains_contact = DomainContact.where('contact_id = ? AND domain_id != ?', owner_contact_id, id).count > 0 if owner_contact.domains_owned.count > 1 || is_other_domains_contact # copy contact @@ -429,15 +431,13 @@ class Epp::Domain < Domain oc.generate_code oc.registrar_id = registrar_id oc.save! - - self.owner_contact = oc end end def transfer_domain_contacts(registrar_id) copied_ids = [] contacts.each do |c| - next if copied_ids.include?(c.id) + next if copied_ids.include?(c.id) || c.registrar_id == registrar_id is_other_domains_contact = DomainContact.where('contact_id = ? AND domain_id != ?', c.id, id).count > 0 # if contact used to be owner contact but was copied, then contact must be transferred diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 952cbf867..92de4757c 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -1105,6 +1105,41 @@ describe 'EPP Domain', epp: true do domain.domain_contacts.where(contact_id: domain.owner_contact_id).count.should == 1 end + it 'does not transfer contacts if they are already under new registrar' do + domain.contacts.each do |c| + c.registrar_id = @registrar2.id + c.save + end + + domain.owner_contact.registrar_id = @registrar2.id + domain.owner_contact.save + + original_oc_id = domain.owner_contact_id + original_oc_code = domain.owner_contact.code + original_contacts_codes = domain.contacts.pluck(:code) + + 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 + + domain.reload + + domain.owner_contact.id.should == original_oc_id + domain.owner_contact.code.should == original_oc_code + domain.owner_contact.registrar_id.should == @registrar2.id + + original_contacts_codes.should == domain.contacts.pluck(:code) + + end + it 'should not creates transfer without password' do xml = domain_transfer_xml({ name: { value: domain.name }