Remove manual rescues from transfer code #2588

This commit is contained in:
Martin Lensment 2015-07-21 14:43:42 +03:00
parent 812381056c
commit 91da0d30f0
3 changed files with 52 additions and 64 deletions

View file

@ -130,10 +130,14 @@ class Epp::DomainsController < EppController
@domain_transfer = @domain.transfer(params[:parsed_frame], action, current_user)
if @domain.errors.empty? && @domain_transfer
if @domain_transfer
render_epp_response '/epp/domains/transfer'
else
handle_errors(@domain)
epp_errors << {
code: '2303',
msg: I18n.t('no_transfers_found')
}
handle_errors
end
end

View file

@ -473,7 +473,6 @@ class Epp::Domain < Domain
when 'reject'
return reject_transfer(frame, current_user) if pending_transfer
end
add_epp_error('2303', nil, nil, I18n.t('no_transfers_found'))
end
# TODO: Eager load problems here. Investigate how it's possible not to query contact again
@ -536,50 +535,48 @@ class Epp::Domain < Domain
end
end
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/MethodLength
# rubocop: disable Metrics/AbcSize
def query_transfer(frame, current_user)
return false unless can_be_transferred_to?(current_user.registrar)
unless can_be_transferred_to?(current_user.registrar)
throw :epp_error, {
code: '2002',
msg: I18n.t(:domain_already_belongs_to_the_querying_registrar)
}
end
old_contact_codes = contacts.pluck(:code).sort.uniq
old_registrant_code = registrant.code
transaction do
begin
dt = domain_transfers.create!(
transfer_requested_at: Time.zone.now,
transfer_to: current_user.registrar,
transfer_from: registrar
dt = domain_transfers.create!(
transfer_requested_at: Time.zone.now,
transfer_to: current_user.registrar,
transfer_from: registrar
)
if dt.pending?
registrar.messages.create!(
body: I18n.t('transfer_requested'),
attached_obj_id: dt.id,
attached_obj_type: dt.class.to_s
)
if dt.pending?
registrar.messages.create!(
body: I18n.t('transfer_requested'),
attached_obj_id: dt.id,
attached_obj_type: dt.class.to_s
)
end
if dt.approved?
transfer_contacts(current_user.registrar_id)
dt.notify_losing_registrar(old_contact_codes, old_registrant_code)
generate_auth_info
self.registrar = current_user.registrar
end
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
save!(validate: false)
return dt
rescue => e
add_epp_error('2306', nil, nil, I18n.t('action_failed_due_to_server_error'))
logger.error('DOMAIN TRANSFER FAILED')
logger.error(e)
raise ActiveRecord::Rollback
end
if dt.approved?
transfer_contacts(current_user.registrar_id)
dt.notify_losing_registrar(old_contact_codes, old_registrant_code)
generate_auth_info
self.registrar = current_user.registrar
end
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
save!(validate: false)
return dt
end
end
# rubocop: enable Metrics/AbcSize
@ -595,22 +592,17 @@ class Epp::Domain < Domain
end
transaction do
begin
pt.update!(
status: DomainTransfer::CLIENT_APPROVED,
transferred_at: Time.zone.now
)
pt.update!(
status: DomainTransfer::CLIENT_APPROVED,
transferred_at: Time.zone.now
)
transfer_contacts(pt.transfer_to_id)
generate_auth_info
self.registrar = pt.transfer_to
transfer_contacts(pt.transfer_to_id)
generate_auth_info
self.registrar = pt.transfer_to
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
save!(validate: false)
rescue => _e
add_epp_error('2306', nil, nil, I18n.t('action_failed_due_to_server_error'))
raise ActiveRecord::Rollback
end
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
save!(validate: false)
end
pt
@ -626,17 +618,12 @@ class Epp::Domain < Domain
end
transaction do
begin
pt.update!(
status: DomainTransfer::CLIENT_REJECTED
)
pt.update!(
status: DomainTransfer::CLIENT_REJECTED
)
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
save!(validate: false)
rescue => _e
add_epp_error('2306', nil, nil, I18n.t('action_failed_due_to_server_error'))
raise ActiveRecord::Rollback
end
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
save!(validate: false)
end
pt
@ -713,11 +700,7 @@ class Epp::Domain < Domain
end
def can_be_transferred_to?(new_registrar)
if new_registrar == registrar
errors.add(:base, :domain_already_belongs_to_the_querying_registrar)
return false
end
true
new_registrar != registrar
end
## SHARED

View file

@ -872,3 +872,4 @@ en:
payment_received: 'Payment received'
domain_registrant_updated: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.'
api_user_not_found: 'API user not found'
domain_already_belongs_to_the_querying_registrar: 'Domain already belongs to the querying registrar'