From 76ea1389e63458714a13a58c76f7492426ffa4fd Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 19 May 2015 17:25:47 +0300 Subject: [PATCH] Add logging to white ip --- app/models/version/white_ip_version.rb | 5 ++ app/models/white_ip.rb | 7 ++- app/views/admin/white_ips/_form.haml | 4 +- .../20150519140853_create_white_ip_log.rb | 18 ++++++++ db/schema.rb | 16 ++++++- spec/fabricators/white_ip_fabricator.rb | 4 ++ spec/models/white_ip_spec.rb | 46 +++++++++---------- 7 files changed, 73 insertions(+), 27 deletions(-) create mode 100644 app/models/version/white_ip_version.rb create mode 100644 db/migrate/20150519140853_create_white_ip_log.rb create mode 100644 spec/fabricators/white_ip_fabricator.rb diff --git a/app/models/version/white_ip_version.rb b/app/models/version/white_ip_version.rb new file mode 100644 index 000000000..0f2ee8a53 --- /dev/null +++ b/app/models/version/white_ip_version.rb @@ -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 diff --git a/app/models/white_ip.rb b/app/models/white_ip.rb index 04ca14ffb..f71a9aaf3 100644 --- a/app/models/white_ip.rb +++ b/app/models/white_ip.rb @@ -1,4 +1,5 @@ class WhiteIp < ActiveRecord::Base + include Versions belongs_to :registrar # rubocop: disable Metrics/LineLength @@ -12,5 +13,9 @@ class WhiteIp < ActiveRecord::Base errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present)) end - INTERFACES = ['epp', 'repp', 'registrar'] + INTERFACE_EPP = 'epp' + INTERFACE_REPP = 'repp' + INTERFACE_REGISTRAR = 'registrar' + + INTERFACES = [INTERFACE_EPP, INTERFACE_REPP, INTERFACE_REGISTRAR] end diff --git a/app/views/admin/white_ips/_form.haml b/app/views/admin/white_ips/_form.haml index e496348ba..f9bb48376 100644 --- a/app/views/admin/white_ips/_form.haml +++ b/app/views/admin/white_ips/_form.haml @@ -13,12 +13,12 @@ .col-md-4.control-label = f.label :ipv4 .col-md-7 - = f.text_field(:ipv4, class: 'form-control') + = f.text_field(:ipv4, class: 'form-control', ipv4: true) .form-group .col-md-4.control-label = f.label :ipv6 .col-md-7 - = f.text_field(:ipv6, class: 'form-control') + = f.text_field(:ipv6, class: 'form-control', ipv6: true) .form-group .col-md-4.control-label = f.label :interface diff --git a/db/migrate/20150519140853_create_white_ip_log.rb b/db/migrate/20150519140853_create_white_ip_log.rb new file mode 100644 index 000000000..b5f1e6e0b --- /dev/null +++ b/db/migrate/20150519140853_create_white_ip_log.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 16cf3d6fd..2b23859cc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # 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 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", ["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| t.string "item_type", null: false t.integer "item_id", null: false @@ -935,6 +947,8 @@ ActiveRecord::Schema.define(version: 20150519115050) do t.string "interface" t.datetime "created_at" t.datetime "updated_at" + t.string "creator_str" + t.string "updator_str" end create_table "whois_records", force: :cascade do |t| diff --git a/spec/fabricators/white_ip_fabricator.rb b/spec/fabricators/white_ip_fabricator.rb new file mode 100644 index 000000000..2508fe4cf --- /dev/null +++ b/spec/fabricators/white_ip_fabricator.rb @@ -0,0 +1,4 @@ +Fabricator(:white_ip) do + ipv4 '192.168.1.1' + interface WhiteIp::INTERFACE_EPP +end diff --git a/spec/models/white_ip_spec.rb b/spec/models/white_ip_spec.rb index ce16780f8..7c169c539 100644 --- a/spec/models/white_ip_spec.rb +++ b/spec/models/white_ip_spec.rb @@ -25,30 +25,30 @@ describe WhiteIp do end end - # context 'with valid attributes' do - # before :all do - # @white_ip = Fabricate(:white_ip) - # end + context 'with valid attributes' do + before :all do + @white_ip = Fabricate(:white_ip) + end - # it 'should be valid' do - # @white_ip.valid? - # @white_ip.errors.full_messages.should match_array([]) - # end + it 'should be valid' do + @white_ip.valid? + @white_ip.errors.full_messages.should match_array([]) + end - # it 'should be valid twice' do - # @white_ip = Fabricate(:white_ip) - # @white_ip.valid? - # @white_ip.errors.full_messages.should match_array([]) - # end + it 'should be valid twice' do + @white_ip = Fabricate(:white_ip) + @white_ip.valid? + @white_ip.errors.full_messages.should match_array([]) + end - # it 'should have one version' do - # with_versioning do - # @white_ip.versions.should == [] - # @white_ip.ipv4 = '192.168.1.1' - # @white_ip.save - # @white_ip.errors.full_messages.should match_array([]) - # @white_ip.versions.size.should == 1 - # end - # end - # end + it 'should have one version' do + with_versioning do + @white_ip.versions.should == [] + @white_ip.ipv4 = '192.168.1.2' + @white_ip.save + @white_ip.errors.full_messages.should match_array([]) + @white_ip.versions.size.should == 1 + end + end + end end