Skip to content

A platform for community discussion. Free, open, simple.

FIX: freeze_original for moved_post notifications for OP moves, link to destination topic (#30147)

Mark VanLandingham07f4e56658c6
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb
index e0ab3be3968..f09cc205410 100644
--- a/app/models/post_mover.rb
+++ b/app/models/post_mover.rb
@@ -278,6 +278,13 @@ class PostMover
new_post.custom_fields = post.custom_fields
new_post.save_custom_fields
+ # When freezing original, ensure the notification generated points
+ # to the newly created post, not the old OP
+ if @options[:freeze_original]
+ @post_ids_after_move =
+ @post_ids_after_move.map { |post_id| post_id == post.id ? new_post.id : post_id }
+ end
+
DiscourseEvent.trigger(:first_post_moved, new_post, post)
DiscourseEvent.trigger(:post_moved, new_post, original_topic.id)
diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb
index e832d8ba053..74fa2a9821f 100644
--- a/spec/models/post_mover_spec.rb
+++ b/spec/models/post_mover_spec.rb
@@ -2668,9 +2668,9 @@ RSpec.describe PostMover do
context "with freeze_original option" do
fab!(:original_topic) { Fabricate(:topic) }
fab!(:destination_topic) { Fabricate(:topic) }
- fab!(:op) { Fabricate(:post, topic: original_topic, raw: "op of this topic") }
+ fab!(:op) { Fabricate(:post, topic: original_topic, raw: "op of original topic") }
fab!(:op_of_destination) do
- Fabricate(:post, topic: destination_topic, raw: "op of this topic")
+ Fabricate(:post, topic: destination_topic, raw: "op of destination topic")
end
fab!(:first_post) { Fabricate(:post, topic: original_topic, raw: "first_post") }
fab!(:second_post) { Fabricate(:post, topic: original_topic, raw: "second_post") }
@@ -2823,23 +2823,46 @@ RSpec.describe PostMover do
describe "moved_post notifications" do
before { Jobs.run_immediately! }
- it "Generates notifications pointing to the newly created post and topic" do
- PostMover.new(
- original_topic,
- Discourse.system_user,
- [first_post.id],
- options: {
- freeze_original: true,
- },
- ).to_topic(destination_topic.id)
+ describe "moving post other than first post" do
+ it "Generates notification pointing to destination topic" do
+ PostMover.new(
+ original_topic,
+ Discourse.system_user,
+ [first_post.id],
+ options: {
+ freeze_original: true,
+ },
+ ).to_topic(destination_topic.id)
- notification =
- Notification.find_by(
- post_number: destination_topic.posts.find_by(raw: "first_post").post_number,
- topic_id: destination_topic.id,
- notification_type: Notification.types[:moved_post],
- )
- expect(notification).to be_present
+ notification =
+ Notification.find_by(
+ post_number: destination_topic.posts.find_by(raw: "first_post").post_number,
+ topic_id: destination_topic.id,
+ notification_type: Notification.types[:moved_post],
+ )
+ expect(notification).to be_present
+ end
+ end
+
+ describe "moving first post" do
+ it "Generates notification pointing to destination topic" do
+ PostMover.new(
+ original_topic,
+ Discourse.system_user,
+ [op.id],
+ options: {
+ freeze_original: true,
+ },
+ ).to_topic(destination_topic.id)
+
+ notification =
+ Notification.find_by(
+ post_number: destination_topic.posts.find_by(raw: op.raw).post_number,
+ topic_id: destination_topic.id,
+ notification_type: Notification.types[:moved_post],
+ )
+ expect(notification).to be_present
+ end
end
end