Merge pull request #1512 from Retrospring/feature/send-to-own-inbox
This commit is contained in:
commit
60b7c23a8b
|
@ -19,6 +19,7 @@ class Ajax::QuestionController < AjaxController
|
||||||
source_user_id: current_user.id,
|
source_user_id: current_user.id,
|
||||||
content: params[:question],
|
content: params[:question],
|
||||||
author_identifier: AnonymousBlock.get_identifier(request.remote_ip),
|
author_identifier: AnonymousBlock.get_identifier(request.remote_ip),
|
||||||
|
send_to_own_inbox: params[:sendToOwnInbox],
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,8 @@ export function questionboxAllHandler(event: Event): void {
|
||||||
body: {
|
body: {
|
||||||
rcpt: 'followers',
|
rcpt: 'followers',
|
||||||
question: document.querySelector<HTMLInputElement>('textarea[name=qb-all-question]').value,
|
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'
|
contentType: 'application/json'
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,5 +14,9 @@
|
||||||
%textarea.form-control{ name: "qb-all-question", placeholder: t(".placeholder"), data: { "character-count-warning-target": "input" } }
|
%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')
|
.alert.alert-warning.mt-3.d-none{ data: { "character-count-warning-target": "warning" } }= t('.long_question_warning')
|
||||||
.modal-footer
|
.modal-footer
|
||||||
%button.btn.btn-default{ type: :button, data: { bs_dismiss: :modal } }= t("voc.cancel")
|
.flex-grow-1
|
||||||
%button.btn.btn-primary{ name: "qb-all-ask", type: :button, data: { loading_text: t(".loading") } }= t(".action")
|
%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")
|
||||||
|
|
|
@ -275,6 +275,7 @@ en:
|
||||||
action: "Ask"
|
action: "Ask"
|
||||||
loading: "Asking…"
|
loading: "Asking…"
|
||||||
long_question_warning: "This question will only be sent to those who allow long questions in their profile settings."
|
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:
|
list:
|
||||||
title: "Manage list memberships"
|
title: "Manage list memberships"
|
||||||
tab:
|
tab:
|
||||||
|
|
|
@ -6,6 +6,7 @@ module UseCase
|
||||||
option :source_user_id, type: Types::Coercible::Integer
|
option :source_user_id, type: Types::Coercible::Integer
|
||||||
option :content, type: Types::Coercible::String
|
option :content, type: Types::Coercible::String
|
||||||
option :author_identifier, type: Types::Coercible::String | Types::Nil
|
option :author_identifier, type: Types::Coercible::String | Types::Nil
|
||||||
|
option :send_to_own_inbox, type: Types::Params::Bool, default: proc { false }
|
||||||
|
|
||||||
def call
|
def call
|
||||||
question = ::Question.create!(
|
question = ::Question.create!(
|
||||||
|
@ -20,6 +21,7 @@ module UseCase
|
||||||
increment_metric
|
increment_metric
|
||||||
|
|
||||||
args = source_user.followers.map { |f| [f.id, question.id] }
|
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)
|
SendToInboxJob.perform_bulk(args)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,9 +77,11 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
|
||||||
{
|
{
|
||||||
question: question_content,
|
question: question_content,
|
||||||
anonymousQuestion: anonymous_question,
|
anonymousQuestion: anonymous_question,
|
||||||
rcpt: rcpt
|
rcpt:,
|
||||||
|
sendToOwnInbox: send_to_own_inbox,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
let(:send_to_own_inbox) { "false" }
|
||||||
|
|
||||||
subject { post(:create, params: params) }
|
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
|
context "when rcpt is a valid user" do
|
||||||
let(:rcpt) { target_user.id }
|
let(:rcpt) { target_user.id }
|
||||||
|
let(:send_to_own_inbox) { false }
|
||||||
|
|
||||||
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 }
|
||||||
|
@ -219,10 +222,41 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
|
||||||
include_examples "creates the question", false
|
include_examples "creates the question", false
|
||||||
include_examples "enqueues SendToInboxJob jobs"
|
include_examples "enqueues SendToInboxJob jobs"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "when rcpt is an invalid value" do
|
context "when rcpt is an invalid value" do
|
||||||
let(:rcpt) { "tripmeister_eder" }
|
let(:rcpt) { "tripmeister_eder" }
|
||||||
|
let(:send_to_own_inbox) { false }
|
||||||
let(:anonymous_question) { "false" }
|
let(:anonymous_question) { "false" }
|
||||||
let(:expected_response) do
|
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
|
context "when rcpt is a non-existent user" do
|
||||||
let(:rcpt) { "-1" }
|
let(:rcpt) { "-1" }
|
||||||
|
let(:send_to_own_inbox) { false }
|
||||||
let(:anonymous_question) { "false" }
|
let(:anonymous_question) { "false" }
|
||||||
let(:expected_response) do
|
let(:expected_response) do
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue