diff --git a/app/controllers/ajax/question_controller.rb b/app/controllers/ajax/question_controller.rb index ebe43d61..f3239ac0 100644 --- a/app/controllers/ajax/question_controller.rb +++ b/app/controllers/ajax/question_controller.rb @@ -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 diff --git a/app/views/answerbox/_header.haml b/app/views/answerbox/_header.haml index e330a7a8..0e31058f 100644 --- a/app/views/answerbox/_header.haml +++ b/app/views/answerbox/_header.haml @@ -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')) diff --git a/db/migrate/20210811133004_add_direct_to_questions.rb b/db/migrate/20210811133004_add_direct_to_questions.rb new file mode 100644 index 00000000..092426b9 --- /dev/null +++ b/db/migrate/20210811133004_add_direct_to_questions.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 86012613..3f9aed55 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: 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