# frozen_string_literal: true # == Schema Information # # Table name: source_changes # # id :integer not null, primary key # fingerprint :string # initial :boolean default(FALSE), not null # ip :inet not null # new_value :string # referrer :string default("") # user_agent :string default("") # created_at :datetime not null # updated_at :datetime not null # post_id :integer not null # user_id :integer # # Indexes # # index_source_changes_on_ip (ip) # index_source_changes_on_post_id (post_id) # index_source_changes_on_user_id (user_id) # # Foreign Keys # # fk_rails_... (post_id => posts.id) # fk_rails_... (user_id => users.id) ON DELETE => nullify ON UPDATE => cascade # class SourceChange < ApplicationRecord include UserAttributable belongs_to :post def user_visible? super && !(post.anonymous && post.uploader_is?(user, ip)) end def self.add_to_img(img, updating_user, request, initial: false) if img.previous_changes.include? 'source_url' SourceChange.create(ip: request.remote_ip, user: updating_user, post: img, new_value: img.source_url, initial: initial) end end def as_json { id: id, post_id: post_id, initial: initial, value: new_value, user: author } end delegate :id, to: :parent, prefix: true alias parent post end