mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 13:15:40 +02:00
REPP: Fix bulk domain transfer
This commit is contained in:
parent
e9c0d09b9f
commit
03d940a695
3 changed files with 91 additions and 32 deletions
|
@ -33,37 +33,16 @@ module Repp
|
|||
initiate_transfer(transfer)
|
||||
end
|
||||
|
||||
if @errors.any?
|
||||
render_epp_error(:bad_request, @errors)
|
||||
else
|
||||
render_success(data: @successful)
|
||||
end
|
||||
render_success(data: {success: @successful, failed: @errors})
|
||||
end
|
||||
|
||||
def initiate_transfer(transfer)
|
||||
domain = transferable_domain(transfer[:domain_name], transfer[:transfer_code])
|
||||
return unless domain
|
||||
domain = Epp::Domain.find_or_initialize_by(name: transfer[:domain_name])
|
||||
action = Actions::DomainTransfer.new(domain, transfer[:transfer_code], current_user.registrar)
|
||||
|
||||
DomainTransfer.request(domain, current_user.registrar)
|
||||
@successful << { type: 'domain_transfer', attributes: { domain_name: domain.name } }
|
||||
end
|
||||
@successful << { type: 'domain_transfer', domain_name: domain.name } and return if action.call
|
||||
|
||||
def transferable_domain(domain_name, transfer_code)
|
||||
domain = Domain.find_by(name: domain_name)
|
||||
# rubocop:disable Style/AndOr
|
||||
add_error("#{domain_name} does not exist") and return unless domain
|
||||
# rubocop:enable Style/AndOr
|
||||
unless domain.transfer_code.eql?(transfer_code)
|
||||
add_error("#{domain_name} transfer code is wrong")
|
||||
return
|
||||
end
|
||||
|
||||
domain
|
||||
end
|
||||
|
||||
def add_error(msg)
|
||||
@errors ||= []
|
||||
@errors << { title: msg }
|
||||
@errors << { type: 'domain_transfer', domain_name: domain.name, errors: domain.errors[:epp_errors] }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
77
app/models/actions/domain_transfer.rb
Normal file
77
app/models/actions/domain_transfer.rb
Normal file
|
@ -0,0 +1,77 @@
|
|||
module Actions
|
||||
class DomainTransfer
|
||||
attr_reader :domain
|
||||
attr_reader :transfer_code
|
||||
attr_reader :legal_document
|
||||
attr_reader :ident
|
||||
attr_reader :user
|
||||
|
||||
def initialize(domain, transfer_code, user)
|
||||
@domain = domain
|
||||
@transfer_code = transfer_code
|
||||
@user = user
|
||||
end
|
||||
|
||||
def call
|
||||
return unless domain_exists?
|
||||
return unless run_validations
|
||||
|
||||
#return domain.pending_transfer if domain.pending_transfer
|
||||
#attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||
|
||||
return if domain.errors[:epp_errors].any?
|
||||
|
||||
commit
|
||||
end
|
||||
|
||||
def domain_exists?
|
||||
return true if domain.persisted?
|
||||
|
||||
domain.add_epp_error('2303', nil, nil, 'Object does not exist')
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
def run_validations
|
||||
return unless validate_transfer_code
|
||||
return unless validate_registrar
|
||||
return unless validate_eligilibty
|
||||
return unless validate_not_discarded
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def validate_transfer_code
|
||||
return true if transfer_code == domain.transfer_code
|
||||
|
||||
domain.add_epp_error('2202', nil, nil, 'Invalid authorization information')
|
||||
false
|
||||
end
|
||||
|
||||
def validate_registrar
|
||||
return true unless user == domain.registrar
|
||||
|
||||
domain.add_epp_error('2002', nil, nil, I18n.t(:domain_already_belongs_to_the_querying_registrar))
|
||||
false
|
||||
end
|
||||
|
||||
def validate_eligilibty
|
||||
return true unless domain.non_transferable?
|
||||
|
||||
domain.add_epp_error('2304', nil, nil, 'Domain is not transferable??')
|
||||
false
|
||||
end
|
||||
|
||||
def validate_not_discarded
|
||||
return true unless domain.discarded?
|
||||
|
||||
domain.add_epp_error('2106', nil, nil, 'Object is not eligible for transfer')
|
||||
false
|
||||
end
|
||||
|
||||
def commit
|
||||
bare_domain = Domain.find(domain.id)
|
||||
::DomainTransfer.request(bare_domain, user)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -25,8 +25,11 @@ class ReppV1DomainsTransferTest < ActionDispatch::IntegrationTest
|
|||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
assert_equal @domain.name, json[:data][0][:attributes][:domain_name]
|
||||
assert_equal 'domain_transfer', json[:data][0][:type]
|
||||
assert_equal @domain.name, json[:data][:success][0][:domain_name]
|
||||
|
||||
@domain.reload
|
||||
|
||||
assert @domain.registrar = @user.registrar
|
||||
end
|
||||
|
||||
def test_does_not_transfer_domain_with_invalid_auth_code
|
||||
|
@ -40,10 +43,10 @@ class ReppV1DomainsTransferTest < ActionDispatch::IntegrationTest
|
|||
post "/repp/v1/domains/transfer", headers: @auth_headers, params: payload
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :bad_request
|
||||
assert_equal 2304, json[:code]
|
||||
assert_equal 'Command failed', json[:message]
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
assert_equal "#{@domain.name} transfer code is wrong", json[:data][0][:title]
|
||||
assert_equal "Invalid authorization information", json[:data][:failed][0][:errors][0][:msg]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue