From b6e61f5bdacb29295b16f43c88d633536f16fe33 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Wed, 6 Aug 2014 14:44:34 +0300 Subject: [PATCH] Refactor --- app/controllers/concerns/epp/common.rb | 6 +++--- app/helpers/epp/contacts_helper.rb | 17 +++++++---------- app/helpers/epp/domains_helper.rb | 13 +------------ 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/app/controllers/concerns/epp/common.rb b/app/controllers/concerns/epp/common.rb index 8baced6e9..a1d92b61d 100644 --- a/app/controllers/concerns/epp/common.rb +++ b/app/controllers/concerns/epp/common.rb @@ -36,12 +36,12 @@ module Epp::Common obj.errors.each do |key, msg| if msg.is_a?(Hash) epp_errors << { - code: find_code(msg[:msg]), + code: find_code(error_code_map, msg[:msg]), msg: msg[:msg], value: {obj: msg[:obj], val: msg[:val]}, } else - next unless code = find_code(msg) + next unless code = find_code(error_code_map, msg) epp_errors << { code: code, msg: msg @@ -50,7 +50,7 @@ module Epp::Common end end - def find_code(msg) + def find_code(error_code_map, msg) error_code_map.each do |code, values| return code if values.include?(msg) end diff --git a/app/helpers/epp/contacts_helper.rb b/app/helpers/epp/contacts_helper.rb index 3dbc7c280..e987425e7 100644 --- a/app/helpers/epp/contacts_helper.rb +++ b/app/helpers/epp/contacts_helper.rb @@ -1,6 +1,6 @@ module Epp::ContactsHelper def create_contact - @contact = Contact.new( contact_and_address_attributes ) + @contact = Contact.new( contact_and_address_attributes ) stamp @contact if @contact.save render '/epp/contacts/create' @@ -40,11 +40,11 @@ module Epp::ContactsHelper def info_contact #TODO do we reject contact without authInfo or display less info? - #TODO add data missing from contacts/info builder ( marked with 'if false' in said view ) + #TODO add data missing from contacts/info builder ( marked with 'if false' in said view ) current_epp_user ph = params_hash['epp']['command']['info']['info'] - @contact = Contact.where(code: ph[:id]).first + @contact = Contact.where(code: ph[:id]).first case has_rights when true render 'epp/contacts/info' @@ -67,7 +67,7 @@ module Epp::ContactsHelper ident: ph[:ident], ident_type: ident_type, email: ph[:email], - name: ph[:postalInfo][:name], + name: ph[:postalInfo][:name], org_name: ph[:postalInfo][:org], address_attributes: { country_id: Country.find_by(iso: ph[:postalInfo][:addr][:cc]), @@ -85,7 +85,7 @@ module Epp::ContactsHelper end def tidy_street - street = params_hash['epp']['command']['create']['create'][:postalInfo][:addr][:street] + street = params_hash['epp']['command']['create']['create'][:postalInfo][:addr][:street] return street if street.is_a? String return street.join(',') if street.is_a? Array return nil @@ -102,11 +102,8 @@ module Epp::ContactsHelper def handle_contact_errors # handle_errors conflicted with domain logic handle_epp_errors({ - '2302' => [:epp_id_taken], + '2302' => ['Contact id already exists'], '2303' => [:not_found, :epp_obj_does_not_exist] - }, @contact - ) + },@contact) end - - end diff --git a/app/helpers/epp/domains_helper.rb b/app/helpers/epp/domains_helper.rb index 187990af5..248acd103 100644 --- a/app/helpers/epp/domains_helper.rb +++ b/app/helpers/epp/domains_helper.rb @@ -60,21 +60,10 @@ module Epp::DomainsHelper def handle_errors handle_epp_errors({ - '2302' => [:epp_domain_taken, :reserved], - '2306' => [:blank, [:out_of_range, {min: 1, max: 13}]], - '2303' => [:not_found], - '2005' => [:hostname_invalid, :ip_invalid] - }, @domain - ) - end - - def error_code_map - { '2302' => ['Domain name already exists', 'Domain name is reserved or restricted'], '2306' => ['Registrant is missing', 'Nameservers count must be between 1-13', 'Admin contact is missing'], '2303' => ['Contact was not found'], '2005' => ['Hostname is invalid', 'IP is invalid'] - } + }, @domain) end - end