mirror of
https://github.com/internetee/registry.git
synced 2025-07-26 04:28:27 +02:00
Merge branch 'master' of github.com:internetee/registry
This commit is contained in:
commit
5bb212ba24
6 changed files with 69 additions and 18 deletions
15
app/controllers/concerns/shared/user_stamper.rb
Normal file
15
app/controllers/concerns/shared/user_stamper.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
module Shared::UserStamper
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
def stamp obj
|
||||||
|
return false if obj.nil? || !obj.has_attribute?( :created_by_id && :updated_by_id )
|
||||||
|
|
||||||
|
if obj.new_record?
|
||||||
|
obj.created_by_id = current_epp_user.id
|
||||||
|
else
|
||||||
|
obj.updated_by_id = current_epp_user.id
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,6 +2,7 @@ class Epp::CommandsController < ApplicationController
|
||||||
include Epp::Common
|
include Epp::Common
|
||||||
include Epp::DomainsHelper
|
include Epp::DomainsHelper
|
||||||
include Epp::ContactsHelper
|
include Epp::ContactsHelper
|
||||||
|
include Shared::UserStamper
|
||||||
|
|
||||||
private
|
private
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -1,27 +1,19 @@
|
||||||
module Epp::ContactsHelper
|
module Epp::ContactsHelper
|
||||||
def create_contact
|
def create_contact
|
||||||
ph = params_hash['epp']['command']['create']['create']
|
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
|
||||||
|
|
||||||
ph[:ident] ? @contact = Contact.where(ident: ph[:ident]).first_or_initialize : @contact = Contact.new
|
@contact = Contact.new
|
||||||
if @contact.new_record?
|
@contact = Contact.where(ident: ph[:ident]).first_or_initialize( new_contact_info ) if ph[:ident]
|
||||||
@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(name: ph[:postalInfo][:name])
|
||||||
country_id: Country.find_by(iso: ph[:postalInfo][:cc]),
|
|
||||||
street: ph[:postalInfo][:street],
|
@contact.addresses << new_address
|
||||||
zip: ph[:postalInfo][:pc]
|
stamp @contact
|
||||||
)
|
|
||||||
|
|
||||||
@contact.save
|
@contact.save
|
||||||
|
|
||||||
render '/epp/contacts/create'
|
render '/epp/contacts/create'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -69,6 +61,35 @@ 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 new_contact_info
|
||||||
|
ph = params_hash['epp']['command']['create']['create']
|
||||||
|
{
|
||||||
|
code: ph[:id],
|
||||||
|
phone: ph[:voice],
|
||||||
|
ident: ph[:ident],
|
||||||
|
ident_type: ident_type,
|
||||||
|
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=)(.*)(?=<)/)
|
||||||
|
|
||||||
|
|
6
db/migrate/20140804095654_add_user_stamps_to_contact.rb
Normal file
6
db/migrate/20140804095654_add_user_stamps_to_contact.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class AddUserStampsToContact < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :contacts, :created_by_id, :integer
|
||||||
|
add_column :contacts, :updated_by_id, :integer
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20140801140249) do
|
ActiveRecord::Schema.define(version: 20140804095654) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -39,6 +39,8 @@ ActiveRecord::Schema.define(version: 20140801140249) do
|
||||||
t.string "ident"
|
t.string "ident"
|
||||||
t.string "ident_type"
|
t.string "ident_type"
|
||||||
t.string "org_name"
|
t.string "org_name"
|
||||||
|
t.integer "created_by_id"
|
||||||
|
t.integer "updated_by_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "countries", force: true do |t|
|
create_table "countries", force: true do |t|
|
||||||
|
|
|
@ -12,6 +12,8 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(response[:result_code]).to eq('1000')
|
expect(response[:result_code]).to eq('1000')
|
||||||
expect(response[:msg]).to eq('Command completed successfully')
|
expect(response[:msg]).to eq('Command completed successfully')
|
||||||
expect(response[:clTRID]).to eq('ABC-12345')
|
expect(response[:clTRID]).to eq('ABC-12345')
|
||||||
|
expect(Contact.first.created_by_id).to be 1
|
||||||
|
expect(Contact.first.updated_by_id).to be nil
|
||||||
|
|
||||||
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.')
|
||||||
|
@ -27,6 +29,10 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(Contact.first.name).to eq("John Doe")
|
expect(Contact.first.name).to eq("John Doe")
|
||||||
expect(Contact.first.ident_type).to eq("op")
|
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)
|
expect(Contact.count).to eq(1)
|
||||||
end
|
end
|
||||||
#TODO tests for missing/invalid/etc ident
|
#TODO tests for missing/invalid/etc ident
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue