Merge branch 'master' of github.com:internetee/registry

This commit is contained in:
Martin Lensment 2014-08-05 17:19:31 +03:00
commit 38f0528d70
6 changed files with 25 additions and 35 deletions

View file

@ -1,17 +1,8 @@
module Epp::ContactsHelper module Epp::ContactsHelper
def create_contact def create_contact
ph = params_hash['epp']['command']['create']['create']
#todo, remove the first_or_initialize logic, since it's redundant due to
#<contact:id> from EPP api
@contact = Contact.new @contact = Contact.new( contact_and_address_attributes )
@contact = Contact.where(ident: ph[:ident]).first_or_initialize( new_contact_info ) if ph[:ident]
@contact.assign_attributes(name: ph[:postalInfo][:name])
@contact.addresses << new_address
stamp @contact stamp @contact
@contact.save @contact.save
render '/epp/contacts/create' render '/epp/contacts/create'
@ -66,24 +57,7 @@ module Epp::ContactsHelper
private private
def has_rights def contact_and_address_attributes
if @contact.created_by.registrar == current_epp_user.registrar
return true
end
return false
end
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 new_contact_info
ph = params_hash['epp']['command']['create']['create'] ph = params_hash['epp']['command']['create']['create']
{ {
code: ph[:id], code: ph[:id],
@ -91,8 +65,21 @@ module Epp::ContactsHelper
ident: ph[:ident], ident: ph[:ident],
ident_type: ident_type, ident_type: ident_type,
email: ph[:email], email: ph[:email],
org_name: ph[:postalInfo][:org] 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]
} }
}
end
def has_rights
if @contact.created_by.registrar == current_epp_user.registrar
return true
end
return false
end end
def tidy_street def tidy_street

View file

@ -2,13 +2,15 @@ class Contact < ActiveRecord::Base
#TODO Foreign contact will get email with activation link/username/temp password #TODO Foreign contact will get email with activation link/username/temp password
#TODO Phone number validation, in first phase very minimam in order to support current registries #TODO Phone number validation, in first phase very minimam in order to support current registries
has_many :addresses has_one :address
has_many :domain_contacts has_many :domain_contacts
has_many :domains, through: :domain_contacts has_many :domains, through: :domain_contacts
belongs_to :created_by, class_name: 'EppUser', foreign_key: :created_by_id belongs_to :created_by, class_name: 'EppUser', foreign_key: :created_by_id
belongs_to :updated_by, class_name: 'EppUser', foreign_key: :updated_by_id belongs_to :updated_by, class_name: 'EppUser', foreign_key: :updated_by_id
accepts_nested_attributes_for :address
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

View file

@ -10,8 +10,8 @@ xml.epp_head do
xml.tag!('contact:name', @contact.name) xml.tag!('contact:name', @contact.name)
xml.tag!('contact:org', @contact.org_name) xml.tag!('contact:org', @contact.org_name)
xml.tag!('contact:addr') do xml.tag!('contact:addr') do
xml.tag!('contact:street', @contact.addresses.first.street) xml.tag!('contact:street', @contact.address.street)
xml.tag!('contact:street', @contact.addresses.first.city) xml.tag!('contact:street', @contact.address.city)
end end
xml.tag!('contact:voice', @contact.phone) xml.tag!('contact:voice', @contact.phone)
xml.tag!('contact:fax', @contact.fax) xml.tag!('contact:fax', @contact.fax)

View file

@ -19,7 +19,8 @@ describe 'EPP Contact', epp: true do
expect(Contact.first.org_name).to eq('Example Inc.') expect(Contact.first.org_name).to eq('Example Inc.')
end end
it 'updates a contact with same ident' do it 'updates a contact with same ident', pending: true do
pending 'fixing this as soon as contact#update is done'
Fabricate(:contact) Fabricate(:contact)
response = epp_request('contacts/create.xml') response = epp_request('contacts/create.xml')
expect(response[:result_code]).to eq('1000') expect(response[:result_code]).to eq('1000')

View file

@ -5,5 +5,5 @@ Fabricator(:contact) do
ident '37605030299' ident '37605030299'
code 'sh8913' code 'sh8913'
ident_type 'op' ident_type 'op'
addresses(count: 2) address
end end

View file

@ -1,7 +1,7 @@
require "rails_helper" require "rails_helper"
describe Contact do describe Contact do
it { should have_many(:addresses) } it { should have_one(:address) }
context 'with invalid attribute' do context 'with invalid attribute' do
before(:each) { @contact = Fabricate(:contact) } before(:each) { @contact = Fabricate(:contact) }