mirror of
https://github.com/internetee/registry.git
synced 2025-05-21 11:49:40 +02:00
Make request validation shorter on domain create
This commit is contained in:
parent
cad6d68bfa
commit
ebfa997124
4 changed files with 22 additions and 27 deletions
|
@ -142,7 +142,7 @@ class Epp::DomainsController < EppController
|
|||
end
|
||||
|
||||
def validate_update
|
||||
if params[:parsed_frame].css('chg registrant').present? && params[:parsed_frame].css('legalDocument').blank?
|
||||
if element_count('update > chg > registrant') > 0
|
||||
requires('extension > extdata > legalDocument')
|
||||
end
|
||||
|
||||
|
|
|
@ -75,32 +75,9 @@ class EppController < ApplicationController
|
|||
epp_errors.empty?
|
||||
end
|
||||
|
||||
def mutually_exclusive(*selectors)
|
||||
present_count = 0
|
||||
selectors.each do |selector|
|
||||
full_selector = [@prefix, selector].join(' ')
|
||||
el = params[:parsed_frame].css(full_selector).first
|
||||
present_count += 1 if el && el.text.present?
|
||||
end
|
||||
|
||||
return if present_count <= 1
|
||||
|
||||
epp_errors << {
|
||||
code: '2306',
|
||||
msg: I18n.t(:are_mutally_exclusive, params: selectors.join(', '))
|
||||
}
|
||||
end
|
||||
|
||||
# let's follow grape's validations: https://github.com/intridea/grape/#parameter-validation-and-coercion
|
||||
def exactly_one_of(*selectors)
|
||||
present_count = 0
|
||||
selectors.each do |selector|
|
||||
full_selector = [@prefix, selector].join(' ')
|
||||
el = params[:parsed_frame].css(full_selector).first
|
||||
present_count += 1 if el && el.text.present?
|
||||
end
|
||||
|
||||
return if present_count == 1
|
||||
return if element_count(*selectors) == 1
|
||||
|
||||
epp_errors << {
|
||||
code: '2306',
|
||||
|
@ -108,6 +85,14 @@ class EppController < ApplicationController
|
|||
}
|
||||
end
|
||||
|
||||
def mutually_exclusive(*selectors)
|
||||
return if element_count(*selectors) <= 1
|
||||
epp_errors << {
|
||||
code: '2306',
|
||||
msg: I18n.t(:mutally_exclusive_params, params: selectors.join(', '))
|
||||
}
|
||||
end
|
||||
|
||||
def optional(selector, *validations)
|
||||
full_selector = [@prefix, selector].join(' ')
|
||||
el = params[:parsed_frame].css(full_selector).first
|
||||
|
@ -121,6 +106,16 @@ class EppController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def element_count(*selectors)
|
||||
present_count = 0
|
||||
selectors.each do |selector|
|
||||
full_selector = [@prefix, selector].join(' ')
|
||||
el = params[:parsed_frame].css(full_selector).first
|
||||
present_count += 1 if el && el.text.present?
|
||||
end
|
||||
present_count
|
||||
end
|
||||
|
||||
def xml_attrs_present?(ph, attributes) # TODO: THIS IS DEPRECATED AND WILL BE REMOVED IN FUTURE
|
||||
attributes.each do |x|
|
||||
epp_errors << {
|
||||
|
|
|
@ -500,4 +500,4 @@ en:
|
|||
could_not_determine_object_type_check_xml_format_and_namespaces: 'Could not determine object type. Check XML format and namespaces.'
|
||||
unknown_expiry_relative_pattern: 'Expiry relative must be compatible to ISO 8601'
|
||||
unknown_expiry_absolute_pattern: 'Expiry absolute must be compatible to ISO 8601'
|
||||
are_mutally_exclusive: '%{params} are mutually exclusive'
|
||||
mutally_exclusive_params: 'Mutually exclusive parameters: %{params}'
|
||||
|
|
|
@ -629,7 +629,7 @@ describe 'EPP Domain', epp: true do
|
|||
})
|
||||
|
||||
response = epp_plain_request(xml, :xml)
|
||||
response[:msg].should == 'keyData, dsData are mutually exclusive'
|
||||
response[:msg].should == 'Mutually exclusive parameters: keyData, dsData'
|
||||
response[:result_code].should == '2306'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue