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
@errors += obj.errors[:epp_errors]
end
# for debugging
@errors << {code: '1', msg: 'handle_errors was executed when there were actually no errors'} if @errors.blank?
render '/epp/error'
end

View file

@ -3,7 +3,7 @@ module Epp::DomainsHelper
Domain.transaction do
@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
render '/epp/domains/success'
@ -38,8 +38,10 @@ module Epp::DomainsHelper
@domain = find_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.detach_objects(@ph, parsed_frame.css('rem'))
handle_errors(@domain) and return unless @domain.parse_and_attach_domain_dependencies(@ph, parsed_frame.css('add'))
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
render '/epp/domains/success'

View file

@ -51,7 +51,7 @@ class Domain < ActiveRecord::Base
### 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_contacts(self.class.parse_contacts_from_frame(parsed_frame))
attach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
@ -60,7 +60,7 @@ class Domain < ActiveRecord::Base
errors.empty?
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_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
detach_statuses(self.class.parse_statuses_from_frame(parsed_frame))
@ -68,6 +68,19 @@ class Domain < ActiveRecord::Base
errors.empty?
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)
self.owner_contact = Contact.find_by(code: code)
@ -324,6 +337,15 @@ class Domain < ActiveRecord::Base
res
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)
domains = [domains] if domains.is_a?(String)