discourse/spec/system/bulk_convert_topics_spec.rb
Régis Hanol c0e9377b0e
FEATURE: Bulk convert PMs to public topics (and vice versa) (#39256)
Adds two new staff-only bulk actions in the topic-list dropdown — "Make
Public Topic…" when every selected topic is a PM, and "Make Personal
Message" when none of them are. Both are silent by default: no bump, no
post revision, no edit notifications to watchers, no small-action post
in the topic, and no forced re-watch. Admins who do want to notify
participants can tick the existing "Notify" checkbox in the bulk-actions
modal.

Today, converting PMs to public topics is a one-at-a-time operation that
fans out noisy edit notifications to everyone watching the PM, creates a
post revision on the first post, and leaves a small-action post behind.
The Support team hits this whenever they move a customer's history out
of a group inbox and into an enterprise category — the existing runbook
(Ref - t/68360) works around it with a custom console script, and doing
it by hand spams participants. A proper bulk action in the UI was the
missing piece.

The plumbing starts at TopicConverter, which now takes a `silent:`
keyword argument. When true, it passes `bypass_bump`, `skip_revision`,
and `silent` through to PostRevisor (suppressing the bump, the revision
row, and the edit notifications), skips `add_small_action`, and skips
the forced `watch_topic` call at the end. While in there,
`convert_to_private_message` now fails loudly with a base error when the
final recipient count would exceed
`max_allowed_message_recipients`, rather than silently collapsing to a
self-only PM and losing all context — this applies to both the
single-topic and bulk paths, since the check lives in the converter
itself.

TopicsBulkAction registers two new operations,
`convert_to_public_topic` and `convert_to_private_message`, both driven
by a small `bulk_convert(from_pm:)` helper. Per-topic success is
detected from the archetype flip rather than from `.valid?`, which would
re-run validations and wipe the `errors.add(:base, ...)` added by the
cap guard. Validation errors bubble into the modal's failure list
through the existing `@errors` channel.

On the frontend, `bulk-select-topics-dropdown` gets two new entries with
matching visibility rules, and `bulk-topic-actions` gains a couple of
cases that reuse the existing CategoryChooser and `allowSilent`-backed
"Notify" checkbox. `isCategoryAction` is extended so the
destination-category picker renders for the PM→public flow.

Ref - t/181539
2026-04-21 15:08:39 +02:00

33 lines
1.2 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Bulk convert PMs to public topics" do
fab!(:admin)
fab!(:category)
fab!(:pm) { Fabricate(:private_message_topic, recipient: admin) }
fab!(:pm_post) { Fabricate(:post, topic: pm, user: pm.user) }
let(:topic_list_header) { PageObjects::Components::TopicListHeader.new }
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:modal) { PageObjects::Modals::TopicBulkActions.new }
let(:toasts) { PageObjects::Components::Toasts.new }
before { sign_in(admin) }
it "silently moves selected PMs into the chosen category" do
visit("/u/#{admin.username}/messages")
topic_list_header.click_bulk_select_button
topic_list.click_topic_checkbox(pm)
topic_list_header.click_bulk_select_topics_dropdown
topic_list_header.click_bulk_button("convert-to-public-topic")
modal.category_selector.expand
modal.category_selector.select_row_by_value(category.id)
modal.click_bulk_topics_confirm
expect(toasts).to have_success(I18n.t("js.topics.bulk.completed"))
expect(pm.reload.archetype).to eq(Archetype.default)
expect(pm.category_id).to eq(category.id)
expect(pm.posts.where(post_type: Post.types[:small_action])).to be_empty
end
end