Better naming and domain updating

This commit is contained in:
Martin Lensment 2014-08-25 11:18:54 +03:00
parent fe54f327d9
commit 8b8a71c4d1
6 changed files with 50 additions and 22 deletions

View file

@ -42,6 +42,9 @@ module Epp::Common
obj.construct_epp_errors obj.construct_epp_errors
@errors += obj.errors[:epp_errors] @errors += obj.errors[:epp_errors]
end end
# for debugging
@errors << {code: '1', msg: 'handle_errors was executed when there were actually no errors'} if @errors.blank?
render '/epp/error' render '/epp/error'
end end

View file

@ -3,7 +3,7 @@ module Epp::DomainsHelper
Domain.transaction do Domain.transaction do
@domain = Domain.new(domain_create_params) @domain = Domain.new(domain_create_params)
handle_errors(@domain) and return unless @domain.attach_objects(@ph, parsed_frame) handle_errors(@domain) and return unless @domain.parse_and_attach_domain_dependencies(@ph, parsed_frame)
handle_errors(@domain) and return unless @domain.save handle_errors(@domain) and return unless @domain.save
render '/epp/domains/success' render '/epp/domains/success'
@ -38,8 +38,10 @@ module Epp::DomainsHelper
@domain = find_domain @domain = find_domain
handle_errors(@domain) and return unless @domain 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.parse_and_attach_domain_dependencies(@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.parse_and_detach_domain_dependencies(parsed_frame.css('rem'))
handle_errors(@domain) and return unless @domain.parse_and_update_domain_dependencies(parsed_frame.css('chg'))
handle_errors(@domain) and return unless @domain.parse_and_update_domain_attributes(parsed_frame.css('chg'))
handle_errors(@domain) and return unless @domain.save handle_errors(@domain) and return unless @domain.save
render '/epp/domains/success' render '/epp/domains/success'

View file

@ -51,7 +51,7 @@ class Domain < ActiveRecord::Base
### CREATE & UPDATE ### ### CREATE & UPDATE ###
def attach_objects(ph, parsed_frame) def parse_and_attach_domain_dependencies(ph, parsed_frame)
attach_owner_contact(ph[:registrant]) if ph[:registrant] attach_owner_contact(ph[:registrant]) if ph[:registrant]
attach_contacts(self.class.parse_contacts_from_frame(parsed_frame)) attach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
attach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame)) attach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
@ -60,7 +60,7 @@ class Domain < ActiveRecord::Base
errors.empty? errors.empty?
end end
def detach_objects(ph, parsed_frame) def parse_and_detach_domain_dependencies(parsed_frame)
detach_contacts(self.class.parse_contacts_from_frame(parsed_frame)) detach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
detach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame)) detach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
detach_statuses(self.class.parse_statuses_from_frame(parsed_frame)) detach_statuses(self.class.parse_statuses_from_frame(parsed_frame))
@ -68,6 +68,19 @@ class Domain < ActiveRecord::Base
errors.empty? errors.empty?
end end
def parse_and_update_domain_dependencies(parsed_frame)
owner_contact_code = parsed_frame.css('registrant').try(:text)
attach_owner_contact(owner_contact_code) if owner_contact_code.present?
errors.empty?
end
def parse_and_update_domain_attributes(parsed_frame)
assign_attributes(self.class.parse_update_params_from_frame(parsed_frame))
errors.empty?
end
def attach_owner_contact(code) def attach_owner_contact(code)
self.owner_contact = Contact.find_by(code: code) self.owner_contact = Contact.find_by(code: code)
@ -324,6 +337,15 @@ class Domain < ActiveRecord::Base
res res
end end
def parse_update_params_from_frame(parsed_frame)
ret = {}
return ret if parsed_frame.blank?
ret[:auth_info] = parsed_frame.css('pw').try(:text)
ret.compact
end
def check_availability(domains) def check_availability(domains)
domains = [domains] if domains.is_a?(String) domains = [domains] if domains.is_a?(String)

View file

@ -309,7 +309,19 @@ describe 'EPP Domain', epp: true do
expect(response[:results][2][:result_code]).to eq('2303') expect(response[:results][2][:result_code]).to eq('2303')
expect(response[:results][2][:msg]).to eq('Status was not found') expect(response[:results][2][:msg]).to eq('Status was not found')
expect(response[:results][2][:value]).to eq('clientHold') expect(response[:results][2][:value]).to eq('clientHold')
end
it 'updates a domain' do
Fabricate(:contact, code: 'mak21')
epp_request('domains/update_add_objects.xml')
response = epp_request('domains/update.xml')
expect(response[:results][0][:result_code]).to eq('1000')
d = Domain.last
expect(d.owner_contact_code).to eq('mak21')
expect(d.auth_info).to eq('2BARfoo')
end end
end end

View file

@ -5,24 +5,8 @@
<domain:update <domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name> <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:add>
<domain:rem>
<domain:ns>
<domain:hostObj>ns1.example.com</domain:hostObj>
</domain:ns>
<domain:contact type="tech">sh8013</domain:contact>
<domain:status s="clientUpdateProhibited"/>
</domain:rem>
<domain:chg> <domain:chg>
<domain:registrant>sh8013</domain:registrant> <domain:registrant>mak21</domain:registrant>
<domain:authInfo> <domain:authInfo>
<domain:pw>2BARfoo</domain:pw> <domain:pw>2BARfoo</domain:pw>
</domain:authInfo> </domain:authInfo>

View file

@ -42,6 +42,11 @@ module Epp
obj obj
end end
#print output
def po(r)
puts r[:parsed].to_s
end
### REQUEST TEMPLATES ### ### REQUEST TEMPLATES ###
def domain_create_xml(xml_params={}) def domain_create_xml(xml_params={})