From 1a68c1b46f11eabb64715246dfd8925f71168e24 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 14 Jun 2022 16:11:00 +0200 Subject: [PATCH] Rename `author_email` field to `author_identifier` --- app/controllers/ajax/question_controller.rb | 8 +++++--- ...1_rename_author_email_to_author_identifier.rb | 5 +++++ db/schema.rb | 16 ++++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20220613221551_rename_author_email_to_author_identifier.rb diff --git a/app/controllers/ajax/question_controller.rb b/app/controllers/ajax/question_controller.rb index 0df36d3f..a3245e0c 100644 --- a/app/controllers/ajax/question_controller.rb +++ b/app/controllers/ajax/question_controller.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "digest" require "errors" class Ajax::QuestionController < AjaxController @@ -34,10 +35,11 @@ class Ajax::QuestionController < AjaxController is_never_anonymous = user_signed_in? && params[:rcpt] == 'followers' begin - question = Question.create!(content: params[:question], + question = Question.create!(content: params[:question], author_is_anonymous: is_never_anonymous ? false : params[:anonymousQuestion], - user: current_user, - direct: params[:rcpt] != 'followers') + author_identifier: Digest::SHA2.new(512).hexdigest(Rails.application.secret_key_base + request.ip), + user: current_user, + direct: params[:rcpt] != 'followers') rescue ActiveRecord::RecordInvalid => e Sentry.capture_exception(e) @response[:status] = :rec_inv diff --git a/db/migrate/20220613221551_rename_author_email_to_author_identifier.rb b/db/migrate/20220613221551_rename_author_email_to_author_identifier.rb new file mode 100644 index 00000000..17759871 --- /dev/null +++ b/db/migrate/20220613221551_rename_author_email_to_author_identifier.rb @@ -0,0 +1,5 @@ +class RenameAuthorEmailToAuthorIdentifier < ActiveRecord::Migration[6.1] + def change + rename_column :questions, :author_email, :author_identifier + end +end diff --git a/db/schema.rb b/db/schema.rb index fd2028e3..15457d1c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_04_15_193829) do +ActiveRecord::Schema.define(version: 2022_06_13_221551) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -39,6 +39,18 @@ ActiveRecord::Schema.define(version: 2022_04_15_193829) do t.index ["user_id", "created_at"], name: "index_answers_on_user_id_and_created_at" end + create_table "appendables", force: :cascade do |t| + t.string "type", null: false + t.bigint "user_id", null: false + t.bigint "parent_id", null: false + t.string "parent_type", null: false + t.text "content" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["parent_id", "parent_type"], name: "index_appendables_on_parent_id_and_parent_type" + t.index ["user_id", "created_at"], name: "index_appendables_on_user_id_and_created_at" + end + create_table "comment_smiles", id: :bigint, default: -> { "gen_timestamp_id('comment_smiles'::text)" }, force: :cascade do |t| t.bigint "user_id" t.bigint "comment_id" @@ -143,7 +155,7 @@ ActiveRecord::Schema.define(version: 2022_04_15_193829) do t.string "content" t.boolean "author_is_anonymous" t.string "author_name" - t.string "author_email" + t.string "author_identifier" t.bigint "user_id" t.datetime "created_at" t.datetime "updated_at"