REPP: Specific domain transfer action

This commit is contained in:
Karl Erik Õunapuu 2021-01-22 12:18:17 +02:00
parent 1d9850fb98
commit 06088e33c5
No known key found for this signature in database
GPG key ID: C9DD647298A34764
4 changed files with 45 additions and 7 deletions

View file

@ -0,0 +1,38 @@
module Repp
module V1
module Domains
class TransfersController < BaseController
before_action :set_domain, only: [:create]
api :POST, 'repp/v1/domains/:domain_name/transfer'
desc 'Transfer a specific domain'
param :transfer, Hash, required: true, desc: 'Renew parameters' do
param :transfer_code, String, required: true, desc: 'Renew period. Month (m) or year (y)'
end
def create
action = Actions::DomainTransfer.new(@domain, transfer_params[:transfer][:transfer_code],
current_user.registrar)
unless action.call
handle_errors(@domain)
return
end
render_success(data: { domain: { name: @domain.name, type: 'domain_transfer' } })
end
private
def set_domain
h = {}
h[transfer_params[:domain_id].match?(/\A[0-9]+\z/) ? :id : :name] = transfer_params[:domain_id]
@domain = Epp::Domain.find_by!(h)
end
def transfer_params
params.permit!
end
end
end
end
end

View file

@ -99,8 +99,8 @@ module Repp
render_success(data: data)
end
api :POST, '/repp/v1/domains/:domain_name/transfer'
desc 'Transfer specific domain'
api :POST, '/repp/v1/domains/transfer'
desc 'Transfer multiple domains'
def transfer
@errors ||= []
@successful = []
@ -112,8 +112,6 @@ module Repp
render_success(data: { success: @successful, failed: @errors })
end
private
def initiate_transfer(transfer)
domain = Epp::Domain.find_or_initialize_by(name: transfer[:domain_name])
action = Actions::DomainTransfer.new(domain, transfer[:transfer_code],
@ -127,6 +125,8 @@ module Repp
end
end
private
def transfer_params
params.require(:data).require(:domain_transfers).each do |t|
t.require(:domain_name)

View file

@ -11,10 +11,9 @@ module Domains
def execute
return domain_pricelist.price.amount if domain_pricelist.try(:price)
errors.add(:domain, I18n.t(:active_price_missing_for_operation_with_domain,
domain: domain.name))
domain.add_epp_error(2104, nil, nil, I18n.t(:active_price_missing_for_this_operation))
errors.add(:domain, I18n.t(:active_price_missing_for_operation_with_domain,
domain: domain.name))
false
end

View file

@ -64,6 +64,7 @@ Rails.application.routes.draw do
resources :dnssec, only: %i[index create], constraints: { id: /.*/ }, controller: 'domains/dnssec'
resources :contacts, only: %i[index create], constraints: { id: /.*/ }, controller: 'domains/contacts'
resources :renew, only: %i[create], constraints: { id: /.*/ }, controller: 'domains/renews'
resources :transfer, only: %i[create], constraints: { id: /.*/ }, controller: 'domains/transfers'
match "dnssec", to: "domains/dnssec#destroy", via: "delete", defaults: { id: nil }
match "contacts", to: "domains/contacts#destroy", via: "delete", defaults: { id: nil }
collection do