A platform for community discussion. Free, open, simple.
FIX: If a user deletes a hidden post, it should not lose history
Robin Ward0d84c5b894e5
diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rbindex e0c5ff3991c..228e5adfb4a 100644--- a/lib/post_destroyer.rb+++ b/lib/post_destroyer.rb@@ -179,7 +179,8 @@ class PostDestroyerkey = @post.is_first_post? ? 'js.topic.deleted_by_author' : 'js.post.deleted_by_author'@post.revise(@user,{ raw: I18n.t(key, count: delete_removed_posts_after) },- force_new_version: true+ force_new_version: true,+ deleting_post: true)Post.transaction dodiff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex eaa00090e13..8ac7b298775 100644--- a/lib/post_revisor.rb+++ b/lib/post_revisor.rb@@ -407,6 +407,7 @@ class PostRevisorenddef remove_flags_and_unhide_post+ return if @opts[:deleting_post]return unless editing_a_flagged_and_hidden_post?flaggers = []diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rbindex ddba7b20735..f8d050c0a84 100644--- a/spec/components/post_destroyer_spec.rb+++ b/spec/components/post_destroyer_spec.rb@@ -345,6 +345,12 @@ describe PostDestroyer doendend+ it "maintains history when a user destroys a hidden post" do+ post.hide!(PostActionType.types[:inappropriate])+ PostDestroyer.new(post.user, post).destroy+ expect(post.revisions[0].modifications['raw']).to be_present+ end+it "when topic is destroyed, it updates user_stats correctly" doSiteSetting.min_topic_title_length = 5post.topic.update_column(:title, "xyz")