Nameserver deserializer

This commit is contained in:
Karl Erik Õunapuu 2020-11-25 15:45:43 +02:00
parent b39de0885a
commit 7459d7e0c5
No known key found for this signature in database
GPG key ID: C9DD647298A34764
4 changed files with 53 additions and 21 deletions

View file

@ -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') }