mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
PostalInfo type checking for contact create
This commit is contained in:
parent
ad03165546
commit
678fd29c09
4 changed files with 24 additions and 7 deletions
|
@ -48,14 +48,12 @@ module Epp
|
||||||
## CREATE
|
## CREATE
|
||||||
def validate_contact_create_request
|
def validate_contact_create_request
|
||||||
@ph = params_hash['epp']['command']['create']['create']
|
@ph = params_hash['epp']['command']['create']['create']
|
||||||
xml_attrs_present?(@ph, [%w(id),
|
xml_attrs_present?(@ph, [%w(id), %w(authInfo pw), %w(postalInfo)])
|
||||||
%w(authInfo pw),
|
|
||||||
%w(postalInfo)])
|
|
||||||
return epp_errors.empty? unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array)
|
return epp_errors.empty? unless @ph['postalInfo'].is_a?(Hash) || @ph['postalInfo'].is_a?(Array)
|
||||||
|
|
||||||
xml_attrs_array_present?(@ph['postalInfo'], [%w(name),
|
(epp_errors << Address.validate_postal_info_types(parsed_frame)).flatten!
|
||||||
%w(addr city),
|
xml_attrs_array_present?(@ph['postalInfo'], [%w(name), %w(addr city), %w(addr cc)])
|
||||||
%w(addr cc)])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
## UPDATE
|
## UPDATE
|
||||||
|
|
|
@ -14,6 +14,23 @@ class Address < ActiveRecord::Base
|
||||||
# validates_inclusion_of :type, in: TYPES
|
# validates_inclusion_of :type, in: TYPES
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
|
def validate_postal_info_types(parsed_frame)
|
||||||
|
errors, used = [], []
|
||||||
|
|
||||||
|
parsed_frame.css('postalInfo').each do |pi|
|
||||||
|
attr = pi.attributes['type'].try(:value)
|
||||||
|
errors << { code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type')} and next unless attr
|
||||||
|
if !TYPES.include?(attr)
|
||||||
|
errors << { code: 2005, msg: I18n.t('errors.messages.invalid_type'), value: { obj: 'type', val: attr }}
|
||||||
|
next
|
||||||
|
end
|
||||||
|
errors << { code: 2005, msg: I18n.t('errors.messages.repeating_postal_info') } and next if used.include?(attr)
|
||||||
|
used << attr
|
||||||
|
end
|
||||||
|
errors
|
||||||
|
end
|
||||||
|
|
||||||
def extract_attributes(ah)
|
def extract_attributes(ah)
|
||||||
address_hash = {}
|
address_hash = {}
|
||||||
[ah].flatten.each do |pi|
|
[ah].flatten.each do |pi|
|
||||||
|
|
|
@ -98,6 +98,8 @@ en:
|
||||||
epp_exp_dates_do_not_match: 'Given and current expire dates do not match'
|
epp_exp_dates_do_not_match: 'Given and current expire dates do not match'
|
||||||
epp_registrant_not_found: 'Registrant not found'
|
epp_registrant_not_found: 'Registrant not found'
|
||||||
required_parameter_missing: 'Required parameter missing: %{key}'
|
required_parameter_missing: 'Required parameter missing: %{key}'
|
||||||
|
attr_missing: 'Required parameter missing: %{key}'
|
||||||
|
repeating_postal_info: 'Only one of each postal info types may be provided'
|
||||||
|
|
||||||
setting_groups:
|
setting_groups:
|
||||||
codes:
|
codes:
|
||||||
|
|
|
@ -36,7 +36,7 @@ module EppContactXmlBuilder
|
||||||
xml.tag!('contact:create', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do
|
xml.tag!('contact:create', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do
|
||||||
xml.tag!('contact:id', xml_params[:id], 'sh8013') unless xml_params[:id] == false
|
xml.tag!('contact:id', xml_params[:id], 'sh8013') unless xml_params[:id] == false
|
||||||
unless xml_params[:postalInfo] == [false]
|
unless xml_params[:postalInfo] == [false]
|
||||||
xml.tag!('contact:postalInfo') do
|
xml.tag!('contact:postalInfo', type: 'int') do
|
||||||
xml.tag!('contact:name', ( xml_params[:name] || 'Sillius Soddus')) unless xml_params[:name] == false
|
xml.tag!('contact:name', ( xml_params[:name] || 'Sillius Soddus')) unless xml_params[:name] == false
|
||||||
xml.tag!('contact:org', ( xml_params[:org_name] || 'Example Inc.')) unless xml_params[:org_name] == false
|
xml.tag!('contact:org', ( xml_params[:org_name] || 'Example Inc.')) unless xml_params[:org_name] == false
|
||||||
unless xml_params[:addr] == [false]
|
unless xml_params[:addr] == [false]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue