0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 02:51:10 +08:00
discourse/plugins/chat
Régis Hanol 2708818126
FIX: Surface actionable errors when chat policy checks fail (#41971)
Previously, several chat endpoints answered policy failures with a
generic 422 `{"failed":"FAILED"}`, rendered literally as "FAILED" in the
UI: an admin creating a channel while `enable_public_channels` was
disabled had no way to know why creation failed, and a user saving a
message edit after staff closed the channel hit the same dead end. The
root cause is structural — a service policy failing without a matching
`on_failed_policy` handler silently falls through to the catch-all
`on_failure`, and near-identical actor-shaped policy names made the
handler lists look exhaustive when they weren't.

This change makes policy failures on the channel-creation and
message-edit endpoints answer with either a 403 (authorization) or a 422
carrying an actionable reason (feature or channel state), and makes that
split visible in the code:

- Creating a channel while public channels are disabled now explains the
`enable public channels` site setting instead of failing blankly.
- Editing a message in a closed/read-only channel now explains the
channel status via a new `Chat::Channel::Policy::MessageModification`
reason, mirroring the existing `MessageCreation` pattern.
- Authorization policies run before feature/state policies on both
endpoints (spec-pinned), so unauthorized users keep getting a plain 403
and are never shown state guidance they cannot act on. This flips a few
edit-endpoint failures (non-author, silenced, lost channel access) from
the opaque 422 to a proper 403.
- State policies are renamed with the channel as the grammatical subject
— `channel_allows_message_creation`,
`channel_allows_message_modification` — to distinguish them from actor
checks like `can_edit_message`; the old actor-shaped names are how the
gaps went unnoticed.
- An audit of every handler block in the chat plugin found nine handlers
naming policies or models that no longer exist. Eight were dead code
(removed or repaired to the current names); one was a live bug:
`bulk_destroy` listened for `:invalid_access` while
`Chat::TrashMessages` declares `:can_delete_all_chat_messages`, so
unauthorized bulk deletions returned the generic 422 instead of 403.
That endpoint also gains its first request specs.

Ref - t/188375
2026-07-24 12:27:14 +02:00
..
admin/assets/javascripts DEV: Consolidate reusable components into ui-kit (#38703) 2026-05-11 18:07:36 -03:00
app FIX: Surface actionable errors when chat policy checks fail (#41971) 2026-07-24 12:27:14 +02:00
assets UX: improve livestream chat messaging (#41750) 2026-07-21 11:07:31 +10:00
config FIX: Surface actionable errors when chat policy checks fail (#41971) 2026-07-24 12:27:14 +02:00
db A11Y: live announcements and optional sounds for chat messages (#41213) 2026-07-02 12:48:58 -04:00
lib FIX: Surface actionable errors when chat policy checks fail (#41971) 2026-07-24 12:27:14 +02:00
public/images FEATURE: add new chat reactions popup (#41028) 2026-06-25 14:56:08 +04:00
spec FIX: Surface actionable errors when chat policy checks fail (#41971) 2026-07-24 12:27:14 +02:00
test/javascripts DEV: Remove rich_editor site setting (#41873) 2026-07-23 19:49:20 -03:00
about.json
package.json DEV: Add a script for generating external types in discourse-types (#37095) 2026-03-09 20:37:43 +01:00
plugin.rb UX: Consolidate chat notifications into live notification preferences (#41538) 2026-07-14 08:32:48 +02:00
README.md
tsconfig.json DEV: Add a script for generating external types in discourse-types (#37095) 2026-03-09 20:37:43 +01:00

This plugin is still in active development and may change frequently

Documentation

The Discourse Chat plugin adds chat functionality to your Discourse so it can natively support both long-form and short-form communication needs of your online community.

For user documentation, see Discourse Chat.

For developer documentation, see Discourse Documentation.