Rename `author_email` field to `author_identifier`

This commit is contained in:
Karina Kwiatek 2022-06-14 16:11:00 +02:00 committed by Karina Kwiatek
parent 37732ff926
commit 1a68c1b46f
3 changed files with 24 additions and 5 deletions

View File

@ -1,5 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require "digest"
require "errors" require "errors"
class Ajax::QuestionController < AjaxController class Ajax::QuestionController < AjaxController
@ -34,10 +35,11 @@ class Ajax::QuestionController < AjaxController
is_never_anonymous = user_signed_in? && params[:rcpt] == 'followers' is_never_anonymous = user_signed_in? && params[:rcpt] == 'followers'
begin begin
question = Question.create!(content: params[:question], question = Question.create!(content: params[:question],
author_is_anonymous: is_never_anonymous ? false : params[:anonymousQuestion], author_is_anonymous: is_never_anonymous ? false : params[:anonymousQuestion],
user: current_user, author_identifier: Digest::SHA2.new(512).hexdigest(Rails.application.secret_key_base + request.ip),
direct: params[:rcpt] != 'followers') user: current_user,
direct: params[:rcpt] != 'followers')
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
Sentry.capture_exception(e) Sentry.capture_exception(e)
@response[:status] = :rec_inv @response[:status] = :rec_inv

View File

@ -0,0 +1,5 @@
class RenameAuthorEmailToAuthorIdentifier < ActiveRecord::Migration[6.1]
def change
rename_column :questions, :author_email, :author_identifier
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_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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" 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" t.index ["user_id", "created_at"], name: "index_answers_on_user_id_and_created_at"
end 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| create_table "comment_smiles", id: :bigint, default: -> { "gen_timestamp_id('comment_smiles'::text)" }, force: :cascade do |t|
t.bigint "user_id" t.bigint "user_id"
t.bigint "comment_id" t.bigint "comment_id"
@ -143,7 +155,7 @@ ActiveRecord::Schema.define(version: 2022_04_15_193829) do
t.string "content" t.string "content"
t.boolean "author_is_anonymous" t.boolean "author_is_anonymous"
t.string "author_name" t.string "author_name"
t.string "author_email" t.string "author_identifier"
t.bigint "user_id" t.bigint "user_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"