From 62d5a9690f3add5a1d970bc32caf60dccdc4142b Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Thu, 16 Jul 2020 09:15:01 -0500 Subject: [PATCH] FIX: Remove user_deleted when staff recovers post (#10245) --- lib/post_destroyer.rb | 4 +++- spec/components/post_destroyer_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index 9a5aece702f..3877bcccdee 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -104,7 +104,9 @@ class PostDestroyer end def staff_recovered - @post.update_column(:user_id, Discourse::SYSTEM_USER_ID) if !@post.user_id + new_post_attrs = { user_deleted: false } + new_post_attrs[:user_id] = Discourse::SYSTEM_USER_ID if !@post.user_id + @post.update_columns(new_post_attrs) @post.recover! mark_topic_changed diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index a7c622fa51f..ea5a7c90a3d 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -244,6 +244,14 @@ describe PostDestroyer do end context "recovered by admin" do + it "should set user_deleted to false" do + PostDestroyer.new(@user, @reply).destroy + expect(@reply.reload.user_deleted).to eq(true) + + PostDestroyer.new(admin, @reply).recover + expect(@reply.reload.user_deleted).to eq(false) + end + it "should increment the user's post count" do PostDestroyer.new(moderator, @reply).destroy expect(@user.reload.user_stat.topic_count).to eq(1)