Add logging to white ip

This commit is contained in:
Martin Lensment 2015-05-19 17:25:47 +03:00
parent 8e37355e13
commit 76ea1389e6
7 changed files with 73 additions and 27 deletions

View file

@ -0,0 +1,5 @@
class WhiteIpVersion < PaperTrail::Version
include VersionSession
self.table_name = :log_white_ips
self.sequence_name = :log_white_ips_id_seq
end

View file

@ -1,4 +1,5 @@
class WhiteIp < ActiveRecord::Base class WhiteIp < ActiveRecord::Base
include Versions
belongs_to :registrar belongs_to :registrar
# rubocop: disable Metrics/LineLength # rubocop: disable Metrics/LineLength
@ -12,5 +13,9 @@ class WhiteIp < ActiveRecord::Base
errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present)) errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present))
end end
INTERFACES = ['epp', 'repp', 'registrar'] INTERFACE_EPP = 'epp'
INTERFACE_REPP = 'repp'
INTERFACE_REGISTRAR = 'registrar'
INTERFACES = [INTERFACE_EPP, INTERFACE_REPP, INTERFACE_REGISTRAR]
end end

View file

@ -13,12 +13,12 @@
.col-md-4.control-label .col-md-4.control-label
= f.label :ipv4 = f.label :ipv4
.col-md-7 .col-md-7
= f.text_field(:ipv4, class: 'form-control') = f.text_field(:ipv4, class: 'form-control', ipv4: true)
.form-group .form-group
.col-md-4.control-label .col-md-4.control-label
= f.label :ipv6 = f.label :ipv6
.col-md-7 .col-md-7
= f.text_field(:ipv6, class: 'form-control') = f.text_field(:ipv6, class: 'form-control', ipv6: true)
.form-group .form-group
.col-md-4.control-label .col-md-4.control-label
= f.label :interface = f.label :interface

View file

@ -0,0 +1,18 @@
class CreateWhiteIpLog < ActiveRecord::Migration
def change
create_table :log_white_ips do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
t.string "session"
t.json "children"
end
add_column :white_ips, :creator_str, :string
add_column :white_ips, :updator_str, :string
end
end

View file

@ -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: 20150519115050) do ActiveRecord::Schema.define(version: 20150519140853) 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"
@ -797,6 +797,18 @@ ActiveRecord::Schema.define(version: 20150519115050) do
add_index "log_users", ["item_type", "item_id"], name: "index_log_users_on_item_type_and_item_id", using: :btree add_index "log_users", ["item_type", "item_id"], name: "index_log_users_on_item_type_and_item_id", using: :btree
add_index "log_users", ["whodunnit"], name: "index_log_users_on_whodunnit", using: :btree add_index "log_users", ["whodunnit"], name: "index_log_users_on_whodunnit", using: :btree
create_table "log_white_ips", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
t.string "session"
t.json "children"
end
create_table "log_zonefile_settings", force: :cascade do |t| create_table "log_zonefile_settings", force: :cascade do |t|
t.string "item_type", null: false t.string "item_type", null: false
t.integer "item_id", null: false t.integer "item_id", null: false
@ -935,6 +947,8 @@ ActiveRecord::Schema.define(version: 20150519115050) do
t.string "interface" t.string "interface"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "creator_str"
t.string "updator_str"
end end
create_table "whois_records", force: :cascade do |t| create_table "whois_records", force: :cascade do |t|

View file

@ -0,0 +1,4 @@
Fabricator(:white_ip) do
ipv4 '192.168.1.1'
interface WhiteIp::INTERFACE_EPP
end

View file

@ -25,30 +25,30 @@ describe WhiteIp do
end end
end end
# context 'with valid attributes' do context 'with valid attributes' do
# before :all do before :all do
# @white_ip = Fabricate(:white_ip) @white_ip = Fabricate(:white_ip)
# end end
# it 'should be valid' do it 'should be valid' do
# @white_ip.valid? @white_ip.valid?
# @white_ip.errors.full_messages.should match_array([]) @white_ip.errors.full_messages.should match_array([])
# end end
# it 'should be valid twice' do it 'should be valid twice' do
# @white_ip = Fabricate(:white_ip) @white_ip = Fabricate(:white_ip)
# @white_ip.valid? @white_ip.valid?
# @white_ip.errors.full_messages.should match_array([]) @white_ip.errors.full_messages.should match_array([])
# end end
# it 'should have one version' do it 'should have one version' do
# with_versioning do with_versioning do
# @white_ip.versions.should == [] @white_ip.versions.should == []
# @white_ip.ipv4 = '192.168.1.1' @white_ip.ipv4 = '192.168.1.2'
# @white_ip.save @white_ip.save
# @white_ip.errors.full_messages.should match_array([]) @white_ip.errors.full_messages.should match_array([])
# @white_ip.versions.size.should == 1 @white_ip.versions.size.should == 1
# end end
# end end
# end end
end end