mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +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
|
def info
|
||||||
send("info_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
send("info_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
send("update_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,17 @@ module Epp::ContactsHelper
|
||||||
end
|
end
|
||||||
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
|
def delete_contact
|
||||||
ph = params_hash['epp']['command']['delete']['delete']
|
ph = params_hash['epp']['command']['delete']['delete']
|
||||||
|
|
||||||
|
@ -60,21 +71,30 @@ module Epp::ContactsHelper
|
||||||
private
|
private
|
||||||
|
|
||||||
def contact_and_address_attributes
|
def contact_and_address_attributes
|
||||||
ph = params_hash['epp']['command']['create']['create']
|
ph = params_hash['epp']['command'][params[:command]][params[:command]]
|
||||||
{
|
ph = ph[:chg] if params[:command] == 'update'
|
||||||
|
contact_hash = {
|
||||||
code: ph[:id],
|
code: ph[:id],
|
||||||
phone: ph[:voice],
|
phone: ph[:voice],
|
||||||
ident: ph[:ident],
|
ident: ph[:ident],
|
||||||
ident_type: ident_type,
|
ident_type: ident_type,
|
||||||
email: ph[:email],
|
email: ph[:email],
|
||||||
|
}
|
||||||
|
|
||||||
|
contact_hash = contact_hash.merge({
|
||||||
name: ph[:postalInfo][:name],
|
name: ph[:postalInfo][:name],
|
||||||
org_name: ph[:postalInfo][:org],
|
org_name: ph[:postalInfo][:org]
|
||||||
|
}) if ph[:postalInfo].is_a? Hash
|
||||||
|
|
||||||
|
contact_hash = contact_hash.merge({
|
||||||
address_attributes: {
|
address_attributes: {
|
||||||
country_id: Country.find_by(iso: ph[:postalInfo][:addr][:cc]),
|
country_id: Country.find_by(iso: ph[:postalInfo][:addr][:cc]),
|
||||||
street: tidy_street,
|
street: tidy_street,
|
||||||
zip: ph[:postalInfo][:addr][:pc]
|
zip: ph[:postalInfo][:addr][:pc]
|
||||||
}
|
}
|
||||||
}
|
}) if ph[:postalInfo].is_a?(Hash) && ph[:postalInfo][:addr].is_a?(Hash)
|
||||||
|
|
||||||
|
contact_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_rights
|
def has_rights
|
||||||
|
@ -85,10 +105,13 @@ module Epp::ContactsHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def tidy_street
|
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 if street.is_a? String
|
||||||
return street.join(',') if street.is_a? Array
|
return street.join(',') if street.is_a? Array
|
||||||
return nil
|
return nil
|
||||||
|
rescue NoMethodError => e #refactor so wouldn't use rescue for flow control
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def ident_type
|
def ident_type
|
||||||
|
@ -103,7 +126,8 @@ module Epp::ContactsHelper
|
||||||
def handle_contact_errors # handle_errors conflicted with domain logic
|
def handle_contact_errors # handle_errors conflicted with domain logic
|
||||||
handle_epp_errors({
|
handle_epp_errors({
|
||||||
'2302' => ['Contact id already exists'],
|
'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)
|
},@contact)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,10 @@ class Contact < ActiveRecord::Base
|
||||||
validates_presence_of :code, :name, :phone, :email, :ident
|
validates_presence_of :code, :name, :phone, :email, :ident
|
||||||
|
|
||||||
validate :ident_must_be_valid
|
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
|
validates_uniqueness_of :code, message: :epp_id_taken
|
||||||
|
|
||||||
IDENT_TYPE_ICO = 'ico'
|
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
|
|
@ -31,8 +31,10 @@ en:
|
||||||
blank: "Required parameter missing - name"
|
blank: "Required parameter missing - name"
|
||||||
phone:
|
phone:
|
||||||
blank: "Required parameter missing - phone"
|
blank: "Required parameter missing - phone"
|
||||||
|
invalid: "Phone nr is invalid"
|
||||||
email:
|
email:
|
||||||
blank: "Required parameter missing - email"
|
blank: "Required parameter missing - email"
|
||||||
|
invalid: "Email is invalid"
|
||||||
ident:
|
ident:
|
||||||
blank: "Required parameter missing - ident"
|
blank: "Required parameter missing - ident"
|
||||||
domain:
|
domain:
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
|
|
||||||
<simpleType name="e164StringType">
|
<simpleType name="e164StringType">
|
||||||
<restriction base="token">
|
<restriction base="token">
|
||||||
<pattern value="(\+[0-9]{1,3}\.[0-9]{1,14})?"/>
|
<!--<pattern value="(\+[0-9]{1,3}\.[0-9]{1,14})?"/> -->
|
||||||
<maxLength value="17"/>
|
<maxLength value="17"/>
|
||||||
</restriction>
|
</restriction>
|
||||||
</simpleType>
|
</simpleType>
|
||||||
|
@ -236,6 +236,8 @@
|
||||||
minOccurs="0"/>
|
minOccurs="0"/>
|
||||||
<element name="email" type="eppcom:minTokenType"
|
<element name="email" type="eppcom:minTokenType"
|
||||||
minOccurs="0"/>
|
minOccurs="0"/>
|
||||||
|
<element name="ident" type="contact:identType"
|
||||||
|
minOccurs="0"/>
|
||||||
<element name="authInfo" type="contact:authInfoType"
|
<element name="authInfo" type="contact:authInfoType"
|
||||||
minOccurs="0"/>
|
minOccurs="0"/>
|
||||||
<element name="disclose" type="contact:discloseType"
|
<element name="disclose" type="contact:discloseType"
|
||||||
|
|
|
@ -29,23 +29,6 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(Contact.count).to eq(1)
|
expect(Contact.count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates a contact with same ident', pending: true do
|
|
||||||
pending 'fixing this as soon as contact#update is done'
|
|
||||||
Fabricate(:contact)
|
|
||||||
response = epp_request('contacts/create.xml')
|
|
||||||
expect(response[:result_code]).to eq('1000')
|
|
||||||
expect(response[:msg]).to eq('Command completed successfully')
|
|
||||||
expect(response[:clTRID]).to eq('ABC-12345')
|
|
||||||
|
|
||||||
expect(Contact.first.name).to eq("John Doe")
|
|
||||||
expect(Contact.first.ident_type).to eq("op")
|
|
||||||
|
|
||||||
expect(Contact.first.updated_by_id).to be 1
|
|
||||||
#nil because we fabricate, hence stamping in controller won't happen
|
|
||||||
expect(Contact.first.created_by_id).to be nil
|
|
||||||
|
|
||||||
expect(Contact.count).to eq(1)
|
|
||||||
end
|
|
||||||
#TODO tests for missing/invalid/etc ident
|
#TODO tests for missing/invalid/etc ident
|
||||||
|
|
||||||
it 'deletes contact' do
|
it 'deletes contact' do
|
||||||
|
@ -107,5 +90,24 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(response[:result_code]).to eq('2201')
|
expect(response[:result_code]).to eq('2201')
|
||||||
expect(response[:msg]).to eq('Authorization error')
|
expect(response[:msg]).to eq('Authorization error')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'updates contact succesfully' do
|
||||||
|
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013')
|
||||||
|
response = epp_request('contacts/update.xml')
|
||||||
|
expect(response[:msg]).to eq('Command completed successfully')
|
||||||
|
expect(Contact.first.name).to eq('John Doe')
|
||||||
|
expect(Contact.first.email).to eq('jdoe@example.com')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns phone and email error' do
|
||||||
|
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013')
|
||||||
|
response = epp_request('contacts/update_with_errors.xml')
|
||||||
|
|
||||||
|
expect(response[:results][0][:result_code]).to eq('2005')
|
||||||
|
expect(response[:results][0][:msg]).to eq('Phone nr is invalid')
|
||||||
|
|
||||||
|
expect(response[:results][1][:result_code]).to eq('2005')
|
||||||
|
expect(response[:results][1][:msg]).to eq('Email is invalid')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
36
spec/epp/requests/contacts/update.xml
Normal file
36
spec/epp/requests/contacts/update.xml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||||
|
<command>
|
||||||
|
<update>
|
||||||
|
<contact:update
|
||||||
|
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
|
||||||
|
<contact:id>sh8013</contact:id>
|
||||||
|
<contact:chg>
|
||||||
|
<contact:postalInfo type="int">
|
||||||
|
<contact:name>John Doe</contact:name>
|
||||||
|
<contact:addr>
|
||||||
|
<contact:street>123 Example Dr.</contact:street>
|
||||||
|
<contact:street>Suite 100</contact:street>
|
||||||
|
<contact:city>Dulles</contact:city>
|
||||||
|
<contact:sp>VA</contact:sp>
|
||||||
|
<contact:pc>20166-6503</contact:pc>
|
||||||
|
<contact:cc>EE</contact:cc>
|
||||||
|
</contact:addr>
|
||||||
|
</contact:postalInfo>
|
||||||
|
<contact:voice x="1234">+123.7035555555</contact:voice>
|
||||||
|
<contact:fax>+1.7035555556</contact:fax>
|
||||||
|
<contact:email>jdoe@example.com</contact:email>
|
||||||
|
<contact:ident type="op">37605030299</contact:ident>
|
||||||
|
<contact:authInfo>
|
||||||
|
<contact:pw>2fooBAR</contact:pw>
|
||||||
|
</contact:authInfo>
|
||||||
|
<contact:disclose flag="0">
|
||||||
|
<contact:voice/>
|
||||||
|
<contact:email/>
|
||||||
|
</contact:disclose>
|
||||||
|
</contact:chg>
|
||||||
|
</contact:update>
|
||||||
|
</update>
|
||||||
|
<clTRID>ABC-12345</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
16
spec/epp/requests/contacts/update_with_errors.xml
Normal file
16
spec/epp/requests/contacts/update_with_errors.xml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||||
|
<command>
|
||||||
|
<update>
|
||||||
|
<contact:update
|
||||||
|
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
|
||||||
|
<contact:id>sh8013</contact:id>
|
||||||
|
<contact:chg>
|
||||||
|
<contact:voice x="1234">123456798</contact:voice>
|
||||||
|
<contact:email>faulty</contact:email>
|
||||||
|
</contact:chg>
|
||||||
|
</contact:update>
|
||||||
|
</update>
|
||||||
|
<clTRID>ABC-12345</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
|
@ -23,8 +23,8 @@ describe Contact do
|
||||||
expect(@contact.errors.messages).to match_array({
|
expect(@contact.errors.messages).to match_array({
|
||||||
:code=>["Required parameter missing - code"],
|
:code=>["Required parameter missing - code"],
|
||||||
:name=>["Required parameter missing - name"],
|
:name=>["Required parameter missing - name"],
|
||||||
:phone=>["Required parameter missing - phone", "bad format"],
|
:phone=>["Required parameter missing - phone", "Phone nr is invalid"],
|
||||||
:email=>["Required parameter missing - email"],
|
:email=>["Required parameter missing - email", "Email is invalid"],
|
||||||
:ident=>["Required parameter missing - ident"]
|
:ident=>["Required parameter missing - ident"]
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue