From b02375985aaa0fee00f01eb2937725e2775bdc60 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Mon, 11 Dec 2023 23:14:58 +0100 Subject: [PATCH 1/2] Add option to send question to own inbox --- app/controllers/ajax/question_controller.rb | 1 + .../retrospring/features/questionbox/all.ts | 3 +- app/views/modal/_ask.html.haml | 3 ++ config/locales/views.en.yml | 1 + lib/use_case/question/create_followers.rb | 2 + .../ajax/question_controller_spec.rb | 37 ++++++++++++++++++- 6 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/controllers/ajax/question_controller.rb b/app/controllers/ajax/question_controller.rb index e8b516d8..e2094fda 100644 --- a/app/controllers/ajax/question_controller.rb +++ b/app/controllers/ajax/question_controller.rb @@ -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 diff --git a/app/javascript/retrospring/features/questionbox/all.ts b/app/javascript/retrospring/features/questionbox/all.ts index 4a1373f4..5f38684a 100644 --- a/app/javascript/retrospring/features/questionbox/all.ts +++ b/app/javascript/retrospring/features/questionbox/all.ts @@ -13,7 +13,8 @@ export function questionboxAllHandler(event: Event): void { body: { rcpt: 'followers', question: document.querySelector('textarea[name=qb-all-question]').value, - anonymousQuestion: 'false' + anonymousQuestion: 'false', + sendToOwnInbox: (document.getElementById('qb-send-to-own-inbox') as HTMLInputElement).checked, }, contentType: 'application/json' }) diff --git a/app/views/modal/_ask.html.haml b/app/views/modal/_ask.html.haml index 647b52c5..b6ec7025 100644 --- a/app/views/modal/_ask.html.haml +++ b/app/views/modal/_ask.html.haml @@ -12,5 +12,8 @@ %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 + .float-start.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') %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") diff --git a/config/locales/views.en.yml b/config/locales/views.en.yml index d7961168..c850747c 100644 --- a/config/locales/views.en.yml +++ b/config/locales/views.en.yml @@ -272,6 +272,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: diff --git a/lib/use_case/question/create_followers.rb b/lib/use_case/question/create_followers.rb index 52277b2b..3f993dc0 100644 --- a/lib/use_case/question/create_followers.rb +++ b/lib/use_case/question/create_followers.rb @@ -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) { diff --git a/spec/controllers/ajax/question_controller_spec.rb b/spec/controllers/ajax/question_controller_spec.rb index eaa37774..9575576f 100644 --- a/spec/controllers/ajax/question_controller_spec.rb +++ b/spec/controllers/ajax/question_controller_spec.rb @@ -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 { From e119f29680562c58a9df6e7539c40648b7ae59d3 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 17 Dec 2023 22:33:54 +0100 Subject: [PATCH 2/2] Group inputs in ask modal Co-authored-by: Andreas Nedbal --- app/views/modal/_ask.html.haml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/modal/_ask.html.haml b/app/views/modal/_ask.html.haml index b6ec7025..403e6a84 100644 --- a/app/views/modal/_ask.html.haml +++ b/app/views/modal/_ask.html.haml @@ -12,8 +12,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 - .float-start.flex-grow-1 + .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') - %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.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")