FIX: Unable to move pm to public topic (#24903)

* FIX: guard against empty category_ids when creating small action post for changing of category

Co-authored-by: Kelvin Tan <kelv@discourse.org>
This commit is contained in:
Blake Erickson 2023-12-14 12:31:38 -07:00 committed by GitHub
parent 5417c4fac0
commit 7aeb5d6012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -154,7 +154,9 @@ class PostRevisor
end
def self.create_small_action_for_category_change(topic:, user:, old_category:, new_category:)
return if !SiteSetting.create_post_for_category_and_tag_changes
if !old_category || !new_category || !SiteSetting.create_post_for_category_and_tag_changes
return
end
topic.add_moderator_post(
user,

View File

@ -291,6 +291,17 @@ RSpec.describe PostRevisor do
),
)
end
describe "with PMs" do
fab!(:pm) { Fabricate(:private_message_topic) }
let(:first_post) { create_post(user: admin, topic: pm, allow_uncategorized_topics: false) }
fab!(:category) { Fabricate(:category, topic_count: 1) }
it "Does not create a category change small_action post when converting to a topic" do
expect do
TopicConverter.new(first_post.topic, admin).convert_to_public_topic(category.id)
end.to change { category.reload.topic_count }.by(1)
end
end
end
end