Skip to content

Commit

Permalink
FIX: Unable to move pm to public topic (discourse#24903)
Browse files Browse the repository at this point in the history
* FIX: guard against empty category_ids when creating small action post for changing of category

Co-authored-by: Kelvin Tan <[email protected]>
  • Loading branch information
oblakeerickson and tyb-talks authored Dec 14, 2023
1 parent 5417c4f commit 7aeb5d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/post_revisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def self.track_and_revise(topic_changes, field, attribute)
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,
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/post_revisor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@
),
)
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

Expand Down

0 comments on commit 7aeb5d6

Please sign in to comment.