Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions spec/requests/whisper_leak_matrix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion sub_plugins/mod_categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading