mirror of
https://github.com/internetee/registry.git
synced 2025-06-13 16:14:47 +02:00
Add epp errors support to bulk renew
This commit is contained in:
parent
0f812d0b15
commit
79351d50d9
8 changed files with 42 additions and 22 deletions
|
@ -6,7 +6,9 @@ module Repp
|
||||||
super
|
super
|
||||||
|
|
||||||
unless @new_contact.identical_to?(@current_contact)
|
unless @new_contact.identical_to?(@current_contact)
|
||||||
@epp_errors << { code: 2304, msg: 'Admin contacts must be identical' }
|
@epp_errors.add(:epp_errors,
|
||||||
|
msg: 'Admin contacts must be identical',
|
||||||
|
code: '2304')
|
||||||
end
|
end
|
||||||
|
|
||||||
return handle_errors if @epp_errors.any?
|
return handle_errors if @epp_errors.any?
|
||||||
|
|
|
@ -15,8 +15,12 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@epp_errors ||= []
|
@epp_errors ||= ActiveModel::Errors.new(self)
|
||||||
@epp_errors << { code: 2304, msg: 'New contact must be valid' } if @new_contact.invalid?
|
if @new_contact.invalid?
|
||||||
|
@epp_errors.add(:epp_errors,
|
||||||
|
msg: 'New contact must be valid',
|
||||||
|
code: '2304')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -50,7 +50,9 @@ module Repp
|
||||||
super
|
super
|
||||||
|
|
||||||
if @new_contact == @current_contact
|
if @new_contact == @current_contact
|
||||||
@epp_errors << { code: 2304, msg: 'New contact must be different from current' }
|
@epp_errors.add(:epp_errors,
|
||||||
|
msg: 'New contact must be different from current',
|
||||||
|
code: '2304')
|
||||||
end
|
end
|
||||||
|
|
||||||
return handle_errors if @epp_errors.any?
|
return handle_errors if @epp_errors.any?
|
||||||
|
|
|
@ -29,8 +29,8 @@ module Repp
|
||||||
renew = run_bulk_renew_task(@domains, bulk_renew_params[:renew_period])
|
renew = run_bulk_renew_task(@domains, bulk_renew_params[:renew_period])
|
||||||
return render_success(data: { updated_domains: @domains.map(&:name) }) if renew.valid?
|
return render_success(data: { updated_domains: @domains.map(&:name) }) if renew.valid?
|
||||||
|
|
||||||
@epp_errors << { code: 2002,
|
msg = renew.errors.keys.map { |k, _v| renew.errors[k] }.join(', ')
|
||||||
msg: renew.errors.keys.map { |k, _v| renew.errors[k] }.join(', ') }
|
@epp_errors.add(:epp_errors, msg: msg , code: '2002')
|
||||||
handle_errors
|
handle_errors
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,20 +41,20 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_renew_period
|
def validate_renew_period
|
||||||
@epp_errors ||= []
|
@epp_errors ||= ActiveModel::Errors.new(self)
|
||||||
periods = Depp::Domain::PERIODS.map { |p| p[1] }
|
periods = Depp::Domain::PERIODS.map { |p| p[1] }
|
||||||
return if periods.include? bulk_renew_params[:renew_period]
|
return if periods.include? bulk_renew_params[:renew_period]
|
||||||
|
|
||||||
@epp_errors << { code: 2005, msg: 'Invalid renew period' }
|
@epp_errors.add(:epp_errors, msg: 'Invalid renew period' , code: '2005')
|
||||||
end
|
end
|
||||||
|
|
||||||
def select_renewable_domains
|
def select_renewable_domains
|
||||||
@epp_errors ||= []
|
@epp_errors ||= ActiveModel::Errors.new(self)
|
||||||
|
|
||||||
if bulk_renew_params[:domains].instance_of?(Array)
|
if bulk_renew_params[:domains].instance_of?(Array)
|
||||||
@domains = bulk_renew_domains
|
@domains = bulk_renew_domains
|
||||||
else
|
else
|
||||||
@epp_errors << { code: 2005, msg: 'Domains attribute must be an array' }
|
@epp_errors.add(:epp_errors, msg: 'Domains attribute must be an array' , code: '2005')
|
||||||
end
|
end
|
||||||
|
|
||||||
return handle_errors if @epp_errors.any?
|
return handle_errors if @epp_errors.any?
|
||||||
|
@ -73,12 +73,16 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_renew_domains
|
def bulk_renew_domains
|
||||||
@epp_errors ||= []
|
@epp_errors ||= ActiveModel::Errors.new(self)
|
||||||
domains = []
|
domains = []
|
||||||
bulk_renew_params[:domains].each do |idn|
|
bulk_renew_params[:domains].each do |idn|
|
||||||
domain = Epp::Domain.find_by(name: idn)
|
domain = Epp::Domain.find_by(name: idn)
|
||||||
domains << domain if domain
|
domains << domain if domain
|
||||||
@epp_errors << { code: 2304, msg: "Object does not exist: #{idn}" } unless domain
|
unless domain
|
||||||
|
@epp_errors.add(:epp_errors,
|
||||||
|
msg: "Object does not exist: #{idn}",
|
||||||
|
code: '2304')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
domains
|
domains
|
||||||
|
|
|
@ -108,7 +108,7 @@ module Repp
|
||||||
api :POST, '/repp/v1/domains/transfer'
|
api :POST, '/repp/v1/domains/transfer'
|
||||||
desc 'Transfer multiple domains'
|
desc 'Transfer multiple domains'
|
||||||
def transfer
|
def transfer
|
||||||
@errors ||= []
|
@errors ||= ActiveModel::Errors.new(self)
|
||||||
@successful = []
|
@successful = []
|
||||||
|
|
||||||
transfer_params[:domain_transfers].each do |transfer|
|
transfer_params[:domain_transfers].each do |transfer|
|
||||||
|
@ -150,8 +150,9 @@ module Repp
|
||||||
if action.call
|
if action.call
|
||||||
@successful << { type: 'domain_transfer', domain_name: domain.name }
|
@successful << { type: 'domain_transfer', domain_name: domain.name }
|
||||||
else
|
else
|
||||||
@errors << { type: 'domain_transfer', domain_name: domain.name,
|
domain.errors.where(:epp_errors).each do |domain_error|
|
||||||
errors: domain.errors.where(:epp_errors)[0].options }
|
@errors.import domain_error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -187,7 +188,7 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_authorized_domain
|
def set_authorized_domain
|
||||||
@epp_errors ||= []
|
@epp_errors ||= ActiveModel::Errors.new(self)
|
||||||
@domain = domain_from_url_hash
|
@domain = domain_from_url_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ module Domains
|
||||||
end
|
end
|
||||||
|
|
||||||
def manage_errors(task)
|
def manage_errors(task)
|
||||||
task.errors.each { |k, v| errors.add(k, v) } unless task.valid?
|
task.errors.each { |task_error| errors.import task_error } unless task.valid?
|
||||||
errors.add(:domain, I18n.t('not_enough_funds')) unless task.result
|
errors.add(:domain, I18n.t('not_enough_funds')) unless task.result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,11 @@ module Domains
|
||||||
period: period,
|
period: period,
|
||||||
unit: unit)
|
unit: unit)
|
||||||
|
|
||||||
task.valid? ? @total_price += task.result : errors.merge!(task.errors)
|
if task.valid?
|
||||||
|
@total_price += task.result
|
||||||
|
else
|
||||||
|
task.errors.each { |task_error| errors.import task_error }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -92,7 +92,10 @@ class ReppV1DomainsBulkRenewTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_throws_error_when_not_enough_balance
|
def test_throws_error_when_not_enough_balance
|
||||||
billing_prices(:renew_one_year).update(price_cents: 99999999)
|
price = Billing::Price.last
|
||||||
|
price.price_cents = 99999999
|
||||||
|
price.save(validate: false)
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"domains": [
|
"domains": [
|
||||||
'invalid.test',
|
'invalid.test',
|
||||||
|
@ -106,7 +109,7 @@ class ReppV1DomainsBulkRenewTest < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
assert_response :bad_request
|
assert_response :bad_request
|
||||||
assert_equal 2002, json[:code]
|
assert_equal 2002, json[:code]
|
||||||
assert_equal 'Domain Billing failure - credit balance low', json[:message]
|
assert_equal 'Billing failure - credit balance low', json[:message]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue