REPP: Verify contact ident type

This commit is contained in:
Karl Erik Õunapuu 2020-10-09 11:12:25 +03:00
parent 39c6d20413
commit a73cd53bff
No known key found for this signature in database
GPG key ID: C9DD647298A34764
3 changed files with 17 additions and 9 deletions

View file

@ -46,7 +46,7 @@ module Repp
end
def ip_whitelisted?
return false unless @api_user.registrar.api_ip_white?(request.ip)
return false unless current_user.registrar.api_ip_white?(request.ip)
end
def basic_token
@ -70,7 +70,6 @@ module Repp
return if allowed
flash[:alert] = t('registrar.authorization.ip_not_allowed', ip: request.ip)
render(json: { errors: [{ base: [I18n.t('registrar.authorization.ip_not_allowed', ip: request.ip)] }] }, status: :unauthorized)
end

View file

@ -41,10 +41,9 @@ module Repp
## POST /repp/v1/contacts
def create
@legal_doc = params[:legal_documents]
@contact_params = contact_create_params
@contact_params = contact_params_with_address
@ident = contact_ident_params
address_present = contact_addr_params.keys.any?
%w[city street zip country_code].each { |k| @contact_params[k] = contact_addr_params[k] }
@contact = Epp::Contact.new(@contact_params, current_user.registrar, epp: false)
@ -70,8 +69,7 @@ module Repp
## PUT /repp/v1/contacts/1
def update
@update = contact_create_params
%w[city street zip country_code].each { |k| @new_params[k] = contact_addr_params[k] }
@update = contact_params_with_address
@legal_doc = params[:legal_document]
@ident = contact_ident_params || {}
@ -101,6 +99,12 @@ module Repp
@contact = Epp::Contact.find_by!(code: code)
end
def contact_params_with_address
addr = {}
contact_addr_params[:addr].each_key { |k| addr[k] = contact_addr_params[:addr][k] }
contact_create_params.merge(addr)
end
def contact_create_params
params.require(:contact).require(%i[name email phone])
params.require(:contact).permit(:name, :email, :phone)

View file

@ -26,9 +26,14 @@ module Actions
end
def validate_ident
if ident.present? && ident[:ident_type].blank?
contact.add_epp_error('2003', nil, 'ident_type', I18n.t('errors.messages.required_ident_attribute_missing'))
@error = true
if ident.present?
if ident[:ident_type].blank?
contact.add_epp_error('2003', nil, 'ident_type', I18n.t('errors.messages.required_ident_attribute_missing'))
@error = true
elsif !%w[priv org birthday].include?(ident[:ident_type])
contact.add_epp_error('2003', nil, 'ident_type', 'Invalid ident type')
@error = true
end
end
if ident.present? && ident[:ident_type] != 'birthday' && ident[:ident_country_code].blank?