diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index ba90f23f2..f69f33dd1 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -1,7 +1,9 @@ +require 'serializers/registrant_api/domain' module Repp module V1 class DomainsController < BaseController - before_action :set_authorized_domain, only: [:transfer_info] + before_action :set_authorized_domain, only: %i[transfer_info] + before_action :set_domain, only: %i[show] def index records = current_user.registrar.domains @@ -11,6 +13,10 @@ module Repp render_success(data: { domains: domains, total_number_of_records: records.count }) end + def show + render_success(data: { domain: Serializers::RegistrantApi::Domain.new(@domain).to_json }) + end + def transfer_info contact_fields = %i[code name ident ident_type ident_country_code phone email street city zip country_code statuses] @@ -66,12 +72,16 @@ module Repp params.permit(:id) end + def set_domain + @domain = Domain.find_by(registrar: current_user.registrar, name: params[:id]) + end + def set_authorized_domain @epp_errors ||= [] h = {} h[transfer_info_params[:id].match?(/\A[0-9]+\z/) ? :id : :name] = transfer_info_params[:id] @domain = Domain.find_by!(h) - + return if @domain.registrar == current_user.registrar return if @domain.transfer_code.eql?(request.headers['Auth-Code']) @epp_errors << { code: 2202, msg: I18n.t('errors.messages.epp_authorization_error') } diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index c46732712..d56fe4e32 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -1,5 +1,5 @@ require 'deserializers/xml/legal_document' - +require 'deserializers/xml/nameserver' class Epp::Domain < Domain include EppErrors @@ -161,7 +161,7 @@ class Epp::Domain < Domain at[:nameservers_attributes] = nameservers_attrs(frame, action) at[:admin_domain_contacts_attributes] = admin_domain_contacts_attrs(frame, action) at[:tech_domain_contacts_attributes] = tech_domain_contacts_attrs(frame, action) - + puts "JHDFHJDGFKDJHF" pw = frame.css('authInfo > pw').text at[:transfer_code] = pw if pw.present? @@ -193,7 +193,7 @@ class Epp::Domain < Domain end def nameservers_attrs(frame, action) - ns_list = nameservers_from(frame) + ns_list = ::Deserializers::Xml::Nameservers.new(frame).call if action == 'rem' to_destroy = [] @@ -215,21 +215,6 @@ class Epp::Domain < Domain end end - def nameservers_from(frame) - res = [] - frame.css('hostAttr').each do |x| - host_attr = { - hostname: x.css('hostName').first.try(:text), - ipv4: x.css('hostAddr[ip="v4"]').map(&:text).compact, - ipv6: x.css('hostAddr[ip="v6"]').map(&:text).compact - } - - res << host_attr.delete_if { |_k, v| v.blank? } - end - - res - end - def admin_domain_contacts_attrs(frame, action) admin_attrs = domain_contact_attrs_from(frame, action, 'admin') diff --git a/config/routes.rb b/config/routes.rb index 0af3d95c9..e2e5bccd5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -59,7 +59,7 @@ Rails.application.routes.draw do end end end - resources :domains do + resources :domains, constraints: { id: /.*/ } do collection do get ':id/transfer_info', to: 'domains#transfer_info', constraints: { id: /.*/ } post 'transfer', to: 'domains#transfer' diff --git a/lib/deserializers/xml/nameserver.rb b/lib/deserializers/xml/nameserver.rb new file mode 100644 index 000000000..f43407d68 --- /dev/null +++ b/lib/deserializers/xml/nameserver.rb @@ -0,0 +1,37 @@ +module Deserializers + module Xml + class Nameserver + attr_reader :frame + + def initialize(frame) + @frame = frame + end + + def call + { + hostname: frame.css('hostName').text, + ipv4: frame.css('hostAddr[ip="v4"]').map(&:text).compact, + ipv6: frame.css('hostAddr[ip="v6"]').map(&:text).compact + } + end + end + + class Nameservers + attr_reader :frame + + def initialize(frame) + @frame = frame + end + + def call + res = [] + frame.css('hostAttr').each do |ns| + ns = Deserializers::Xml::Nameserver.new(ns).call + res << ns.delete_if { |_k, v| v.blank? } + end + + res + end + end + end +end