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
218ecb3317
10 changed files with 143 additions and 38 deletions
|
@ -24,4 +24,8 @@ class Epp::CommandsController < ApplicationController
|
|||
def info
|
||||
send("info_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||
end
|
||||
|
||||
def update
|
||||
send("update_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,17 @@ module Epp::ContactsHelper
|
|||
end
|
||||
end
|
||||
|
||||
def update_contact
|
||||
code = params_hash['epp']['command']['update']['update'][:id]
|
||||
@contact = Contact.where(code: code).first
|
||||
if @contact.update_attributes(contact_and_address_attributes.delete_if { |k, v| v.nil? })
|
||||
render 'epp/contacts/update'
|
||||
else
|
||||
handle_contact_errors
|
||||
render '/epp/error'
|
||||
end
|
||||
end
|
||||
|
||||
def delete_contact
|
||||
ph = params_hash['epp']['command']['delete']['delete']
|
||||
|
||||
|
@ -60,21 +71,30 @@ module Epp::ContactsHelper
|
|||
private
|
||||
|
||||
def contact_and_address_attributes
|
||||
ph = params_hash['epp']['command']['create']['create']
|
||||
{
|
||||
code: ph[:id],
|
||||
phone: ph[:voice],
|
||||
ident: ph[:ident],
|
||||
ident_type: ident_type,
|
||||
email: ph[:email],
|
||||
name: ph[:postalInfo][:name],
|
||||
org_name: ph[:postalInfo][:org],
|
||||
address_attributes: {
|
||||
country_id: Country.find_by(iso: ph[:postalInfo][:addr][:cc]),
|
||||
street: tidy_street,
|
||||
zip: ph[:postalInfo][:addr][:pc]
|
||||
}
|
||||
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],
|
||||
}
|
||||
|
||||
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: tidy_street,
|
||||
zip: ph[:postalInfo][:addr][:pc]
|
||||
}
|
||||
}) if ph[:postalInfo].is_a?(Hash) && ph[:postalInfo][:addr].is_a?(Hash)
|
||||
|
||||
contact_hash
|
||||
end
|
||||
|
||||
def has_rights
|
||||
|
@ -85,10 +105,13 @@ module Epp::ContactsHelper
|
|||
end
|
||||
|
||||
def tidy_street
|
||||
street = params_hash['epp']['command']['create']['create'][:postalInfo][:addr][:street]
|
||||
command = params[:command]
|
||||
street = params_hash['epp']['command'][command][command][:postalInfo][:addr][:street]
|
||||
return street if street.is_a? String
|
||||
return street.join(',') if street.is_a? Array
|
||||
return nil
|
||||
rescue NoMethodError => e #refactor so wouldn't use rescue for flow control
|
||||
return nil
|
||||
end
|
||||
|
||||
def ident_type
|
||||
|
@ -103,7 +126,8 @@ module Epp::ContactsHelper
|
|||
def handle_contact_errors # handle_errors conflicted with domain logic
|
||||
handle_epp_errors({
|
||||
'2302' => ['Contact id already exists'],
|
||||
'2303' => [:not_found, :epp_obj_does_not_exist]
|
||||
'2303' => [:not_found, :epp_obj_does_not_exist],
|
||||
'2005' => ['Phone nr is invalid', 'Email is invalid']
|
||||
},@contact)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,10 @@ class Contact < ActiveRecord::Base
|
|||
validates_presence_of :code, :name, :phone, :email, :ident
|
||||
|
||||
validate :ident_must_be_valid
|
||||
validates :phone, format: { with: /\+\d{3}\.\d+/, message: "bad format" }
|
||||
|
||||
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/ #/\+\d{3}\.\d+/
|
||||
validates :email, format: /@/
|
||||
|
||||
validates_uniqueness_of :code, message: :epp_id_taken
|
||||
|
||||
IDENT_TYPE_ICO = 'ico'
|
||||
|
|
16
app/views/epp/contacts/update.xml.builder
Normal file
16
app/views/epp/contacts/update.xml.builder
Normal file
|
@ -0,0 +1,16 @@
|
|||
xml.epp_head do
|
||||
xml.response do
|
||||
xml.result('code' => '1000') do
|
||||
xml.msg 'Command completed successfully'
|
||||
end
|
||||
|
||||
xml.resData do
|
||||
xml.tag!('contact:creData', 'xmlns:contact' => 'http://www.nic.cz/xml/epp/contact-1.6', 'xsi:schemaLocation' => 'http://www.nic.cz/xml/epp/contact-1.6 contact-1.6.xsd') do
|
||||
xml.tag!('contact:id', @contact.code)
|
||||
xml.tag!('contact:crDate', @contact.created_at)
|
||||
end
|
||||
end
|
||||
|
||||
xml << render('/epp/shared/trID')
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue