Merge pull request #567 from Retrospring/feature/improving-asks
This commit is contained in:
commit
a39a6e2826
|
@ -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?
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue