mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 20:18:22 +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
|
end
|
||||||
|
|
||||||
def update_contact
|
def update_contact
|
||||||
#TODO add support for rem and add
|
|
||||||
code = params_hash['epp']['command']['update']['update'][:id]
|
code = params_hash['epp']['command']['update']['update'][:id]
|
||||||
@contact = Contact.where(code: code).first
|
@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'
|
render 'epp/contacts/update'
|
||||||
else
|
else
|
||||||
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'), value: { obj: 'id', val: code } } if @contact == []
|
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
|
def delete_contact
|
||||||
#no deleting, implement PaperTrail or something similar.
|
#no deleting, implement PaperTrail or something similar.
|
||||||
ph = params_hash['epp']['command']['delete']['delete']
|
@contact = find_contact
|
||||||
|
handle_errors(@contact) and return unless @contact
|
||||||
@contact = Contact.where(code: ph[:id]).first
|
|
||||||
@contact.destroy
|
@contact.destroy
|
||||||
render '/epp/contacts/delete'
|
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
|
end
|
||||||
|
|
||||||
def check_contact
|
def check_contact
|
||||||
ph = params_hash['epp']['command']['check']['check']
|
ph = params_hash['epp']['command']['check']['check']
|
||||||
@contacts = Contact.check_availability( ph[:id] )
|
@contacts = Contact.check_availability( ph[:id] )
|
||||||
|
render '/epp/contacts/check'
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def info_contact
|
def info_contact
|
||||||
#TODO do we reject contact without authInfo or display less info?
|
@contact = find_contact
|
||||||
#TODO add data missing from contacts/info builder ( marked with 'if false' in said view )
|
handle_errors(@contact) and return unless @contact
|
||||||
current_epp_user
|
render 'epp/contacts/info'
|
||||||
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'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
## HELPER METHODS
|
||||||
private
|
private
|
||||||
|
|
||||||
|
## CREATE
|
||||||
def validate_contact_create_request
|
def validate_contact_create_request
|
||||||
@ph = params_hash['epp']['command']['create']['create']
|
@ph = params_hash['epp']['command']['create']['create']
|
||||||
xml_attrs_present?(@ph, [['id'],
|
xml_attrs_present?(@ph, [['id'],
|
||||||
|
@ -79,54 +54,54 @@ module Epp::ContactsHelper
|
||||||
['postalInfo', 'addr', 'cc'],
|
['postalInfo', 'addr', 'cc'],
|
||||||
['authInfo']])
|
['authInfo']])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
## UPDATE
|
||||||
def validate_contact_update_request
|
def validate_contact_update_request
|
||||||
@ph = params_hash['epp']['command']['update']['update']
|
@ph = params_hash['epp']['command']['update']['update']
|
||||||
xml_attrs_present?(@ph, [['id'] ])
|
xml_attrs_present?(@ph, [['id'] ])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
## DELETE
|
||||||
def validate_contact_delete_request
|
def validate_contact_delete_request
|
||||||
@ph = params_hash['epp']['command']['delete']['delete']
|
@ph = params_hash['epp']['command']['delete']['delete']
|
||||||
xml_attrs_present?(@ph, [ ['id'] ] )
|
xml_attrs_present?(@ph, [ ['id'] ] )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
## CHECK
|
||||||
def validate_contact_check_request
|
def validate_contact_check_request
|
||||||
@ph = params_hash['epp']['command']['check']['check']
|
@ph = params_hash['epp']['command']['check']['check']
|
||||||
xml_attrs_present?(@ph, [ ['id'] ])
|
xml_attrs_present?(@ph, [ ['id'] ])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
## INFO
|
||||||
def validate_contact_info_request
|
def validate_contact_info_request
|
||||||
@ph = params_hash['epp']['command']['info']['info']
|
@ph = params_hash['epp']['command']['info']['info']
|
||||||
xml_attrs_present?(@ph, [ ['id'] ])
|
xml_attrs_present?(@ph, [ ['id'] ])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
## SHARED
|
||||||
|
|
||||||
def contact_and_address_attributes
|
def find_contact
|
||||||
ph = params_hash['epp']['command'][params[:command]][params[:command]]
|
contact = Contact.find_by(code: @ph[:id])
|
||||||
ph = ph[:chg] if params[:command] == 'update'
|
unless contact
|
||||||
contact_hash = {
|
epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'), value: { obj: 'id', val: @ph[:id] } }
|
||||||
code: ph[:id],
|
end
|
||||||
phone: ph[:voice],
|
contact
|
||||||
ident: ph[:ident],
|
end
|
||||||
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: 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
|
contact_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,20 @@
|
||||||
class Address < ActiveRecord::Base
|
class Address < ActiveRecord::Base
|
||||||
belongs_to :contact
|
belongs_to :contact
|
||||||
belongs_to :country
|
belongs_to :country
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def extract_attributes ah, type=:create
|
||||||
|
address_hash = {}
|
||||||
|
address_hash = ({
|
||||||
|
country_id: Country.find_by(iso: ah[:cc]).try(:id),
|
||||||
|
city: ah[:city],
|
||||||
|
street: ah[:street][0],
|
||||||
|
street2: ah[:street][1],
|
||||||
|
street3: ah[:street][2],
|
||||||
|
zip: ah[:pc]
|
||||||
|
}) if ah.is_a?(Hash)
|
||||||
|
|
||||||
|
address_hash.delete_if { |k, v| v.nil? }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -67,6 +67,25 @@ class Contact < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
|
def extract_attributes ph, type=:create
|
||||||
|
|
||||||
|
contact_hash = {
|
||||||
|
phone: ph[:voice],
|
||||||
|
ident: ph[:ident],
|
||||||
|
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[:code] = ph[:id] if type == :create
|
||||||
|
|
||||||
|
contact_hash.delete_if { |k, v| v.nil? }
|
||||||
|
end
|
||||||
|
|
||||||
def check_availability(codes)
|
def check_availability(codes)
|
||||||
codes = [codes] if codes.is_a?(String)
|
codes = [codes] if codes.is_a?(String)
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@ describe 'EPP Contact', epp: true do
|
||||||
|
|
||||||
expect(Contact.count).to eq(1)
|
expect(Contact.count).to eq(1)
|
||||||
expect(Contact.first.org_name).to eq('Example Inc.')
|
expect(Contact.first.org_name).to eq('Example Inc.')
|
||||||
|
expect(Contact.first.ident).to eq '37605030299'
|
||||||
|
expect(Contact.first.ident_type).to eq 'op'
|
||||||
|
|
||||||
expect(Contact.first.address.street).to eq('123 Example Dr.')
|
expect(Contact.first.address.street).to eq('123 Example Dr.')
|
||||||
expect(Contact.first.address.street2).to eq('Suite 100')
|
expect(Contact.first.address.street2).to eq('Suite 100')
|
||||||
|
@ -68,8 +70,8 @@ describe 'EPP Contact', epp: true do
|
||||||
|
|
||||||
context 'update command' do
|
context 'update command' do
|
||||||
it "fails if request is invalid" do
|
it "fails if request is invalid" do
|
||||||
#response = epp_request('contacts/update_missing_attr.xml')
|
response = epp_request('contacts/update_missing_attr.xml')
|
||||||
response = epp_request(contact_update_xml( {id: false} ), :xml)
|
#response = epp_request(contact_update_xml( {id: false} ), :xml)
|
||||||
|
|
||||||
expect(response[:results][0][:result_code]).to eq('2003')
|
expect(response[:results][0][:result_code]).to eq('2003')
|
||||||
expect(response[:results][0][:msg]).to eq('Required parameter missing: id')
|
expect(response[:results][0][:msg]).to eq('Required parameter missing: id')
|
||||||
|
@ -88,16 +90,20 @@ describe 'EPP Contact', epp: true do
|
||||||
|
|
||||||
it 'is succesful' do
|
it 'is succesful' do
|
||||||
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013')
|
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013')
|
||||||
response = epp_request(contact_update_xml( { chg: { email: 'fred@bloggers.ee', postalInfo: { name: 'Fred Bloggers' } } } ), :xml)
|
#response = epp_request(contact_update_xml( { chg: { email: 'fred@bloggers.ee', postalInfo: { name: 'Fred Bloggers' } } } ), :xml)
|
||||||
|
response = epp_request('contacts/update.xml')
|
||||||
|
|
||||||
expect(response[:msg]).to eq('Command completed successfully')
|
expect(response[:msg]).to eq('Command completed successfully')
|
||||||
expect(Contact.first.name).to eq('Fred Bloggers')
|
expect(Contact.first.name).to eq('John Doe')
|
||||||
expect(Contact.first.email).to eq('fred@bloggers.ee')
|
expect(Contact.first.email).to eq('jdoe@example.com')
|
||||||
|
expect(Contact.first.ident).to eq('J836954')
|
||||||
|
expect(Contact.first.ident_type).to eq('passport')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns phone and email error' do
|
it 'returns phone and email error' do
|
||||||
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013')
|
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013')
|
||||||
response = epp_request(contact_update_xml( { chg: { email: "qwe", phone: "123qweasd" } }), :xml)
|
#response = epp_request(contact_update_xml( { chg: { email: "qwe", phone: "123qweasd" } }), :xml)
|
||||||
|
response = epp_request('contacts/update_with_errors.xml')
|
||||||
|
|
||||||
expect(response[:results][0][:result_code]).to eq('2005')
|
expect(response[:results][0][:result_code]).to eq('2005')
|
||||||
expect(response[:results][0][:msg]).to eq('Phone nr is invalid')
|
expect(response[:results][0][:msg]).to eq('Phone nr is invalid')
|
||||||
|
@ -189,7 +195,8 @@ describe 'EPP Contact', epp: true do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'doesn\'t display unassociated object' do
|
it 'doesn\'t display unassociated object', pending: true do
|
||||||
|
pending 'until new contact rights systems is implemented'
|
||||||
Fabricate(:contact, name:"Johnny Awesome", created_by_id: '240', code: 'info-4444')
|
Fabricate(:contact, name:"Johnny Awesome", created_by_id: '240', code: 'info-4444')
|
||||||
Fabricate(:epp_user, id: 240)
|
Fabricate(:epp_user, id: 240)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<contact:voice x="1234">+123.7035555555</contact:voice>
|
<contact:voice x="1234">+123.7035555555</contact:voice>
|
||||||
<contact:fax>+1.7035555556</contact:fax>
|
<contact:fax>+1.7035555556</contact:fax>
|
||||||
<contact:email>jdoe@example.com</contact:email>
|
<contact:email>jdoe@example.com</contact:email>
|
||||||
<contact:ident type="op">37605030299</contact:ident>
|
<contact:ident type="passport">J836954</contact:ident>
|
||||||
<contact:authInfo>
|
<contact:authInfo>
|
||||||
<contact:pw>2fooBAR</contact:pw>
|
<contact:pw>2fooBAR</contact:pw>
|
||||||
</contact:authInfo>
|
</contact:authInfo>
|
||||||
|
|
4
spec/fabricators/country_fabricator.rb
Normal file
4
spec/fabricators/country_fabricator.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
Fabricator(:country) do
|
||||||
|
iso Faker::Address.state_abbr
|
||||||
|
name Faker::Address.country
|
||||||
|
end
|
|
@ -4,3 +4,19 @@ describe Address do
|
||||||
it { should belong_to(:contact) }
|
it { should belong_to(:contact) }
|
||||||
it { should belong_to(:country) }
|
it { should belong_to(:country) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
describe Address, '.extract_params' do
|
||||||
|
it 'returns params hash'do
|
||||||
|
Fabricate(:country, iso:'EE')
|
||||||
|
ph = { postalInfo: { name: "fred", addr: { cc: 'EE', city: 'Village', street: [ 'street1', 'street2' ] } } }
|
||||||
|
expect(Address.extract_attributes(ph[:postalInfo][:addr])).to eq( {
|
||||||
|
city: 'Village',
|
||||||
|
country_id: 1,
|
||||||
|
street: 'street1',
|
||||||
|
street2: 'street2'
|
||||||
|
} )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,18 @@ describe Contact, '#upID' do
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
describe Contact, '.extract_params' do
|
||||||
|
it 'returns params hash'do
|
||||||
|
ph = { id: '123123', email: 'jdoe@example.com', postalInfo: { name: "fred", addr: { cc: 'EE' } } }
|
||||||
|
expect(Contact.extract_attributes(ph)).to eq( {
|
||||||
|
code: '123123',
|
||||||
|
email: 'jdoe@example.com',
|
||||||
|
name: 'fred'
|
||||||
|
} )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
describe Contact, '.check_availability' do
|
describe Contact, '.check_availability' do
|
||||||
|
|
||||||
before(:each) {
|
before(:each) {
|
||||||
|
|
|
@ -58,7 +58,7 @@ module EppContactXmlBuilder
|
||||||
xml.tag!('contact:voice', (xml_params[:voice] || '+372.1234567')) unless xml_params[:voice] == false
|
xml.tag!('contact:voice', (xml_params[:voice] || '+372.1234567')) unless xml_params[:voice] == false
|
||||||
xml.tag!('contact:fax', (xml_params[:fax] || '123123' )) unless xml_params[:fax] == false
|
xml.tag!('contact:fax', (xml_params[:fax] || '123123' )) unless xml_params[:fax] == false
|
||||||
xml.tag!('contact:email', (xml_params[:email] || 'example@test.example')) unless xml_params[:email] == false
|
xml.tag!('contact:email', (xml_params[:email] || 'example@test.example')) unless xml_params[:email] == false
|
||||||
xml.tag!('contact:ident', (xml_params[:ident] || '37605030299')) unless xml_params[:ident] == false
|
xml.tag!('contact:ident', (xml_params[:ident] || '37605030299'), type: 'op') unless xml_params[:ident] == false
|
||||||
unless xml_params[:authInfo] == [false]
|
unless xml_params[:authInfo] == [false]
|
||||||
xml.tag!('contact:authInfo') do
|
xml.tag!('contact:authInfo') do
|
||||||
xml.tag!('contact:pw', xml_params[:authInfo][:pw] ) unless xml_params[:authInfo][:pw] == false
|
xml.tag!('contact:pw', xml_params[:authInfo][:pw] ) unless xml_params[:authInfo][:pw] == false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue