From 9b0efe9c845c7bb8f9e9fd809660cc758ab18db6 Mon Sep 17 00:00:00 2001 From: riking Date: Mon, 21 May 2018 12:04:55 -0700 Subject: [PATCH] FIX: TopicLinkClick: do not log IP of logged in users --- app/models/topic_link_click.rb | 4 ++-- .../20180521190040_allow_null_ip_topic_link_click.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20180521190040_allow_null_ip_topic_link_click.rb diff --git a/app/models/topic_link_click.rb b/app/models/topic_link_click.rb index ce0f7fcbe18..422c974bfdc 100644 --- a/app/models/topic_link_click.rb +++ b/app/models/topic_link_click.rb @@ -7,7 +7,6 @@ class TopicLinkClick < ActiveRecord::Base belongs_to :user validates_presence_of :topic_link_id - validates_presence_of :ip_address WHITELISTED_REDIRECT_HOSTNAMES = Set.new(%W{www.youtube.com youtu.be}) @@ -108,6 +107,7 @@ class TopicLinkClick < ActiveRecord::Base rate_key = "link-clicks:#{link.id}:#{args[:user_id] || args[:ip]}" if $redis.setnx(rate_key, "1") $redis.expire(rate_key, 1.day.to_i) + args[:ip] = nil if args[:user_id] create!(topic_link_id: link.id, user_id: args[:user_id], ip_address: args[:ip]) end @@ -125,7 +125,7 @@ end # user_id :integer # created_at :datetime not null # updated_at :datetime not null -# ip_address :inet not null +# ip_address :inet # # Indexes # diff --git a/db/migrate/20180521190040_allow_null_ip_topic_link_click.rb b/db/migrate/20180521190040_allow_null_ip_topic_link_click.rb new file mode 100644 index 00000000000..b9f29e1aa84 --- /dev/null +++ b/db/migrate/20180521190040_allow_null_ip_topic_link_click.rb @@ -0,0 +1,10 @@ +class AllowNullIpTopicLinkClick < ActiveRecord::Migration[5.1] + def up + begin + Migration::SafeMigrate.disable! + change_column :topic_link_clicks, :ip_address, :inet, null: true + ensure + Migration::SafeMigrate.enable! + end + end +end