Merge pull request #187 from Retrospring/fix/question-link-visibility

Show question link for answered questions with only one answer
This commit is contained in:
Karina Kwiatek 2021-08-12 15:40:09 +02:00 committed by GitHub
commit 72e9ca61aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 3 deletions

View File

@ -32,7 +32,8 @@ class Ajax::QuestionController < AjaxController
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) user: current_user,
direct: params[:rcpt] != 'followers')
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
NewRelic::Agent.notice_error(e) NewRelic::Agent.notice_error(e)
@response[:status] = :rec_inv @response[:status] = :rec_inv

View File

@ -24,7 +24,7 @@
View in Kontrollzentrum View in Kontrollzentrum
%h6.text-muted.media-heading.answerbox__question-user %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)) = raw t('views.answerbox.asked', user: user_screen_name(a.question.user, anonymous: a.question.author_is_anonymous), time: time_tooltip(a.question))
- if !a.question.author_is_anonymous && a.question.answer_count > 1 - if !a.question.author_is_anonymous && !a.question.direct
· ·
%a{ href: show_user_question_path(a.question.user.screen_name, a.question.id) } %a{ href: show_user_question_path(a.question.user.screen_name, a.question.id) }
= pluralize(a.question.answer_count, t('views.general.answer')) = pluralize(a.question.answer_count, t('views.general.answer'))

View File

@ -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

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: 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -125,6 +125,7 @@ ActiveRecord::Schema.define(version: 2020_11_01_155648) do
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "answer_count", default: 0, null: false 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" t.index ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at"
end end

View File

@ -10,6 +10,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
expect(Question.last.content).to eq(question_content) expect(Question.last.content).to eq(question_content)
expect(Question.last.author_is_anonymous).to be(expected_question_anonymous) expect(Question.last.author_is_anonymous).to be(expected_question_anonymous)
expect(Question.last.user).to eq(expected_question_user) expect(Question.last.user).to eq(expected_question_user)
expect(Question.last.direct).to eq(expected_question_direct)
end end
if check_for_inbox if check_for_inbox
@ -85,6 +86,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
context "when user allows anonymous questions" do context "when user allows anonymous questions" do
let(:user_allows_anonymous_questions) { true } let(:user_allows_anonymous_questions) { true }
let(:expected_question_direct) { true }
context "when anonymousQuestion is true" do context "when anonymousQuestion is true" do
let(:anonymous_question) { "true" } let(:anonymous_question) { "true" }
@ -120,6 +122,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
context "when anonymousQuestion is false" do context "when anonymousQuestion is false" do
let(:anonymous_question) { "false" } let(:anonymous_question) { "false" }
let(:expected_question_anonymous) { false } let(:expected_question_anonymous) { false }
let(:expected_question_direct) { true }
include_examples "creates the question" include_examples "creates the question"
end end
@ -128,6 +131,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
context "when rcpt is followers" do context "when rcpt is followers" do
let(:rcpt) { "followers" } let(:rcpt) { "followers" }
let(:expected_question_direct) { false }
context "when anonymousQuestion is true" do context "when anonymousQuestion is true" do
let(:anonymous_question) { "true" } let(:anonymous_question) { "true" }
@ -182,6 +186,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
context "when user allows anonymous questions" do context "when user allows anonymous questions" do
let(:user_allows_anonymous_questions) { true } let(:user_allows_anonymous_questions) { true }
let(:expected_question_direct) { true }
include_examples "creates the question" include_examples "creates the question"