Add direct field to questions
Co-authored-by: Georg Gadinger <nilsding@nilsding.org>
This commit is contained in:
parent
5e7042ad6c
commit
56786ebb38
|
@ -32,7 +32,8 @@ class Ajax::QuestionController < AjaxController
|
|||
begin
|
||||
question = Question.create!(content: params[:question],
|
||||
author_is_anonymous: is_never_anonymous ? false : params[:anonymousQuestion],
|
||||
user: current_user)
|
||||
user: current_user,
|
||||
direct: params[:rcpt] != 'followers')
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
NewRelic::Agent.notice_error(e)
|
||||
@response[:status] = :rec_inv
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
View in Kontrollzentrum
|
||||
%h6.text-muted.media-heading.answerbox__question-user
|
||||
= raw t('views.answerbox.asked', user: user_screen_name(a.question.user, anonymous: a.question.author_is_anonymous), time: time_tooltip(a.question))
|
||||
- unless a.question.author_is_anonymous
|
||||
- if !a.question.author_is_anonymous && !a.question.direct
|
||||
·
|
||||
%a{ href: show_user_question_path(a.question.user.screen_name, a.question.id) }
|
||||
= pluralize(a.question.answer_count, t('views.general.answer'))
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddDirectToQuestions < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :questions, :direct, :boolean, null: false, default: false
|
||||
|
||||
# default all legacy questions to direct
|
||||
execute 'UPDATE questions SET direct = true;'
|
||||
|
||||
# All questions where
|
||||
# - the author is not 'justask' (generated questions), and
|
||||
# - the question wasn't asked anonymously
|
||||
# can be direct or not. This depends on if the question has more than one answer
|
||||
execute "
|
||||
UPDATE questions
|
||||
SET direct = (NOT (questions.answer_count > 1))
|
||||
WHERE author_name <> 'justask'
|
||||
OR NOT author_is_anonymous;"
|
||||
|
||||
# All questions which exist in at least more than one inbox are not direct
|
||||
execute "
|
||||
UPDATE questions
|
||||
SET direct = false
|
||||
WHERE id IN (
|
||||
SELECT question_id FROM inboxes GROUP BY question_id HAVING count(question_id) > 1
|
||||
);"
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2020_11_01_155648) do
|
||||
ActiveRecord::Schema.define(version: 2021_08_11_133004) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -125,6 +125,7 @@ ActiveRecord::Schema.define(version: 2020_11_01_155648) do
|
|||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "answer_count", default: 0, null: false
|
||||
t.boolean "direct", default: false, null: false
|
||||
t.index ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at"
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue