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 def questions
@title = 'Questions' @title = 'Questions'
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @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 @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? @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 end
# rubocop:disable Rails/SkipsModelValidations # 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 # rubocop:enable Rails/SkipsModelValidations
end end

View File

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

View File

@ -25,6 +25,10 @@
%a.dropdown-item{ href: '#', tabindex: -1, data: { action: 'ab-question-report', q_id: question.id } } %a.dropdown-item{ href: '#', tabindex: -1, data: { action: 'ab-question-report', q_id: question.id } }
%i.fa.fa-exclamation-triangle %i.fa.fa-exclamation-triangle
= t 'views.actions.report' = 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 %h6.text-muted.media-heading.answerbox__question-user
- identifier = question.author_is_anonymous ? question.author_identifier : nil - identifier = question.author_is_anonymous ? question.author_identifier : nil
- if hidden - if hidden

View File

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

View File

@ -11,6 +11,7 @@ module UseCase
option :content, type: Types::Coercible::String option :content, type: Types::Coercible::String
option :anonymous, type: Types::Params::Bool, default: proc { false } option :anonymous, type: Types::Params::Bool, default: proc { false }
option :author_identifier, type: Types::Coercible::String | Types::Nil option :author_identifier, type: Types::Coercible::String | Types::Nil
option :direct, type: Types::Params::Bool, default: proc { true }
def call def call
check_anonymous_rules check_anonymous_rules
@ -20,7 +21,8 @@ module UseCase
content: content, content: content,
author_is_anonymous: anonymous, author_is_anonymous: anonymous,
author_identifier: author_identifier, 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) return if filtered?(question)
@ -55,9 +57,9 @@ module UseCase
end end
def increment_asked_count 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 # 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 return
end end

View File

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

View File

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