discourse/lib/nested_replies
Rafael dos Santos Silva a051d96b65
FIX: Allow staff to view deleted topics in nested replies (#40134)
## Summary

`NestedReplies::TreeLoader#op_post` loaded the OP via `topic.posts`,
whose default scope (from `Trashable`) excludes rows with `deleted_at`
set. When a topic is trashed its OP is trashed too, so the lookup
returned `nil` and the `/n/...` request crashed in
`PostPreloader#prepare` with `undefined method 'user_id' for nil` —
preventing staff from reaching the page to recover the topic.

Fix: apply the existing visibility helper (which already unscopes
`deleted_at`) on the OP query. The serializer's
`deleted_post_placeholder` path preserves content for staff and hides it
for everyone else, matching the flat topic view.

- non-staff still 404 via the earlier guardian check on the topic
itself, so this does not change their visibility
- both the `show` and `context` endpoints share the same loader, so both
paths are fixed

## Test plan

- [x] `bin/rspec spec/requests/nested_topics_controller_spec.rb` (100
examples, 0 failures), with new cases for staff `show`, staff `context`,
and non-staff 404 on a fully-deleted topic
- [x] `bin/rspec spec/lib/nested_replies/ spec/services/nested_topic/`
(127 examples, 0 failures)
- [ ] Manually: as admin, delete a topic that uses nested replies, then
navigate to `/n/<slug>/<id>` — page renders with the deleted OP
placeholder and the admin menu's Recover Topic action works
2026-05-18 15:45:14 -03:00
..
ancestor_walker.rb
post_preloader.rb DEV: add ids method to NestedReplies::PostPreloader to resolve warning (#40010) 2026-05-13 16:40:37 -05:00
post_tree_serializer.rb FIX: Properly open threads when clicking nested notifications (#39890) 2026-05-11 13:04:08 -05:00
sort.rb
tree_loader.rb FIX: Allow staff to view deleted topics in nested replies (#40134) 2026-05-18 15:45:14 -03:00