diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index c47e0d69f..82eae2105 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -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 diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 6d38a5225..8981dcd8f 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -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 << { diff --git a/config/locales/en.yml b/config/locales/en.yml index 15236335a..b14579991 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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}' diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index e810585ba..355c06f09 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -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