mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Fixed address saving for contact, refactored a bit
This commit is contained in:
parent
8ce1875484
commit
2a6a30c2b2
1 changed files with 40 additions and 16 deletions
|
@ -3,27 +3,15 @@ module Epp::ContactsHelper
|
||||||
ph = params_hash['epp']['command']['create']['create']
|
ph = params_hash['epp']['command']['create']['create']
|
||||||
|
|
||||||
ph[:ident] ? @contact = Contact.where(ident: ph[:ident]).first_or_initialize : @contact = Contact.new
|
ph[:ident] ? @contact = Contact.where(ident: ph[:ident]).first_or_initialize : @contact = Contact.new
|
||||||
if @contact.new_record?
|
|
||||||
@contact.assign_attributes(
|
|
||||||
code: ph[:id],
|
|
||||||
phone: ph[:voice],
|
|
||||||
ident: ph[:ident],
|
|
||||||
email: ph[:email],
|
|
||||||
org_name: ph[:postalInfo][:org]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
@contact.name = ph[:postalInfo][:name]
|
|
||||||
@contact.ident_type = ident_type
|
|
||||||
|
|
||||||
@contact.addresses << Address.new(
|
@contact.assign_attributes(new_contact_info ) if @contact.new_record?
|
||||||
country_id: Country.find_by(iso: ph[:postalInfo][:cc]),
|
@contact.assign_attributes(name_and_ident_type)
|
||||||
street: ph[:postalInfo][:street],
|
|
||||||
zip: ph[:postalInfo][:pc]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@contact.addresses << new_address
|
||||||
stamp @contact
|
stamp @contact
|
||||||
|
|
||||||
@contact.save
|
@contact.save
|
||||||
|
|
||||||
render '/epp/contacts/create'
|
render '/epp/contacts/create'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -71,6 +59,42 @@ module Epp::ContactsHelper
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def new_address
|
||||||
|
ph = params_hash['epp']['command']['create']['create']
|
||||||
|
|
||||||
|
Address.new(
|
||||||
|
country_id: Country.find_by(iso: ph[:postalInfo][:addr][:cc]),
|
||||||
|
street: tidy_street,
|
||||||
|
zip: ph[:postalInfo][:addr][:pc]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def name_and_ident_type
|
||||||
|
ph = params_hash['epp']['command']['create']['create']
|
||||||
|
{
|
||||||
|
name: ph[:postalInfo][:name],
|
||||||
|
ident_type: ident_type
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_contact_info
|
||||||
|
ph = params_hash['epp']['command']['create']['create']
|
||||||
|
{
|
||||||
|
code: ph[:id],
|
||||||
|
phone: ph[:voice],
|
||||||
|
ident: ph[:ident],
|
||||||
|
email: ph[:email],
|
||||||
|
org_name: ph[:postalInfo][:org]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def tidy_street
|
||||||
|
street = params_hash['epp']['command']['create']['create'][:postalInfo][:addr][:street]
|
||||||
|
return street if street.is_a? String
|
||||||
|
return street.join(',') if street.is_a? Array
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
def ident_type
|
def ident_type
|
||||||
result = params[:frame].slice(/(?<=\<ns2:ident type=)(.*)(?=<)/)
|
result = params[:frame].slice(/(?<=\<ns2:ident type=)(.*)(?=<)/)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue