discourse/plugins/chat/lib/chat_sdk
Alan Guo Xiang Tan 029519ce15
FIX: Scope thread lookup by channel_id in chat thread messages service (#37978)
What is the problem?

- The chat plugin routes thread message requests through
  `/chat/api/channels/:channel_id/threads/:thread_id/messages`, where
  `channel_id` is part of the URL hierarchy.
- `Chat::ListChannelThreadMessages` ignores the `channel_id` route
  parameter entirely, looking up threads globally via `thread_id` alone
  in `fetch_thread`.
- This violates REST hierarchy semantics — a request with a mismatched
  `channel_id` still succeeds — and is inconsistent with every other
  thread-scoped service (`Chat::LookupThread`,
  `Chat::UpdateUserThreadLastRead`, etc.) which all scope by both IDs.
- Additionally, unlike peer services, it does not enforce that threading
  is enabled for the channel.

What is the solution?

- Add `channel_id` to the service contract with presence validation.
- Scope `fetch_thread` by both `thread_id` and `channel_id` so
  mismatched pairs return a 404.
- Add a `threading_enabled_for_channel` policy check after
  `can_view_thread`, matching the pattern in `Chat::LookupThread`
  (with `thread.force` support for forced threads like AI bot DMs).
- Add the corresponding `on_failed_policy` handler in
  `Chat::Api::ChannelThreadMessagesController`.
- Update `ChatSDK::Thread#messages` to resolve and pass `channel_id`
  to the service, and handle the new policy failure.
2026-02-24 10:10:45 +08:00
..
channel.rb DEV: correctly handle contract error in chat sdk (#37446) 2026-02-02 12:14:52 +01:00
message.rb FIX: Chat::UpdateMessage is not scoped to route channel_id (#37873) 2026-02-18 09:20:18 +10:00
thread.rb FIX: Scope thread lookup by channel_id in chat thread messages service (#37978) 2026-02-24 10:10:45 +08:00