Merge pull request #1512 from Retrospring/feature/send-to-own-inbox

This commit is contained in:
Karina J. Kwiatek 2023-12-17 23:13:20 +01:00 committed by GitHub
commit 60b7c23a8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 4 deletions

View File

@ -19,6 +19,7 @@ class Ajax::QuestionController < AjaxController
source_user_id: current_user.id,
content: params[:question],
author_identifier: AnonymousBlock.get_identifier(request.remote_ip),
send_to_own_inbox: params[:sendToOwnInbox],
)
return
end

View File

@ -13,7 +13,8 @@ export function questionboxAllHandler(event: Event): void {
body: {
rcpt: 'followers',
question: document.querySelector<HTMLInputElement>('textarea[name=qb-all-question]').value,
anonymousQuestion: 'false'
anonymousQuestion: 'false',
sendToOwnInbox: (document.getElementById('qb-send-to-own-inbox') as HTMLInputElement).checked,
},
contentType: 'application/json'
})

View File

@ -14,5 +14,9 @@
%textarea.form-control{ name: "qb-all-question", placeholder: t(".placeholder"), data: { "character-count-warning-target": "input" } }
.alert.alert-warning.mt-3.d-none{ data: { "character-count-warning-target": "warning" } }= t('.long_question_warning')
.modal-footer
%button.btn.btn-default{ type: :button, data: { bs_dismiss: :modal } }= t("voc.cancel")
%button.btn.btn-primary{ name: "qb-all-ask", type: :button, data: { loading_text: t(".loading") } }= t(".action")
.flex-grow-1
%input.form-check-input#qb-send-to-own-inbox{ type: :checkbox }
%label.form-check-label{ for: 'qb-send-to-own-inbox' }= t('.send_to_own_inbox')
.flex-grow-1.d-flex
%button.btn.btn-default.ms-auto{ type: :button, data: { bs_dismiss: :modal } }= t("voc.cancel")
%button.btn.btn-primary{ name: "qb-all-ask", type: :button, data: { loading_text: t(".loading") } }= t(".action")

View File

@ -275,6 +275,7 @@ en:
action: "Ask"
loading: "Asking…"
long_question_warning: "This question will only be sent to those who allow long questions in their profile settings."
send_to_own_inbox: "Send copy to my inbox"
list:
title: "Manage list memberships"
tab:

View File

@ -6,6 +6,7 @@ module UseCase
option :source_user_id, type: Types::Coercible::Integer
option :content, type: Types::Coercible::String
option :author_identifier, type: Types::Coercible::String | Types::Nil
option :send_to_own_inbox, type: Types::Params::Bool, default: proc { false }
def call
question = ::Question.create!(
@ -20,6 +21,7 @@ module UseCase
increment_metric
args = source_user.followers.map { |f| [f.id, question.id] }
SendToInboxJob.perform_async(source_user_id, question.id) if send_to_own_inbox
SendToInboxJob.perform_bulk(args)
{

View File

@ -77,9 +77,11 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
{
question: question_content,
anonymousQuestion: anonymous_question,
rcpt: rcpt
rcpt:,
sendToOwnInbox: send_to_own_inbox,
}
end
let(:send_to_own_inbox) { "false" }
subject { post(:create, params: params) }
@ -98,6 +100,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
context "when rcpt is a valid user" do
let(:rcpt) { target_user.id }
let(:send_to_own_inbox) { false }
context "when user allows anonymous questions" do
let(:user_allows_anonymous_questions) { true }
@ -219,10 +222,41 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
include_examples "creates the question", false
include_examples "enqueues SendToInboxJob jobs"
end
context "when sendToOwnInbox is true" do
let(:anonymous_question) { "false" }
let(:expected_question_anonymous) { false }
let(:user_allows_anonymous_questions) { false }
let(:send_to_own_inbox) { "true" }
include_examples "creates the question", false
it "sends question to the current user" do
allow(SendToInboxJob).to receive(:perform_async)
subject
expect(SendToInboxJob).to have_received(:perform_async).with(user.id, Question.last.id)
end
end
context "when sendToOwnInbox is false" do
let(:anonymous_question) { "false" }
let(:expected_question_anonymous) { false }
let(:user_allows_anonymous_questions) { false }
let(:send_to_own_inbox) { "false" }
include_examples "creates the question", false
it "sends question to the current user" do
allow(SendToInboxJob).to receive(:perform_async)
subject
expect(SendToInboxJob).not_to have_received(:perform_async).with(user.id, Question.last.id)
end
end
end
context "when rcpt is an invalid value" do
let(:rcpt) { "tripmeister_eder" }
let(:send_to_own_inbox) { false }
let(:anonymous_question) { "false" }
let(:expected_response) do
{
@ -239,6 +273,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
context "when rcpt is a non-existent user" do
let(:rcpt) { "-1" }
let(:send_to_own_inbox) { false }
let(:anonymous_question) { "false" }
let(:expected_response) do
{