diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb index 44dfed9b9b7..2da1ca25258 100644 --- a/app/models/post_mover.rb +++ b/app/models/post_mover.rb @@ -16,7 +16,10 @@ class PostMover @move_type = PostMover.move_types[:existing_topic] topic = Topic.find_by_id(id) - raise Discourse::InvalidParameters unless topic.archetype == @original_topic.archetype + if topic.archetype != @original_topic.archetype && + [@original_topic.archetype, topic.archetype].include?(Archetype.private_message) + raise Discourse::InvalidParameters + end Topic.transaction do move_posts_to topic diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb index 82dc48dc034..65783ed31dd 100644 --- a/spec/models/post_mover_spec.rb +++ b/spec/models/post_mover_spec.rb @@ -675,5 +675,29 @@ describe PostMover do end end end + + context 'banner topic' do + let(:admin) { Fabricate(:admin) } + let(:evil_trout) { Fabricate(:evil_trout) } + let(:regular_user) { Fabricate(:trust_level_4) } + let(:topic) { Fabricate(:topic) } + let(:personal_message) { Fabricate(:private_message_topic, user: regular_user) } + let(:banner_topic) { Fabricate(:banner_topic, user: evil_trout) } + let!(:p1) { Fabricate(:post, topic: banner_topic, user: evil_trout) } + let!(:p2) { Fabricate(:post, topic: banner_topic, reply_to_post_number: p1.post_number, user: regular_user) } + + context 'move to existing topic' do + it "allows moving banner topic posts in regular topic" do + banner_topic.move_posts(admin, [p2.id], destination_topic_id: topic.id) + expect(p2.reload.topic_id).to eq(topic.id) + end + + it "does not allow moving banner topic posts in personal message" do + expect { + banner_topic.move_posts(admin, [p2.id], destination_topic_id: personal_message.id) + }.to raise_error(Discourse::InvalidParameters) + end + end + end end end