mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 08:22:05 +02:00
Merge branch 'master' of github.com:internetee/registry
This commit is contained in:
commit
eaa9b015e2
9 changed files with 118 additions and 69 deletions
|
@ -10,10 +10,9 @@ module Epp::ContactsHelper
|
|||
end
|
||||
|
||||
def update_contact
|
||||
#TODO add support for rem and add
|
||||
code = params_hash['epp']['command']['update']['update'][:id]
|
||||
@contact = Contact.where(code: code).first
|
||||
if stamp(@contact) && @contact.update_attributes(contact_and_address_attributes.delete_if { |k, v| v.nil? })
|
||||
if stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
|
||||
render 'epp/contacts/update'
|
||||
else
|
||||
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'), value: { obj: 'id', val: code } } if @contact == []
|
||||
|
@ -23,52 +22,28 @@ module Epp::ContactsHelper
|
|||
|
||||
def delete_contact
|
||||
#no deleting, implement PaperTrail or something similar.
|
||||
ph = params_hash['epp']['command']['delete']['delete']
|
||||
|
||||
@contact = Contact.where(code: ph[:id]).first
|
||||
@contact = find_contact
|
||||
handle_errors(@contact) and return unless @contact
|
||||
@contact.destroy
|
||||
render '/epp/contacts/delete'
|
||||
rescue NoMethodError => e
|
||||
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist') }
|
||||
render '/epp/error'
|
||||
rescue
|
||||
epp_errors << {code: '2400', msg: t('errors.messages.epp_command_failed')}
|
||||
render '/epp/error'
|
||||
end
|
||||
|
||||
def check_contact
|
||||
ph = params_hash['epp']['command']['check']['check']
|
||||
@contacts = Contact.check_availability( ph[:id] )
|
||||
|
||||
if @contacts.any?
|
||||
render '/epp/contacts/check'
|
||||
else
|
||||
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist') }
|
||||
render 'epp/error'
|
||||
end
|
||||
render '/epp/contacts/check'
|
||||
end
|
||||
|
||||
def info_contact
|
||||
#TODO do we reject contact without authInfo or display less info?
|
||||
#TODO add data missing from contacts/info builder ( marked with 'if false' in said view )
|
||||
current_epp_user
|
||||
ph = params_hash['epp']['command']['info']['info']
|
||||
|
||||
@contact = Contact.where(code: ph[:id]).first
|
||||
case has_rights
|
||||
when true
|
||||
render 'epp/contacts/info'
|
||||
when false
|
||||
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error') }
|
||||
render 'epp/error'
|
||||
end
|
||||
rescue NoMethodError => e
|
||||
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'), value: { obj: 'id', val: ph[:id] } }
|
||||
render 'epp/error'
|
||||
@contact = find_contact
|
||||
handle_errors(@contact) and return unless @contact
|
||||
render 'epp/contacts/info'
|
||||
end
|
||||
|
||||
## HELPER METHODS
|
||||
private
|
||||
|
||||
|
||||
## CREATE
|
||||
def validate_contact_create_request
|
||||
@ph = params_hash['epp']['command']['create']['create']
|
||||
xml_attrs_present?(@ph, [['id'],
|
||||
|
@ -79,54 +54,54 @@ module Epp::ContactsHelper
|
|||
['postalInfo', 'addr', 'cc'],
|
||||
['authInfo']])
|
||||
end
|
||||
|
||||
|
||||
## UPDATE
|
||||
def validate_contact_update_request
|
||||
@ph = params_hash['epp']['command']['update']['update']
|
||||
xml_attrs_present?(@ph, [['id'] ])
|
||||
end
|
||||
|
||||
## DELETE
|
||||
def validate_contact_delete_request
|
||||
@ph = params_hash['epp']['command']['delete']['delete']
|
||||
xml_attrs_present?(@ph, [ ['id'] ] )
|
||||
end
|
||||
|
||||
## CHECK
|
||||
def validate_contact_check_request
|
||||
@ph = params_hash['epp']['command']['check']['check']
|
||||
xml_attrs_present?(@ph, [ ['id'] ])
|
||||
end
|
||||
|
||||
## INFO
|
||||
def validate_contact_info_request
|
||||
@ph = params_hash['epp']['command']['info']['info']
|
||||
xml_attrs_present?(@ph, [ ['id'] ])
|
||||
end
|
||||
|
||||
## SHARED
|
||||
|
||||
def contact_and_address_attributes
|
||||
ph = params_hash['epp']['command'][params[:command]][params[:command]]
|
||||
ph = ph[:chg] if params[:command] == 'update'
|
||||
contact_hash = {
|
||||
code: ph[:id],
|
||||
phone: ph[:voice],
|
||||
ident: ph[:ident],
|
||||
ident_type: ident_type,
|
||||
email: ph[:email],
|
||||
}
|
||||
def find_contact
|
||||
contact = Contact.find_by(code: @ph[:id])
|
||||
unless contact
|
||||
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'), value: { obj: 'id', val: @ph[:id] } }
|
||||
end
|
||||
contact
|
||||
end
|
||||
|
||||
contact_hash = contact_hash.merge({
|
||||
name: ph[:postalInfo][:name],
|
||||
org_name: ph[:postalInfo][:org]
|
||||
}) if ph[:postalInfo].is_a? Hash
|
||||
|
||||
contact_hash = contact_hash.merge({
|
||||
address_attributes: {
|
||||
country_id: Country.find_by(iso: ph[:postalInfo][:addr][:cc]),
|
||||
street: ph[:postalInfo][:addr][:street][0],
|
||||
street2: ph[:postalInfo][:addr][:street][1],
|
||||
street3: ph[:postalInfo][:addr][:street][2],
|
||||
zip: ph[:postalInfo][:addr][:pc]
|
||||
}
|
||||
}) if ph[:postalInfo].is_a?(Hash) && ph[:postalInfo][:addr].is_a?(Hash)
|
||||
|
||||
def contact_and_address_attributes( type=:create )
|
||||
case type
|
||||
when :update
|
||||
contact_hash = Contact.extract_attributes(@ph[:chg], type)
|
||||
contact_hash[:address_attributes] =
|
||||
Address.extract_attributes(( @ph.try(:[], :chg).try(:[], :postalInfo).try(:[], :addr) || [] ), type)
|
||||
else
|
||||
contact_hash = Contact.extract_attributes(@ph, type)
|
||||
contact_hash[:address_attributes] =
|
||||
Address.extract_attributes(( @ph.try(:[], :postalInfo).try(:[], :addr) || [] ), type)
|
||||
end
|
||||
contact_hash[:ident_type] = ident_type unless ident_type.nil?
|
||||
contact_hash
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue