Add target_user field to anonymous blocks

This commit is contained in:
Andreas Nedbal 2022-12-27 02:26:06 +01:00 committed by Andreas Nedbal
parent 481f3c4d8f
commit e7f60acad5
3 changed files with 13 additions and 3 deletions

View File

@ -5,6 +5,7 @@ require "digest"
class AnonymousBlock < ApplicationRecord class AnonymousBlock < ApplicationRecord
belongs_to :user, optional: true belongs_to :user, optional: true
belongs_to :question, optional: true belongs_to :question, optional: true
belongs_to :target_user, class_name: "User", optional: true
def self.get_identifier(ip) def self.get_identifier(ip)
Digest::SHA2.new(512).hexdigest(Rails.application.secret_key_base + ip) Digest::SHA2.new(512).hexdigest(Rails.application.secret_key_base + ip)

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddTargetUserToAnonymousBlocks < ActiveRecord::Migration[6.1]
def change
add_reference :anonymous_blocks, :target_user, null: true, foreign_key: { to_table: :users }
end
end

View File

@ -10,7 +10,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: 2022_11_16_201723) do ActiveRecord::Schema.define(version: 2022_12_27_002012) 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"
@ -28,13 +28,15 @@ ActiveRecord::Schema.define(version: 2022_11_16_201723) do
end end
create_table "anonymous_blocks", force: :cascade do |t| create_table "anonymous_blocks", force: :cascade do |t|
t.bigint "user_id"
t.string "identifier" t.string "identifier"
t.bigint "question_id", null: false
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.bigint "user_id" t.bigint "target_user_id"
t.bigint "question_id"
t.index ["identifier"], name: "index_anonymous_blocks_on_identifier" t.index ["identifier"], name: "index_anonymous_blocks_on_identifier"
t.index ["question_id"], name: "index_anonymous_blocks_on_question_id" t.index ["question_id"], name: "index_anonymous_blocks_on_question_id"
t.index ["target_user_id"], name: "index_anonymous_blocks_on_target_user_id"
t.index ["user_id"], name: "index_anonymous_blocks_on_user_id" t.index ["user_id"], name: "index_anonymous_blocks_on_user_id"
end end