Refactor domain transfer controller

This commit is contained in:
Martin Lensment 2015-03-10 17:17:29 +02:00
parent b91f9b1a8e
commit d056d370be
3 changed files with 42 additions and 25 deletions

View file

@ -58,32 +58,13 @@ class Epp::DomainsController < EppController
authorize! :transfer, @domain, @password
action = params[:parsed_frame].css('transfer').first[:op]
if action == 'query'
if @domain.pending_transfer
@domain_transfer = @domain.pending_transfer
else
@domain_transfer = @domain.query_transfer(params[:parsed_frame], current_user)
handle_errors(@domain) and return unless @domain_transfer
end
elsif action == 'approve'
if @domain.pending_transfer
@domain_transfer = @domain.approve_transfer(params[:parsed_frame], current_user)
handle_errors(@domain) and return unless @domain_transfer
else
epp_errors << { code: '2303', msg: I18n.t('pending_transfer_was_not_found') }
handle_errors(@domain) and return
end
elsif action == 'reject'
if @domain.pending_transfer
@domain_transfer = @domain.reject_transfer(params[:parsed_frame], current_user)
handle_errors(@domain) and return unless @domain_transfer
else
epp_errors << { code: '2303', msg: I18n.t('pending_transfer_was_not_found') }
handle_errors(@domain) and return
end
end
@domain_transfer = @domain.transfer(params[:parsed_frame], action, current_user)
render_epp_response '/epp/domains/transfer'
if @domain.errors.empty? && @domain_transfer
render_epp_response '/epp/domains/transfer'
else
handle_errors(@domain)
end
end
# rubocop: enable Metrics/MethodLength

View file

@ -385,6 +385,23 @@ class Epp::Domain < Domain
### TRANSFER ###
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity
def transfer(frame, action, current_user)
case action
when 'query'
return pending_transfer if pending_transfer
return query_transfer(frame, current_user)
when 'approve'
return approve_transfer(frame, current_user) if pending_transfer
when 'reject'
return reject_transfer(frame, current_user) if pending_transfer
end
add_epp_error('2303', nil, nil, I18n.t('pending_transfer_was_not_found'))
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/MethodLength
def query_transfer(frame, current_user)
return false unless can_be_transferred_to?(current_user.registrar)

View file

@ -1046,6 +1046,25 @@ describe 'EPP Domain', epp: true do
end
end
it 'should get an error when there is no pending transfer ' do
pw = domain.auth_info
xml = domain_transfer_xml({
name: { value: domain.name },
authInfo: { pw: { value: pw } }
}, 'approve', {
_anonymus: [
legalDocument: {
value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==',
attrs: { type: 'pdf' }
}
]
})
response = epp_plain_request(xml, :xml)
response[:msg].should == 'Pending transfer was not found'
response[:result_code].should == '2303'
end
### UPDATE ###
it 'updates a domain' do
existing_pw = Domain.last.auth_info