diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index ff7240bc115..4e969f9fb9a 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -214,7 +214,8 @@ class PostDestroyer private def post_is_reviewable? - Guardian.new(@user).can_review_topic?(@post.topic) && Reviewable.exists?(target: @post) + topic = @post.topic || Topic.with_deleted.find(@post.topic_id) + Guardian.new(@user).can_review_topic?(topic) && Reviewable.exists?(target: @post) end # we need topics to change if ever a post in them is deleted or created diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index 75eb1494ae5..99a8bd3ad24 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -289,7 +289,7 @@ describe PostDestroyer do ReviewableFlaggedPost.needs_review!(target: @reply, created_by: Fabricate(:user)) end - it "changes deleted_at to nil" do + def changes_deleted_at_to_nil PostDestroyer.new(Discourse.system_user, @reply).destroy @reply.reload expect(@reply.user_deleted).to eq(false) @@ -299,6 +299,19 @@ describe PostDestroyer do @reply.reload expect(@reply.deleted_at).to eq(nil) end + + it "changes deleted_at to nil" do + changes_deleted_at_to_nil + end + + context "when the topic is deleted" do + before do + @reply.topic.trash! + end + it "changes deleted_at to nil" do + changes_deleted_at_to_nil + end + end end context "when the post does not have a Reviewable record" do