From 06088e33c5a3a46c9820f681711450fba200e8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Fri, 22 Jan 2021 12:18:17 +0200 Subject: [PATCH] REPP: Specific domain transfer action --- .../repp/v1/domains/transfers_controller.rb | 38 +++++++++++++++++++ app/controllers/repp/v1/domains_controller.rb | 8 ++-- .../domains/check_balance/single_domain.rb | 5 +-- config/routes.rb | 1 + 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 app/controllers/repp/v1/domains/transfers_controller.rb diff --git a/app/controllers/repp/v1/domains/transfers_controller.rb b/app/controllers/repp/v1/domains/transfers_controller.rb new file mode 100644 index 000000000..be1f754c2 --- /dev/null +++ b/app/controllers/repp/v1/domains/transfers_controller.rb @@ -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 diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index 06849fb7f..a63f40402 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -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) diff --git a/app/interactions/domains/check_balance/single_domain.rb b/app/interactions/domains/check_balance/single_domain.rb index 365b69d6c..de8f24d18 100644 --- a/app/interactions/domains/check_balance/single_domain.rb +++ b/app/interactions/domains/check_balance/single_domain.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 32d5b83fb..0bd0da82e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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