mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 02:12:09 +08:00
FEATURE: Add freeze_original
option to PostMover
This option will allow the api user to specify if the original topic should be `frozen`(locked and posts not deleted neither moved) With this option when moving topic posts your posts will be `copied` to the new topic and the original topic will be kept there.
This commit is contained in:
@ -7,11 +7,14 @@ class PostMover
|
|||||||
@move_types ||= Enum.new(:new_topic, :existing_topic)
|
@move_types ||= Enum.new(:new_topic, :existing_topic)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(original_topic, user, post_ids, move_to_pm: false)
|
# options:
|
||||||
|
# freeze_original: :boolean - if true, the original topic will be frozen but not deleted and posts will be "copied" to topic
|
||||||
|
def initialize(original_topic, user, post_ids, move_to_pm: false, options: {})
|
||||||
@original_topic = original_topic
|
@original_topic = original_topic
|
||||||
@user = user
|
@user = user
|
||||||
@post_ids = post_ids
|
@post_ids = post_ids
|
||||||
@move_to_pm = move_to_pm
|
@move_to_pm = move_to_pm
|
||||||
|
@options = options
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_topic(id, participants: nil, chronological_order: false)
|
def to_topic(id, participants: nil, chronological_order: false)
|
||||||
|
@ -2637,5 +2637,105 @@ RSpec.describe PostMover do
|
|||||||
expect(topic_1.deleted_at).not_to be_nil
|
expect(topic_1.deleted_at).not_to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with freeze_original option" do
|
||||||
|
fab!(:original_topic) { Fabricate(:topic) }
|
||||||
|
fab!(:destination_topic) { Fabricate(:topic) }
|
||||||
|
fab!(:post_1) { Fabricate(:post, topic: original_topic) }
|
||||||
|
fab!(:post_2) { Fabricate(:post, topic: original_topic) }
|
||||||
|
|
||||||
|
it "keeps all posts when moving to a new topic" do
|
||||||
|
new_topic =
|
||||||
|
PostMover.new(
|
||||||
|
original_topic,
|
||||||
|
Discourse.system_user,
|
||||||
|
[post_1.id, post_2.id],
|
||||||
|
options: {
|
||||||
|
freeze_original: true,
|
||||||
|
},
|
||||||
|
).to_new_topic("Hi I'm a new topic, with a copy of the old posts")
|
||||||
|
|
||||||
|
expect(original_topic.posts.count).to eq(2)
|
||||||
|
expect(new_topic.posts.count).to eq(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not get deleted when moved all posts to topic" do
|
||||||
|
SiteSetting.delete_merged_stub_topics_after_days = 0
|
||||||
|
PostMover.new(
|
||||||
|
original_topic,
|
||||||
|
Discourse.system_user,
|
||||||
|
[post_1.id, post_2.id],
|
||||||
|
options: {
|
||||||
|
freeze_original: true,
|
||||||
|
},
|
||||||
|
).to_topic(destination_topic.id)
|
||||||
|
|
||||||
|
expect(original_topic.deleted_at).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "keeps all posts when moving to an existing topic" do
|
||||||
|
PostMover.new(
|
||||||
|
original_topic,
|
||||||
|
Discourse.system_user,
|
||||||
|
[post_1.id, post_2.id],
|
||||||
|
options: {
|
||||||
|
freeze_original: true,
|
||||||
|
},
|
||||||
|
).to_topic(destination_topic.id)
|
||||||
|
|
||||||
|
expect(original_topic.posts.count).to eq(2)
|
||||||
|
expect(destination_topic.posts.count).to eq(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "lets you move multiple times to the same topic" do
|
||||||
|
mover =
|
||||||
|
PostMover.new(
|
||||||
|
original_topic,
|
||||||
|
Discourse.system_user,
|
||||||
|
[post_1.id, post_2.id],
|
||||||
|
options: {
|
||||||
|
freeze_original: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
mover.to_topic(destination_topic.id)
|
||||||
|
mover.to_topic(destination_topic.id)
|
||||||
|
|
||||||
|
expect(original_topic.posts.count).to eq(2)
|
||||||
|
expect(destination_topic.posts.count).to eq(4)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "keeps all posts when moving to a new PM" do
|
||||||
|
pm =
|
||||||
|
PostMover.new(
|
||||||
|
original_topic,
|
||||||
|
Discourse.system_user,
|
||||||
|
[post_1.id, post_2.id],
|
||||||
|
move_to_pm: true,
|
||||||
|
options: {
|
||||||
|
freeze_original: true,
|
||||||
|
},
|
||||||
|
).to_new_topic("Hi I'm a new PM, with a copy of the old posts")
|
||||||
|
|
||||||
|
expect(original_topic.posts.count).to eq(2)
|
||||||
|
expect(pm.posts.count).to eq(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "keep all posts when moving to an existing PM" do
|
||||||
|
pm = Fabricate(:private_message_topic)
|
||||||
|
|
||||||
|
PostMover.new(
|
||||||
|
original_topic,
|
||||||
|
Discourse.system_user,
|
||||||
|
[post_1.id, post_2.id],
|
||||||
|
move_to_pm: true,
|
||||||
|
options: {
|
||||||
|
freeze_original: true,
|
||||||
|
},
|
||||||
|
).to_topic(pm.id)
|
||||||
|
|
||||||
|
expect(original_topic.posts.count).to eq(2)
|
||||||
|
expect(pm.posts.count).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user