diff --git a/spec/requests/whisper_leak_matrix_spec.rb b/spec/requests/whisper_leak_matrix_spec.rb index a8bbaeaf..ae165900 100644 --- a/spec/requests/whisper_leak_matrix_spec.rb +++ b/spec/requests/whisper_leak_matrix_spec.rb @@ -460,6 +460,41 @@ def stream_ids(user) ).perform expect(Reviewable.viewable_by(stranger).to_a.map(&:id)).to include(plain.reviewable.id) end + + it "ignores a client's whisper flag while whispers are switched off" do + SiteSetting.enable_category_group_moderation = true + reviewers = Fabricate(:group) + reviewers.add(stranger) + Fabricate(:category_moderation_group, category: category, group: reviewers) + SiteSetting.mod_whisper_enabled = false + + result = + NewPostManager.new( + alice, + :topic_id => topic.id, + :raw => "a public reply that claims to be a whisper", + armed => "true", + ).perform + expect(result.action).to eq(:enqueued) + + reviewable = result.reviewable + expect(reviewable.payload).not_to have_key(armed) + expect(DiscourseModCategories::Whisper.private_reviewable?(reviewable)).to eq(false) + expect(Reviewable.viewable_by(stranger).to_a.map(&:id)).to include(reviewable.id) + + reviewable.perform(admin, :approve_post) + expect(whisper?(reviewable.reload.target)).to eq(false) + + # Answering an existing whisper still keeps the answer private. + back = + NewPostManager.new( + alice, + topic_id: topic.id, + raw: "queued whisper-back with the switch off", + reply_to_post_number: whisper_to_alice.post_number, + ).perform + expect(DiscourseModCategories::Whisper.private_reviewable?(back.reviewable)).to eq(true) + end end describe "the Telegram bridge" do diff --git a/sub_plugins/mod_categories.rb b/sub_plugins/mod_categories.rb index c9a9b4be..b4bd121a 100644 --- a/sub_plugins/mod_categories.rb +++ b/sub_plugins/mod_categories.rb @@ -659,10 +659,18 @@ class Engine < ::Rails::Engine args[:raw], ) armed_key = DiscourseModCategories::POST_WHISPER_ARMED_PARAM + # The client's own flag only counts while whispers can be written, as in + # Whisper.prepare_new_post!. With them off it would still have marked the + # queued copy a whisper, hiding a post that comes out public from + # reviewers and from the reports chat. armed = - ::ActiveModel::Type::Boolean.new.cast(DiscourseModCategories::Whisper.opt(args, armed_key)) + DiscourseModCategories::Whisper.enabled? && + ::ActiveModel::Type::Boolean.new.cast(DiscourseModCategories::Whisper.opt(args, armed_key)) if armed || DiscourseModCategories::Whisper.answered_whispers(stub, {}, user).any? args[armed_key] = "true" + else + args.delete(armed_key) + args.delete(armed_key.to_sym) end nil rescue StandardError => e