mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 18:01:01 +08:00
FIX: When moving posts between threads, ensure only relevant timings are moved (#30176)
Co-authored-by: Martin Brennan <martin@discourse.org>
This commit is contained in:
parent
eeb01ea0de
commit
19c3f7db93
|
@ -504,7 +504,9 @@ class PostMover
|
|||
end
|
||||
|
||||
def move_post_timings
|
||||
DB.exec <<~SQL
|
||||
params = { post_ids: @post_ids_after_move }
|
||||
|
||||
DB.exec(<<~SQL, params)
|
||||
UPDATE post_timings pt
|
||||
SET topic_id = mp.new_topic_id,
|
||||
post_number = mp.new_post_number
|
||||
|
@ -513,6 +515,7 @@ class PostMover
|
|||
AND pt.post_number = mp.old_post_number
|
||||
AND mp.old_post_id = mp.new_post_id
|
||||
AND mp.old_topic_id <> mp.new_topic_id
|
||||
AND mp.new_post_id IN (:post_ids)
|
||||
SQL
|
||||
end
|
||||
|
||||
|
|
|
@ -2005,6 +2005,47 @@ RSpec.describe PostMover do
|
|||
expect(TopicUser.find_by(topic: destination_topic, user: user).liked).to eq(true)
|
||||
end
|
||||
|
||||
it "allows moving posts from multiple topics into one existing topic" do
|
||||
dest_topic = Fabricate(:topic, user: user, created_at: 5.hours.ago)
|
||||
Fabricate(:post, topic: dest_topic, created_at: 5.hours.ago)
|
||||
create_post_timing(dest_topic.first_post, user, 500)
|
||||
|
||||
source_1_topic = Fabricate(:topic, user: user, created_at: 4.hours.ago)
|
||||
Fabricate(:post, topic: source_1_topic, user: user, created_at: 4.hours.ago)
|
||||
create_post_timing(source_1_topic.first_post, user, 500)
|
||||
source_1_post =
|
||||
Fabricate(:post, topic: source_1_topic, user: user, created_at: 3.hours.ago)
|
||||
create_post_timing(source_1_topic.posts.second, user, 500)
|
||||
|
||||
source_2_topic = Fabricate(:topic, user: user, created_at: 2.hours.ago)
|
||||
Fabricate(:post, topic: source_2_topic, user: user, created_at: 2.hours.ago)
|
||||
create_post_timing(source_2_topic.first_post, user, 500)
|
||||
source_2_post =
|
||||
Fabricate(:post, topic: source_2_topic, user: user, created_at: 1.hours.ago)
|
||||
create_post_timing(source_2_topic.posts.second, user, 500)
|
||||
|
||||
moved_to =
|
||||
source_2_topic.move_posts(
|
||||
user,
|
||||
[source_2_post.id],
|
||||
destination_topic_id: dest_topic.id,
|
||||
chronological_order: true,
|
||||
)
|
||||
|
||||
expect(moved_to).to be_present
|
||||
dest_topic.reload
|
||||
|
||||
moved_to_too =
|
||||
source_1_topic.move_posts(
|
||||
user,
|
||||
[source_1_post.id],
|
||||
destination_topic_id: dest_topic.id,
|
||||
chronological_order: true,
|
||||
)
|
||||
|
||||
expect(moved_to_too).to be_present
|
||||
end
|
||||
|
||||
context "with read state and other stats per user" do
|
||||
def create_topic_user(user, topic, opts = {})
|
||||
notification_level = opts.delete(:notification_level) || :regular
|
||||
|
|
Loading…
Reference in New Issue
Block a user