Skip to content

A platform for community discussion. Free, open, simple.

FIX: Allow staff to view deleted topics in nested replies (#40134)

Rafael dos Santos Silvaa051d96b6526
diff --git a/lib/nested_replies/tree_loader.rb b/lib/nested_replies/tree_loader.rb
index c0514627603..2c832cf2fe0 100644
--- a/lib/nested_replies/tree_loader.rb
+++ b/lib/nested_replies/tree_loader.rb
@@ -33,7 +33,7 @@ module NestedReplies
end
def op_post
- @op_post ||= load_posts_for_tree(topic.posts.where(post_number: 1)).first
+ @op_post ||= load_posts_for_tree(apply_visibility(topic.posts.where(post_number: 1))).first
end
def root_posts_scope(sort)
diff --git a/spec/requests/nested_topics_controller_spec.rb b/spec/requests/nested_topics_controller_spec.rb
index 94079fa39b1..d6770ae9d49 100644
--- a/spec/requests/nested_topics_controller_spec.rb
+++ b/spec/requests/nested_topics_controller_spec.rb
@@ -455,6 +455,28 @@ RSpec.describe NestedTopicsController, type: :request do
expect(root_json["cooked"]).to be_present
expect(root_json["cooked"]).not_to eq("")
end
+
+ it "lets staff view a fully-deleted topic so they can recover it" do
+ PostDestroyer.new(admin, op).destroy
+ topic.reload
+ expect(topic.deleted_at).to be_present
+ sign_in(admin)
+
+ get show_url(topic)
+ expect(response.status).to eq(200)
+ json = response.parsed_body
+ expect(json["op_post"]).to be_present
+ expect(json["op_post"]["deleted_post_placeholder"]).to eq(true)
+ end
+
+ it "returns 404 for non-staff on a fully-deleted topic" do
+ PostDestroyer.new(admin, op).destroy
+ topic.reload
+ sign_in(user)
+
+ get show_url(topic)
+ expect(response.status).to eq(404)
+ end
end
describe "pinned replies" do
@@ -1170,6 +1192,20 @@ RSpec.describe NestedTopicsController, type: :request do
expect(ancestor["cooked"]).to be_present
expect(ancestor["cooked"]).not_to eq("")
end
+
+ it "lets staff load the context view of a fully-deleted topic" do
+ reply = Fabricate(:post, topic: topic, user: user, reply_to_post_number: nil)
+ PostDestroyer.new(admin, op).destroy
+ topic.reload
+ expect(topic.deleted_at).to be_present
+ sign_in(admin)
+
+ get context_url(topic, reply.post_number)
+ expect(response.status).to eq(200)
+ json = response.parsed_body
+ expect(json["op_post"]).to be_present
+ expect(json["op_post"]["deleted_post_placeholder"]).to eq(true)
+ end
end
end