Contact removing on domain update, displaying errors

This commit is contained in:
Martin Lensment 2014-08-22 12:59:48 +03:00
parent a7de74eb82
commit 755bfc9a24
4 changed files with 50 additions and 6 deletions

View file

@ -61,7 +61,10 @@ class Domain < ActiveRecord::Base
end
def detach_objects(ph, parsed_frame)
detach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
detach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
errors.empty?
end
def attach_owner_contact(code)
@ -120,10 +123,39 @@ class Domain < ActiveRecord::Base
end
end
def detach_contacts(contact_list)
to_delete = []
contact_list.each do |k, v|
v.each do |x|
contact = domain_contacts.joins(:contact).where(contacts: {code: x[:contact]})
if contact.blank?
errors.add(:domain_contacts, {
obj: 'contact',
val: x[:contact],
msg: errors.generate_message(:domain_contacts, :not_found)
})
else
to_delete << contact
end
end
end
self.domain_contacts.delete(to_delete)
end
def detach_nameservers(ns_list)
to_delete = []
ns_list.each do |ns_attrs|
to_delete << self.nameservers.where(ns_attrs)
nameserver = self.nameservers.where(ns_attrs)
if nameserver.blank?
errors.add(:nameservers, {
obj: 'hostObj',
val: ns_attrs[:hostname],
msg: errors.generate_message(:nameservers, :not_found)
})
else
to_delete << nameserver
end
end
self.nameservers.delete(to_delete)
@ -199,7 +231,8 @@ class Domain < ActiveRecord::Base
],
'2303' => [ # Object does not exist
[:owner_contact, :epp_registrant_not_found],
[:domain_contacts, :not_found]
[:domain_contacts, :not_found],
[:nameservers, :not_found]
],
'2200' => [
[:auth_info, :wrong_pw]

View file

@ -50,6 +50,7 @@ en:
blank: 'Admin contact is missing'
nameservers:
out_of_range: 'Nameservers count must be between %{min}-%{max}'
not_found: 'Nameserver was not found'
period:
out_of_range: 'Period must add up to 1, 2 or 3 years'
auth_info:

View file

@ -285,13 +285,23 @@ describe 'EPP Domain', epp: true do
d = Domain.last
new_ns = d.nameservers.find_by(hostname: 'ns1.example.com')
expect(new_ns).to be_truthy
response = epp_request('domains/update_remove_objects.xml')
rem_ns = d.nameservers.find_by(hostname: 'ns1.example.com')
expect(rem_ns).to be_falsey
rem_cnt = d.tech_contacts.find_by(code: 'mak21')
expect(rem_cnt).to be_falsey
response = epp_request('domains/update_remove_objects.xml')
expect(response[:results][0][:result_code]).to eq('2303')
expect(response[:results][0][:msg]).to eq('Contact was not found')
expect(response[:results][0][:value]).to eq('mak21')
expect(response[:results][1][:result_code]).to eq('2303')
expect(response[:results][1][:msg]).to eq('Nameserver was not found')
expect(response[:results][1][:value]).to eq('ns1.example.com')
end
end

View file

@ -9,7 +9,7 @@
<domain:ns>
<domain:hostObj>ns1.example.com</domain:hostObj>
</domain:ns>
<domain:contact type="tech">sh8013</domain:contact>
<domain:contact type="tech">mak21</domain:contact>
<domain:status s="clientHold"/>
</domain:rem>
</domain:update>