mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: keep first post edit history when moving/merging (#22966)
This commit is contained in:
parent
c91409e6fd
commit
701ae8764e
@ -260,7 +260,13 @@ class PostMover
|
|||||||
|
|
||||||
PostAction.copy(post, new_post)
|
PostAction.copy(post, new_post)
|
||||||
|
|
||||||
attrs_to_update = { reply_count: @reply_count[1] || 0 }
|
PostRevision.copy(post, new_post)
|
||||||
|
|
||||||
|
attrs_to_update = {
|
||||||
|
reply_count: @reply_count[1] || 0,
|
||||||
|
version: post.version,
|
||||||
|
public_version: post.public_version,
|
||||||
|
}
|
||||||
|
|
||||||
if new_post.post_number != @move_map[post.post_number]
|
if new_post.post_number != @move_map[post.post_number]
|
||||||
attrs_to_update[:post_number] = @move_map[post.post_number]
|
attrs_to_update[:post_number] = @move_map[post.post_number]
|
||||||
|
@ -39,6 +39,17 @@ class PostRevision < ActiveRecord::Base
|
|||||||
def create_notification
|
def create_notification
|
||||||
PostActionNotifier.after_create_post_revision(self)
|
PostActionNotifier.after_create_post_revision(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.copy(original_post, target_post)
|
||||||
|
cols_to_copy = (column_names - %w[id post_id]).join(", ")
|
||||||
|
|
||||||
|
DB.exec <<~SQL
|
||||||
|
INSERT INTO post_revisions(post_id, #{cols_to_copy})
|
||||||
|
SELECT #{target_post.id}, #{cols_to_copy}
|
||||||
|
FROM post_revisions
|
||||||
|
WHERE post_id = #{original_post.id}
|
||||||
|
SQL
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
|
@ -875,6 +875,18 @@ RSpec.describe PostMover do
|
|||||||
expect(TopicUser.find_by(topic: destination_topic, user: user).liked).to eq(true)
|
expect(TopicUser.find_by(topic: destination_topic, user: user).liked).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "copies the post revisions from first post to the new post" do
|
||||||
|
p1.revise(another_user, { raw: "A different raw content" })
|
||||||
|
|
||||||
|
moved_to = topic.move_posts(user, [p1.id], destination_topic_id: destination_topic.id)
|
||||||
|
new_post = moved_to.posts.last
|
||||||
|
|
||||||
|
expect(new_post.id).not_to eq(p1.id)
|
||||||
|
expect(new_post.version).to eq(2)
|
||||||
|
expect(new_post.public_version).to eq(2)
|
||||||
|
expect(new_post.post_revisions.size).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
context "with read state and other stats per user" do
|
context "with read state and other stats per user" do
|
||||||
def create_topic_user(user, topic, opts = {})
|
def create_topic_user(user, topic, opts = {})
|
||||||
notification_level = opts.delete(:notification_level) || :regular
|
notification_level = opts.delete(:notification_level) || :regular
|
||||||
@ -1223,6 +1235,18 @@ RSpec.describe PostMover do
|
|||||||
expect(new_topic.first_post.custom_fields).to eq(custom_fields)
|
expect(new_topic.first_post.custom_fields).to eq(custom_fields)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "preserves the post revisions in the new post" do
|
||||||
|
p1.revise(another_user, { raw: "A different raw content" })
|
||||||
|
|
||||||
|
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_post.id).not_to eq(p1.id)
|
||||||
|
expect(new_post.version).to eq(2)
|
||||||
|
expect(new_post.public_version).to eq(2)
|
||||||
|
expect(new_post.post_revisions.size).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
include_examples "moves email related stuff" do
|
include_examples "moves email related stuff" do
|
||||||
let!(:old_post) { p1 }
|
let!(:old_post) { p1 }
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user