Added general user stamping on contact

This commit is contained in:
Andres Keskküla 2014-08-04 13:15:54 +03:00
parent 86dc8321c6
commit 8ce1875484
6 changed files with 33 additions and 1 deletions

View 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

View file

@ -2,6 +2,7 @@ class Epp::CommandsController < ApplicationController
include Epp::Common
include Epp::DomainsHelper
include Epp::ContactsHelper
include Shared::UserStamper
private
def create

View file

@ -21,6 +21,8 @@ module Epp::ContactsHelper
zip: ph[:postalInfo][:pc]
)
stamp @contact
@contact.save
render '/epp/contacts/create'
end

View 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

View file

@ -11,7 +11,7 @@
#
# 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
enable_extension "plpgsql"
@ -39,6 +39,8 @@ ActiveRecord::Schema.define(version: 20140801140249) do
t.string "ident"
t.string "ident_type"
t.string "org_name"
t.integer "created_by_id"
t.integer "updated_by_id"
end
create_table "countries", force: true do |t|

View file

@ -12,6 +12,8 @@ describe 'EPP Contact', epp: true do
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.created_by_id).to be 1
expect(Contact.first.updated_by_id).to be nil
expect(Contact.count).to eq(1)
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.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