mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 18:29:40 +02:00
Basic contact check command implementation
This commit is contained in:
parent
65bb5166cc
commit
1f29925004
6 changed files with 106 additions and 0 deletions
|
@ -40,4 +40,17 @@ module Epp::ContactsHelper
|
|||
render '/epp/error'
|
||||
end
|
||||
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
|
||||
@code = '2303'
|
||||
@msg = "Object does not exist"
|
||||
render 'epp/error'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,4 +14,22 @@ class Contact < ActiveRecord::Base
|
|||
code = Isikukood.new(ident)
|
||||
errors.add(:ident, 'bad format') unless code.valid?
|
||||
end
|
||||
|
||||
class << self
|
||||
def check_availability(codes)
|
||||
codes = [codes] if codes.is_a?(String)
|
||||
|
||||
res = []
|
||||
codes.each do |x|
|
||||
if Contact.find_by(code: x)
|
||||
res << {code: x, avail: 0, reason: 'in use'}
|
||||
else
|
||||
res << {code: x, avail: 1}
|
||||
end
|
||||
end
|
||||
|
||||
res
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
22
app/views/epp/contacts/check.xml.builder
Normal file
22
app/views/epp/contacts/check.xml.builder
Normal file
|
@ -0,0 +1,22 @@
|
|||
xml.epp_head do
|
||||
xml.response do
|
||||
xml.result('code' => '1000') do
|
||||
xml.msg 'Command completed successfully'
|
||||
end
|
||||
|
||||
xml.resData do
|
||||
xml.tag!('contact:chkData', '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)
|
||||
@contacts.each do |contact|
|
||||
xml.tag!('contact:cd') do
|
||||
xml.tag! "contact:id", contact[:code], avail: contact[:avail]
|
||||
xml.tag!('contact:reason', contact[:reason]) unless contact[:avail] == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
xml << render('/epp/shared/trID')
|
||||
end
|
||||
end
|
|
@ -45,6 +45,16 @@ describe 'EPP Contact', epp: true do
|
|||
expect(response[:msg]).to eq('Object does not exist')
|
||||
end
|
||||
|
||||
it 'checks contacts' do
|
||||
Fabricate(:contact)
|
||||
Fabricate(:contact, id:'sh8914')
|
||||
|
||||
response = epp_request('contacts/check.xml')
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
expect(response[:msg]).to eq('Command completed successfully')
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
13
spec/epp/requests/contacts/check.xml
Normal file
13
spec/epp/requests/contacts/check.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<check>
|
||||
<contact:check
|
||||
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
|
||||
<contact:id>sh8913</contact:id>
|
||||
<contact:id>sh8914</contact:id>
|
||||
</contact:check>
|
||||
</check>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -25,3 +25,33 @@ describe Contact do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe Contact, '.check_availability' do
|
||||
|
||||
before(:each) {
|
||||
Fabricate(:contact, code: "asd12")
|
||||
Fabricate(:contact, code: "asd13")
|
||||
}
|
||||
|
||||
it 'should return array if argument is string' do
|
||||
response = Contact.check_availability("asd12")
|
||||
expect(response.class).to be Array
|
||||
expect(response.length).to eq(1)
|
||||
end
|
||||
|
||||
it 'should return in_use and available codes' do
|
||||
response = Contact.check_availability(["asd12","asd13","asd14"])
|
||||
expect(response.class).to be Array
|
||||
expect(response.length).to eq(3)
|
||||
|
||||
expect(response[0][:avail]).to eq(0)
|
||||
expect(response[0][:code]).to eq("asd12")
|
||||
|
||||
expect(response[1][:avail]).to eq(0)
|
||||
expect(response[1][:code]).to eq("asd13")
|
||||
|
||||
expect(response[2][:avail]).to eq(1)
|
||||
expect(response[2][:code]).to eq("asd14")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue