mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Copy post actions when moving a topic.
This commit is contained in:
parent
402eaaa773
commit
934bff43d9
@ -308,6 +308,19 @@ SQL
|
|||||||
PostAction.where(where_attrs).first
|
PostAction.where(where_attrs).first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.copy(original_post, target_post)
|
||||||
|
cols_to_copy = (column_names - %w{id post_id}).join(', ')
|
||||||
|
|
||||||
|
exec_sql <<~SQL
|
||||||
|
INSERT INTO post_actions(post_id, #{cols_to_copy})
|
||||||
|
SELECT #{target_post.id}, #{cols_to_copy}
|
||||||
|
FROM post_actions
|
||||||
|
WHERE post_id = #{original_post.id}
|
||||||
|
SQL
|
||||||
|
|
||||||
|
target_post.post_actions.each { |post_action| post_action.update_counters }
|
||||||
|
end
|
||||||
|
|
||||||
def self.remove_act(user, post, post_action_type_id)
|
def self.remove_act(user, post, post_action_type_id)
|
||||||
|
|
||||||
limit_action!(user,post,post_action_type_id)
|
limit_action!(user,post,post_action_type_id)
|
||||||
|
@ -85,14 +85,16 @@ class PostMover
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_first_post(post)
|
def create_first_post(post)
|
||||||
p = PostCreator.create(
|
new_post = PostCreator.create(
|
||||||
post.user,
|
post.user,
|
||||||
raw: post.raw,
|
raw: post.raw,
|
||||||
topic_id: destination_topic.id,
|
topic_id: destination_topic.id,
|
||||||
acting_user: user,
|
acting_user: user,
|
||||||
skip_validations: true
|
skip_validations: true
|
||||||
)
|
)
|
||||||
p.update_column(:reply_count, @reply_count[1] || 0)
|
|
||||||
|
PostAction.copy(post, new_post)
|
||||||
|
new_post.update_column(:reply_count, @reply_count[1] || 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def move(post)
|
def move(post)
|
||||||
|
@ -273,10 +273,7 @@ describe PostMover do
|
|||||||
new_topic = topic.move_posts(user, [p1.id, p2.id], title: "new testing topic name")
|
new_topic = topic.move_posts(user, [p1.id, p2.id], title: "new testing topic name")
|
||||||
|
|
||||||
expect(new_topic).to be_present
|
expect(new_topic).to be_present
|
||||||
new_topic.posts.reload
|
|
||||||
expect(new_topic.posts.by_post_number.first.raw).to eq(p1.raw)
|
expect(new_topic.posts.by_post_number.first.raw).to eq(p1.raw)
|
||||||
|
|
||||||
new_topic.reload
|
|
||||||
expect(new_topic.posts_count).to eq(2)
|
expect(new_topic.posts_count).to eq(2)
|
||||||
expect(new_topic.highest_post_number).to eq(2)
|
expect(new_topic.highest_post_number).to eq(2)
|
||||||
|
|
||||||
@ -284,7 +281,7 @@ describe PostMover do
|
|||||||
p1.reload
|
p1.reload
|
||||||
expect(p1.sort_order).to eq(1)
|
expect(p1.sort_order).to eq(1)
|
||||||
expect(p1.post_number).to eq(1)
|
expect(p1.post_number).to eq(1)
|
||||||
p1.topic_id == topic.id
|
expect(p1.topic_id).to eq(topic.id)
|
||||||
expect(p1.reply_count).to eq(0)
|
expect(p1.reply_count).to eq(0)
|
||||||
|
|
||||||
# New first post
|
# New first post
|
||||||
@ -295,7 +292,7 @@ describe PostMover do
|
|||||||
p2.reload
|
p2.reload
|
||||||
expect(p2.post_number).to eq(2)
|
expect(p2.post_number).to eq(2)
|
||||||
expect(p2.sort_order).to eq(2)
|
expect(p2.sort_order).to eq(2)
|
||||||
p2.topic_id == new_topic.id
|
expect(p2.topic_id).to eq(new_topic.id)
|
||||||
expect(p2.reply_to_post_number).to eq(1)
|
expect(p2.reply_to_post_number).to eq(1)
|
||||||
expect(p2.reply_count).to eq(0)
|
expect(p2.reply_count).to eq(0)
|
||||||
|
|
||||||
@ -304,6 +301,17 @@ describe PostMover do
|
|||||||
expect(topic.highest_post_number).to eq(p4.post_number)
|
expect(topic.highest_post_number).to eq(p4.post_number)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "preserves post actions in the new post" do
|
||||||
|
PostAction.act(another_user, p1, PostActionType.types[:like])
|
||||||
|
|
||||||
|
new_topic = topic.move_posts(user, [p1.id], title: "new testing topic name")
|
||||||
|
new_post = new_topic.posts.where(post_number: 1).first
|
||||||
|
|
||||||
|
expect(new_topic.like_count).to eq(1)
|
||||||
|
expect(new_post.like_count).to eq(1)
|
||||||
|
expect(new_post.post_actions.size).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "to an existing topic with a deleted post" do
|
context "to an existing topic with a deleted post" do
|
||||||
|
Loading…
Reference in New Issue
Block a user