Refactor request_valid

This commit is contained in:
Martin Lensment 2015-01-23 13:35:38 +02:00
parent 0b7017481d
commit e66b5adae5
3 changed files with 14 additions and 12 deletions

View file

@ -117,12 +117,12 @@ class Epp::DomainsController < EppController
def validate_info
@prefix = 'info > info >'
epp_request_valid?('name')
requires('name')
end
def validate_check
@prefix = 'check > check >'
epp_request_valid?('name')
requires('name')
end
def validate_create
@ -131,30 +131,30 @@ class Epp::DomainsController < EppController
end
@prefix = 'create > create >'
epp_request_valid?('name', 'ns', 'registrant', 'ns > hostAttr')
requires('name', 'ns', 'registrant', 'ns > hostAttr')
@prefix = nil
epp_request_valid?('extension > extdata > legalDocument')
requires('extension > extdata > legalDocument')
end
def validate_renew
@prefix = 'renew > renew >'
epp_request_valid?('name', 'curExpDate', 'period')
requires('name', 'curExpDate', 'period')
end
def validate_update
if params[:parsed_frame].css('chg registrant').present? && params[:parsed_frame].css('legalDocument').blank?
epp_request_valid?('extension > extdata > legalDocument')
requires('extension > extdata > legalDocument')
end
@prefix = 'update > update >'
epp_request_valid?('name')
requires('name')
end
## TRANSFER
def validate_transfer
@prefix = 'transfer > transfer >'
epp_request_valid?('name')
requires('name')
op = params[:parsed_frame].css('transfer').first[:op]
return if %w(approve query reject).include?(op)
@ -163,10 +163,10 @@ class Epp::DomainsController < EppController
## DELETE
def validate_delete
epp_request_valid?('extension > extdata > legalDocument')
requires('extension > extdata > legalDocument')
@prefix = 'delete > delete >'
epp_request_valid?('name')
requires('name')
end
def domain_create_params

View file

@ -15,7 +15,8 @@ class Epp::KeyrelaysController < EppController
def validate_keyrelay
@prefix = 'keyrelay >'
epp_request_valid?(
requires(
'name',
'keyData', 'keyData > pubKey', 'keyData > flags', 'keyData > protocol', 'keyData > alg',
'authInfo', 'authInfo > pw'
@ -23,6 +24,7 @@ class Epp::KeyrelaysController < EppController
optional 'expiry > relative', duration_iso8601: true
optional 'expiry > absolute', date_time_iso8601: true
exactly_one_of 'expiry > relative', 'expiry > absolute'
end
# rubocop: enable Metrics/PerceivedComplexity

View file

@ -62,7 +62,7 @@ class EppController < ApplicationController
handle_errors and return if epp_errors.any?
end
def epp_request_valid?(*selectors)
def requires(*selectors)
selectors.each do |selector|
full_selector = [@prefix, selector].join(' ')
el = params[:parsed_frame].css(full_selector).first