A platform for community discussion. Free, open, simple.
FIX: Scope `PostMover` reviewable updates to moved posts (#42371)
Juan David Martínez Cubillos5895bb976c40
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rbindex ce242620526..e985d4b5f23 100644--- a/app/models/post_mover.rb+++ b/app/models/post_mover.rb@@ -120,6 +120,8 @@ class PostMoverendend+ @moving_post_ids = posts.map(&:id)+create_temp_tablemove_each_posthandle_moved_references@@ -748,10 +750,12 @@ class PostMoverenddef update_reviewables- Reviewable.where(target_type: "Post", target_id: @post_ids).update_all(- topic_id: @destination_topic.id,- category_id: @destination_topic.category_id,- )+ Reviewable.where(+ target_type: "Post",+ target_id: @moving_post_ids,+ topic_id: @original_topic.id,+ category_id: @original_topic.category_id,+ ).update_all(topic_id: @destination_topic.id, category_id: @destination_topic.category_id)enddef watch_new_topicdiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 7cb813d4a80..bd0395a6d32 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -342,6 +342,39 @@ RSpec.describe TopicsController doexpect(response).to be_forbiddenend+ it "ignores unrelated post IDs without exposing their reviewables" do+ restricted_category = Fabricate(:private_category, group: Fabricate(:group))+ restricted_topic = Fabricate(:topic, category: restricted_category)+ restricted_post = Fabricate(:post, topic: restricted_topic)+ restricted_reviewable =+ Fabricate(+ :reviewable_flagged_post,+ target: restricted_post,+ target_created_by: restricted_post.user,+ topic: restricted_topic,+ category: restricted_category,+ )++ expect(Reviewable.list_for(user, preload: false)).not_to include(restricted_reviewable)++ post "/t/#{topic.id}/move-posts.json",+ params: {+ title: "Logan is a good movie",+ post_ids: [p2.id, restricted_post.id],+ category_id: category.id,+ }++ aggregate_failures do+ expect(response.status).to eq(200)+ expect(response.parsed_body["success"]).to eq(true)+ expect(restricted_reviewable.reload).to have_attributes(+ topic_id: restricted_topic.id,+ category_id: restricted_category.id,+ )+ expect(Reviewable.list_for(user, preload: false)).not_to include(restricted_reviewable)+ end+ end+it "does not allow posts outside of the category to be moved" dotopic.update!(category: nil)