From d77dccc636b30ebcb11b0ed3b2744cdd93229a5a Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 9 Aug 2018 14:54:23 -0400 Subject: [PATCH] FIX: user-deleted posts with deferred flags can be destroyed --- lib/post_destroyer.rb | 7 ++++--- spec/components/post_destroyer_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index ff808b418f..3b68fc60aa 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -26,9 +26,10 @@ class PostDestroyer .where("NOT EXISTS ( SELECT 1 FROM post_actions pa - WHERE pa.post_id = posts.id AND - pa.deleted_at IS NULL AND - pa.post_action_type_id IN (?) + WHERE pa.post_id = posts.id + AND pa.deleted_at IS NULL + AND pa.deferred_at IS NULL + AND pa.post_action_type_id IN (?) )", PostActionType.notify_flag_type_ids) .find_each do |post| diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index f1c772478f..ddd00be307 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -91,6 +91,12 @@ describe PostDestroyer do reply1.reload expect(reply1.deleted_at).to eq(nil) + # defer the flag, we should be able to delete the stub + PostAction.defer_flags!(reply1, Discourse.system_user) + PostDestroyer.destroy_stubs + + reply1.reload + expect(reply1.deleted_at).to_not eq(nil) end it 'uses the delete_removed_posts_after site setting' do