mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 10:49:39 +02:00
Nameserver removing with domain update request
This commit is contained in:
parent
c0d25ccedf
commit
87cc7799be
9 changed files with 87 additions and 16 deletions
|
@ -39,6 +39,7 @@ module Epp::DomainsHelper
|
|||
|
||||
handle_errors(@domain) and return unless @domain
|
||||
handle_errors(@domain) and return unless @domain.attach_objects(@ph, parsed_frame.css('add'))
|
||||
handle_errors(@domain) and return unless @domain.detach_objects(@ph, parsed_frame.css('rem'))
|
||||
handle_errors(@domain) and return unless @domain.save
|
||||
|
||||
render '/epp/domains/success'
|
||||
|
|
|
@ -49,7 +49,7 @@ class Domain < ActiveRecord::Base
|
|||
write_attribute(:name_dirty, value)
|
||||
end
|
||||
|
||||
### CREATE ###
|
||||
### CREATE & UPDATE ###
|
||||
|
||||
def attach_objects(ph, parsed_frame)
|
||||
attach_owner_contact(ph[:registrant]) if ph[:registrant]
|
||||
|
@ -60,6 +60,10 @@ class Domain < ActiveRecord::Base
|
|||
errors.empty?
|
||||
end
|
||||
|
||||
def detach_objects(ph, parsed_frame)
|
||||
detach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
|
||||
end
|
||||
|
||||
def attach_owner_contact(code)
|
||||
self.owner_contact = Contact.find_by(code: code)
|
||||
|
||||
|
@ -116,6 +120,15 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def detach_nameservers(ns_list)
|
||||
to_delete = []
|
||||
ns_list.each do |ns_attrs|
|
||||
to_delete << self.nameservers.where(ns_attrs)
|
||||
end
|
||||
|
||||
self.nameservers.delete(to_delete)
|
||||
end
|
||||
|
||||
### RENEW ###
|
||||
|
||||
def renew(cur_exp_date, period, unit='y')
|
||||
|
@ -255,7 +268,6 @@ class Domain < ActiveRecord::Base
|
|||
description: x.text
|
||||
}
|
||||
end
|
||||
|
||||
res
|
||||
end
|
||||
|
||||
|
@ -275,7 +287,7 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
if Domain.find_by(name: x)
|
||||
res << {name: x, avail: 0, reason: 'in use'} #confirm reason with current API
|
||||
res << {name: x, avail: 0, reason: 'in use'}
|
||||
else
|
||||
res << {name: x, avail: 1}
|
||||
end
|
||||
|
|
|
@ -13,10 +13,6 @@ class DomainStatus < ActiveRecord::Base
|
|||
|
||||
validates :setting, uniqueness: { scope: :domain_id }
|
||||
|
||||
def setting_uniqueness
|
||||
|
||||
end
|
||||
|
||||
def epp_code_map
|
||||
{
|
||||
'2302' => [[:setting, :taken]]
|
||||
|
|
|
@ -70,6 +70,8 @@ en:
|
|||
attributes:
|
||||
setting:
|
||||
taken: 'Status already exists on this domain'
|
||||
value:
|
||||
taken: 'Status already exists on this domain'
|
||||
attributes:
|
||||
domain:
|
||||
name: 'Domain name'
|
||||
|
|
|
@ -245,34 +245,51 @@ describe 'EPP Domain', epp: true do
|
|||
expect(response[:results][0][:msg]).to eq('Domain not found')
|
||||
end
|
||||
|
||||
it 'updates domain' do
|
||||
response = epp_request('domains/update.xml')
|
||||
it 'updates domain and adds objects' do
|
||||
response = epp_request('domains/update_add_objects.xml')
|
||||
expect(response[:results][0][:result_code]).to eq('2303')
|
||||
expect(response[:results][0][:msg]).to eq('Contact was not found')
|
||||
|
||||
Fabricate(:contact, code: 'mak21')
|
||||
|
||||
response = epp_request('domains/update.xml')
|
||||
response = epp_request('domains/update_add_objects.xml')
|
||||
expect(response[:results][0][:result_code]).to eq('1000')
|
||||
|
||||
d = Domain.first
|
||||
|
||||
new_ns = d.nameservers.find_by(hostname: 'ns2.example.com')
|
||||
expect(new_ns).to be_truthy
|
||||
new_ns_count = d.nameservers.where(hostname: ['ns1.example.com', 'ns2.example.com']).count
|
||||
expect(new_ns_count).to eq(2)
|
||||
|
||||
new_contact = d.tech_contacts.find_by(code: 'mak21')
|
||||
expect(new_contact).to be_truthy
|
||||
|
||||
expect(d.domain_statuses.count).to eq(1)
|
||||
expect(d.domain_statuses.count).to eq(2)
|
||||
expect(d.domain_statuses.first.description).to eq('Payment overdue.')
|
||||
expect(d.domain_statuses.first.value).to eq('clientHold')
|
||||
expect(d.domain_statuses.first.code).to eq('client_hold')
|
||||
|
||||
response = epp_request('domains/update.xml')
|
||||
expect(d.domain_statuses.last.value).to eq('clientUpdateProhibited')
|
||||
|
||||
response = epp_request('domains/update_add_objects.xml')
|
||||
|
||||
expect(response[:results][0][:result_code]).to eq('2302')
|
||||
expect(response[:results][0][:msg]).to eq('Status already exists on this domain')
|
||||
expect(d.domain_statuses.count).to eq(1)
|
||||
expect(d.domain_statuses.count).to eq(2)
|
||||
end
|
||||
|
||||
it 'updates a domain and removes objects' do
|
||||
Fabricate(:contact, code: 'mak21')
|
||||
epp_request('domains/update_add_objects.xml')
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<domain:name>example.ee</domain:name>
|
||||
<domain:add>
|
||||
<domain:ns>
|
||||
<domain:hostObj>ns1.example.com</domain:hostObj>
|
||||
<domain:hostObj>ns2.example.com</domain:hostObj>
|
||||
</domain:ns>
|
||||
<domain:contact type="tech">mak21</domain:contact>
|
||||
|
|
22
spec/epp/requests/domains/update_add_objects.xml
Normal file
22
spec/epp/requests/domains/update_add_objects.xml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<update>
|
||||
<domain:update
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.ee</domain:name>
|
||||
<domain:add>
|
||||
<domain:ns>
|
||||
<domain:hostObj>ns1.example.com</domain:hostObj>
|
||||
<domain:hostObj>ns2.example.com</domain:hostObj>
|
||||
</domain:ns>
|
||||
<domain:contact type="tech">mak21</domain:contact>
|
||||
<domain:status s="clientHold"
|
||||
lang="en">Payment overdue.</domain:status>
|
||||
<domain:status s="clientUpdateProhibited"/>
|
||||
</domain:add>
|
||||
</domain:update>
|
||||
</update>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
19
spec/epp/requests/domains/update_remove_objects.xml
Normal file
19
spec/epp/requests/domains/update_remove_objects.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<update>
|
||||
<domain:update
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.ee</domain:name>
|
||||
<domain:rem>
|
||||
<domain:ns>
|
||||
<domain:hostObj>ns1.example.com</domain:hostObj>
|
||||
</domain:ns>
|
||||
<domain:contact type="tech">sh8013</domain:contact>
|
||||
<domain:status s="clientHold"/>
|
||||
</domain:rem>
|
||||
</domain:update>
|
||||
</update>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -17,6 +17,7 @@ end
|
|||
Fabricator(:domain_statuses_setting_group, from: :setting_group) do
|
||||
code 'domain_statuses'
|
||||
settings { [
|
||||
Fabricate(:setting, code: 'client_hold', value: 'clientHold')
|
||||
Fabricate(:setting, code: 'client_hold', value: 'clientHold'),
|
||||
Fabricate(:setting, code: 'client_update_prohibited', value: 'clientUpdateProhibited')
|
||||
]}
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue