models: stop saving IP addresses in version tables.
Mark various `creator_ip_addr` and `updater_ip_addr` columns as ignored and stop updating them in preparation for dropping them.
This commit is contained in:
@@ -38,7 +38,7 @@ class ForumPostsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@forum_post = authorize ForumPost.new(creator: CurrentUser.user, topic_id: params.dig(:forum_post, :topic_id))
|
||||
@forum_post = authorize ForumPost.new(creator: CurrentUser.user, creator_ip_addr: CurrentUser.ip_addr, topic_id: params.dig(:forum_post, :topic_id))
|
||||
@forum_post.update(permitted_attributes(@forum_post))
|
||||
|
||||
page = @forum_post.topic.last_page if @forum_post.topic.last_page > 1
|
||||
|
||||
@@ -56,9 +56,9 @@ class ForumTopicsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@forum_topic = authorize ForumTopic.new(permitted_attributes(ForumTopic))
|
||||
@forum_topic.creator = CurrentUser.user
|
||||
@forum_topic = authorize ForumTopic.new(creator: CurrentUser.user, **permitted_attributes(ForumTopic))
|
||||
@forum_topic.original_post.creator = CurrentUser.user
|
||||
@forum_topic.original_post.creator_ip_addr = CurrentUser.ip_addr
|
||||
@forum_topic.save
|
||||
|
||||
respond_with(@forum_topic)
|
||||
|
||||
@@ -5,12 +5,12 @@ class UploadsController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token, only: [:create], if: -> { request.xhr? }
|
||||
|
||||
def new
|
||||
@upload = authorize Upload.new(uploader: CurrentUser.user, uploader_ip_addr: CurrentUser.ip_addr, source: params[:url], referer_url: params[:ref], **permitted_attributes(Upload))
|
||||
@upload = authorize Upload.new(uploader: CurrentUser.user, source: params[:url], referer_url: params[:ref], **permitted_attributes(Upload))
|
||||
respond_with(@upload)
|
||||
end
|
||||
|
||||
def create
|
||||
@upload = authorize Upload.new(uploader: CurrentUser.user, uploader_ip_addr: CurrentUser.ip_addr, **permitted_attributes(Upload))
|
||||
@upload = authorize Upload.new(uploader: CurrentUser.user, **permitted_attributes(Upload))
|
||||
@upload.save
|
||||
respond_with(@upload)
|
||||
end
|
||||
|
||||
@@ -65,14 +65,14 @@ class SpamDetector
|
||||
# Initialize a spam check for a message.
|
||||
# @param record [Dmail, ForumPost, Comment] the message to spam check
|
||||
# @param user_ip [String] the IP address of the user who posted the message
|
||||
def initialize(record, user_ip: nil)
|
||||
def initialize(record, user_ip:)
|
||||
case record
|
||||
when Dmail
|
||||
@record = record
|
||||
@user = record.from
|
||||
@content = record.body
|
||||
@comment_type = "message"
|
||||
@user_ip = user_ip || record.creator_ip_addr.to_s
|
||||
@user_ip = user_ip
|
||||
when ForumPost
|
||||
@record = record
|
||||
@user = record.creator
|
||||
@@ -84,7 +84,7 @@ class SpamDetector
|
||||
@user = record.creator
|
||||
@content = record.body
|
||||
@comment_type = "comment"
|
||||
@user_ip = user_ip || record.creator_ip_addr.to_s
|
||||
@user_ip = user_ip
|
||||
else
|
||||
raise ArgumentError
|
||||
end
|
||||
|
||||
@@ -191,7 +191,6 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
belongs_to :updater, class_name: "User", **options
|
||||
before_validation do |rec|
|
||||
rec.updater_id = CurrentUser.id
|
||||
rec.updater_ip_addr = CurrentUser.ip_addr if rec.respond_to?(:updater_ip_addr=)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -111,7 +111,6 @@ class Artist < ApplicationRecord
|
||||
:artist_id => id,
|
||||
:name => name,
|
||||
:updater_id => CurrentUser.id,
|
||||
:updater_ip_addr => CurrentUser.ip_addr,
|
||||
:urls => url_array,
|
||||
:is_deleted => is_deleted,
|
||||
:is_banned => is_banned,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ArtistCommentaryVersion < ApplicationRecord
|
||||
self.ignored_columns = [:updater_ip_addr]
|
||||
|
||||
belongs_to :post
|
||||
belongs_to_updater
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ArtistVersion < ApplicationRecord
|
||||
self.ignored_columns = [:updater_ip_addr]
|
||||
|
||||
array_attribute :urls
|
||||
array_attribute :other_names
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Comment < ApplicationRecord
|
||||
self.ignored_columns = [:creator_ip_addr, :updater_ip_addr]
|
||||
|
||||
attr_accessor :creator_ip_addr
|
||||
|
||||
belongs_to :post
|
||||
belongs_to :creator, class_name: "User"
|
||||
belongs_to_updater
|
||||
@@ -52,7 +56,7 @@ class Comment < ApplicationRecord
|
||||
extend SearchMethods
|
||||
|
||||
def autoreport_spam
|
||||
if SpamDetector.new(self).spam?
|
||||
if SpamDetector.new(self, user_ip: creator_ip_addr).spam?
|
||||
moderation_reports << ModerationReport.new(creator: User.system, reason: "Spam.")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Dmail < ApplicationRecord
|
||||
self.ignored_columns = [:creator_ip_addr]
|
||||
|
||||
attr_accessor :creator_ip_addr
|
||||
|
||||
validate :validate_sender_is_not_limited, on: :create
|
||||
validates :title, presence: true, length: { maximum: 200 }, if: :title_changed?
|
||||
validates :body, presence: true, length: { maximum: 50_000 }, if: :body_changed?
|
||||
@@ -52,7 +56,7 @@ class Dmail < ApplicationRecord
|
||||
end
|
||||
|
||||
def create_automated(params)
|
||||
dmail = Dmail.new(from: User.system, creator_ip_addr: "127.0.0.1", **params)
|
||||
dmail = Dmail.new(from: User.system, **params)
|
||||
dmail.owner = dmail.to
|
||||
dmail.save
|
||||
dmail
|
||||
@@ -171,7 +175,7 @@ class Dmail < ApplicationRecord
|
||||
end
|
||||
|
||||
def autoreport_spam
|
||||
if is_recipient? && !is_sender? && SpamDetector.new(self).spam?
|
||||
if is_recipient? && !is_sender? && SpamDetector.new(self, user_ip: creator_ip_addr).spam?
|
||||
self.is_deleted = true
|
||||
moderation_reports << ModerationReport.new(creator: User.system, reason: "Spam.")
|
||||
end
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
class ForumPost < ApplicationRecord
|
||||
attr_readonly :topic_id
|
||||
attr_accessor :creator_ip_addr
|
||||
|
||||
belongs_to :creator, class_name: "User"
|
||||
belongs_to_updater
|
||||
@@ -97,7 +98,7 @@ class ForumPost < ApplicationRecord
|
||||
end
|
||||
|
||||
def autoreport_spam
|
||||
if SpamDetector.new(self, user_ip: CurrentUser.ip_addr).spam?
|
||||
if SpamDetector.new(self, user_ip: creator_ip_addr).spam?
|
||||
moderation_reports << ModerationReport.new(creator: User.system, reason: "Spam.")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,7 +54,7 @@ class Note < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def create_version(updater: CurrentUser.user, updater_ip_addr: CurrentUser.ip_addr)
|
||||
def create_version(updater: CurrentUser.user)
|
||||
return unless saved_change_to_versioned_attributes?
|
||||
|
||||
if merge_version?(updater.id)
|
||||
@@ -62,7 +62,7 @@ class Note < ApplicationRecord
|
||||
else
|
||||
Note.where(:id => id).update_all("version = coalesce(version, 0) + 1")
|
||||
reload
|
||||
create_new_version(updater.id, updater_ip_addr)
|
||||
create_new_version(updater.id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,10 +70,9 @@ class Note < ApplicationRecord
|
||||
new_record? || saved_change_to_x? || saved_change_to_y? || saved_change_to_width? || saved_change_to_height? || saved_change_to_is_active? || saved_change_to_body?
|
||||
end
|
||||
|
||||
def create_new_version(updater_id, updater_ip_addr)
|
||||
def create_new_version(updater_id)
|
||||
versions.create(
|
||||
:updater_id => updater_id,
|
||||
:updater_ip_addr => updater_ip_addr,
|
||||
:post_id => post_id,
|
||||
:x => x,
|
||||
:y => y,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class NoteVersion < ApplicationRecord
|
||||
self.ignored_columns = [:updater_ip_addr]
|
||||
|
||||
belongs_to :post
|
||||
belongs_to :note
|
||||
belongs_to_updater :counter_cache => "note_update_count"
|
||||
|
||||
@@ -220,9 +220,9 @@ class Pool < ApplicationRecord
|
||||
post_count > 0 ? Post.find(post_ids.first) : nil
|
||||
end
|
||||
|
||||
def create_version(updater: CurrentUser.user, updater_ip_addr: CurrentUser.ip_addr)
|
||||
def create_version(updater: CurrentUser.user)
|
||||
if PoolVersion.enabled?
|
||||
PoolVersion.queue(self, updater, updater_ip_addr)
|
||||
PoolVersion.queue(self, updater)
|
||||
else
|
||||
Rails.logger.warn("Archive service is not configured. Pool versions will not be saved.")
|
||||
end
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PoolVersion < ApplicationRecord
|
||||
self.ignored_columns = [:updater_ip_addr]
|
||||
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to :pool
|
||||
|
||||
@@ -64,7 +66,7 @@ class PoolVersion < ApplicationRecord
|
||||
SqsService.new(Danbooru.config.aws_sqs_archives_url)
|
||||
end
|
||||
|
||||
def self.queue(pool, updater, updater_ip_addr)
|
||||
def self.queue(pool, updater)
|
||||
# queue updates to sqs so that if archives goes down for whatever reason it won't
|
||||
# block pool updates
|
||||
raise NotImplementedError, "Archive service is not configured." if !enabled?
|
||||
@@ -73,7 +75,6 @@ class PoolVersion < ApplicationRecord
|
||||
pool_id: pool.id,
|
||||
post_ids: pool.post_ids,
|
||||
updater_id: updater.id,
|
||||
updater_ip_addr: updater_ip_addr.to_s,
|
||||
created_at: pool.created_at.try(:iso8601),
|
||||
updated_at: pool.updated_at.try(:iso8601),
|
||||
description: pool.description,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Post < ApplicationRecord
|
||||
self.ignored_columns = [:uploader_ip_addr]
|
||||
|
||||
class RevertError < StandardError; end
|
||||
class DeletionError < StandardError; end
|
||||
|
||||
@@ -109,7 +111,6 @@ class Post < ApplicationRecord
|
||||
|
||||
post = Post.new(
|
||||
uploader: upload.uploader,
|
||||
uploader_ip_addr: upload.uploader_ip_addr,
|
||||
md5: media_asset&.md5,
|
||||
file_ext: media_asset&.file_ext,
|
||||
file_size: media_asset&.file_size,
|
||||
@@ -1420,7 +1421,7 @@ class Post < ApplicationRecord
|
||||
:image_height, :tag_count, :has_children, :has_active_children,
|
||||
:is_pending, :is_flagged, :is_deleted, :is_banned,
|
||||
:last_comment_bumped_at, :last_commented_at, :last_noted_at,
|
||||
:uploader_ip_addr, :uploader, :approver, :parent,
|
||||
:uploader, :approver, :parent,
|
||||
:artist_commentary, :flags, :appeals, :notes, :comments, :children,
|
||||
:approvals, :replacements, :pixiv_ugoira_frame_data
|
||||
)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PostVersion < ApplicationRecord
|
||||
self.ignored_columns = [:updater_ip_addr]
|
||||
|
||||
class RevertError < StandardError; end
|
||||
extend Memoist
|
||||
|
||||
@@ -91,7 +93,6 @@ class PostVersion < ApplicationRecord
|
||||
"parent_id" => post.parent_id,
|
||||
"source" => post.source,
|
||||
"updater_id" => CurrentUser.id,
|
||||
"updater_ip_addr" => CurrentUser.ip_addr.to_s,
|
||||
"updated_at" => post.updated_at.try(:iso8601),
|
||||
"created_at" => post.created_at.try(:iso8601),
|
||||
"tags" => post.tag_string,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Upload < ApplicationRecord
|
||||
self.ignored_columns = [:uploader_ip_addr]
|
||||
|
||||
extend Memoist
|
||||
class Error < StandardError; end
|
||||
|
||||
|
||||
@@ -185,7 +185,6 @@ class WikiPage < ApplicationRecord
|
||||
def create_new_version
|
||||
versions.create(
|
||||
:updater_id => CurrentUser.id,
|
||||
:updater_ip_addr => CurrentUser.ip_addr,
|
||||
:title => title,
|
||||
:body => body,
|
||||
:is_locked => is_locked,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WikiPageVersion < ApplicationRecord
|
||||
self.ignored_columns = [:updater_ip_addr]
|
||||
|
||||
array_attribute :other_names
|
||||
belongs_to :wiki_page
|
||||
belongs_to_updater
|
||||
|
||||
Reference in New Issue
Block a user