Merge pull request #567 from Retrospring/feature/improving-asks

This commit is contained in:
Karina Kwiatek 2022-07-25 07:16:20 +02:00 committed by GitHub
commit a39a6e2826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 10 deletions

View File

@ -54,7 +54,7 @@ class UserController < ApplicationController
def questions
@title = 'Questions'
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
@questions = @user.cursored_questions(author_is_anonymous: false, last_id: params[:last_id])
@questions = @user.cursored_questions(author_is_anonymous: false, direct: false, last_id: params[:last_id])
@questions_last_id = @questions.map(&:id).min
@more_data_available = !@user.cursored_questions(author_is_anonymous: false, last_id: @questions_last_id, size: 1).count.zero?

View File

@ -17,7 +17,7 @@ class Question < ApplicationRecord
end
# rubocop:disable Rails/SkipsModelValidations
user&.decrement! :asked_count unless author_is_anonymous
user&.decrement! :asked_count unless author_is_anonymous || direct
# rubocop:enable Rails/SkipsModelValidations
end

View File

@ -5,9 +5,9 @@ module User::QuestionMethods
define_cursor_paginator :cursored_questions, :ordered_questions
def ordered_questions(author_is_anonymous: nil)
def ordered_questions(author_is_anonymous: nil, direct: nil)
questions
.where({ author_is_anonymous: author_is_anonymous }.compact)
.where({ author_is_anonymous:, direct: }.compact)
.order(:created_at)
.reverse_order
end

View File

@ -25,6 +25,10 @@
%a.dropdown-item{ href: '#', tabindex: -1, data: { action: 'ab-question-report', q_id: question.id } }
%i.fa.fa-exclamation-triangle
= t 'views.actions.report'
- if current_user.has_role? :administrator
%a.dropdown-item{ href: rails_admin_path_for_resource(question) }
%i.fa.fa-gears
= t("voc.view_in_rails_admin")
%h6.text-muted.media-heading.answerbox__question-user
- identifier = question.author_is_anonymous ? question.author_identifier : nil
- if hidden

View File

@ -21,11 +21,15 @@
%a.dropdown-item{ href: '#', tabindex: -1, data: { action: 'ab-question-report', q_id: q.id } }
%i.fa.fa-exclamation-triangle
= t 'views.actions.report'
- if current_user.has_role? :administrator
%a.dropdown-item{ href: rails_admin_path_for_resource(q) }
%i.fa.fa-gears
= t("voc.view_in_rails_admin")
%h6.media-heading.text-muted.answerbox__question-user
= raw t('views.answerbox.asked', user: user_screen_name(q.user), time: time_tooltip(q))
- if q.answer_count > 1
·
%a{ href: question_path(q.user.screen_name, q.id) }
= pluralize(q.answer_count, t('views.general.answer'))
%p.answerbox__question-text
= q.content
.answerbox__question-text
= question_markdown q.content

View File

@ -11,6 +11,7 @@ module UseCase
option :content, type: Types::Coercible::String
option :anonymous, type: Types::Params::Bool, default: proc { false }
option :author_identifier, type: Types::Coercible::String | Types::Nil
option :direct, type: Types::Params::Bool, default: proc { true }
def call
check_anonymous_rules
@ -20,7 +21,8 @@ module UseCase
content: content,
author_is_anonymous: anonymous,
author_identifier: author_identifier,
user: source_user_id.nil? ? nil : source_user
user: source_user_id.nil? ? nil : source_user,
direct: direct
)
return if filtered?(question)
@ -55,9 +57,9 @@ module UseCase
end
def increment_asked_count
unless source_user_id && !anonymous
unless source_user_id && !anonymous && !direct
# Only increment the asked count of the source user if the question
# is not anonymous, and we actually have a source user
# is not anonymous, and is not direct, and we actually have a source user
return
end

View File

@ -14,7 +14,8 @@ module UseCase
content: content,
author_is_anonymous: false,
author_identifier: author_identifier,
user: source_user
user: source_user,
direct: false
)
increment_asked_count

View File

@ -22,6 +22,7 @@ describe UseCase::Question::Create do
expect(question.content).to eq(content)
expect(question.author_is_anonymous).to eq(anonymous)
expect(question.author_identifier).to eq(author_identifier)
expect(question.direct).to eq(true)
if should_send_to_inbox
expect(target_user.inboxes.first.question_id).to eq(question.id)