A platform for community discussion. Free, open, simple.
FIX: Don't update `watching_first_post` notifications when moving first post
Gerhard Schlager2a95c5c5d6ce
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rbindex bf7ca569ade..3fcf4f3b53b 100644--- a/app/models/post_mover.rb+++ b/app/models/post_mover.rb@@ -238,6 +238,7 @@ class PostMover)) :: JSONFROM moved_posts mpWHERE n.topic_id = mp.old_topic_id AND n.post_number = mp.old_post_number+ AND n.notification_type <> #{Notification.types[:watching_first_post]}SQLenddiff --git a/spec/fabricators/notification_fabricator.rb b/spec/fabricators/notification_fabricator.rbindex 2d22ed320c8..6c386c73369 100644--- a/spec/fabricators/notification_fabricator.rb+++ b/spec/fabricators/notification_fabricator.rb@@ -72,3 +72,17 @@ Fabricator(:mentioned_notification, from: :notification) do}.to_jsonendend++Fabricator(:watching_first_post_notification, from: :notification) do+ notification_type Notification.types[:watching_first_post]+ data do |attrs|+ {+ topic_title: attrs[:topic].title,+ original_post_id: attrs[:post].id,+ original_post_type: attrs[:post].post_type,+ original_username: attrs[:post].user.username,+ revision_number: nil,+ display_username: attrs[:post].user.username+ }.to_json+ end+enddiff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rbindex da1aedd7f68..80a5f97d6ba 100644--- a/spec/models/post_mover_spec.rb+++ b/spec/models/post_mover_spec.rb@@ -312,6 +312,17 @@ describe PostMover doexpect(n4.post_number).to eq(4)end+ it "doesn't update notifications of type 'watching_first_post'" do+ n1 = Fabricate(:watching_first_post_notification, post: p1, user: another_user)++ topic.move_posts(user, [p1.id], title: "new testing topic name")++ n1.reload+ expect(n1.topic_id).to eq(topic.id)+ expect(n1.data_hash[:topic_title]).to eq(topic.title)+ expect(n1.post_number).to eq(1)+ end+it "deletes notifications for users not allowed to see the topic" doanother_admin = Fabricate(:admin)staff_category = Fabricate(:private_category, group: Group[:staff])