0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 07:23:30 +08:00
discourse/plugins/chat/spec
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
..
components/chat FIX: Don't auto-remove chat members from logged_in_users group (#40543) 2026-06-03 18:15:32 +02:00
db/post_migrate FIX: Duplicate notifications when mentioned in chat (#39670) 2026-04-30 14:52:39 -03:00
fabricators FEATURE: Pin chat messages (#37985) 2026-02-23 22:00:16 +01:00
integration FEATURE: Add enable_discourse_workflows upcoming change (#41541) 2026-07-13 10:48:37 +10:00
jobs FEATURE: Restore web push quick reply for chat messages (#39614) 2026-04-29 12:36:03 -03:00
lib SECURITY: Enforce recipient PM allowlists for existing direct chat channels (#41923) 2026-07-22 12:11:42 -05:00
mailers DEV: bump simple email subject status to stable (#41285) 2026-06-30 18:18:57 +04:00
models A11Y: live announcements and optional sounds for chat messages (#41213) 2026-07-02 12:48:58 -04:00
queries/chat Revert "FIX: Existing DM sends bypass direct-message group restrictions (#40405)" (#40561) 2026-06-04 15:00:45 +08:00
requests FIX: Surface actionable errors when chat policy checks fail (#41971) 2026-07-24 12:27:14 +02:00
serializer UX: improve livestream chat messaging (#41750) 2026-07-21 11:07:31 +10:00
services FIX: Surface actionable errors when chat policy checks fail (#41971) 2026-07-24 12:27:14 +02:00
support FEATURE: Pin chat messages (#37985) 2026-02-23 22:00:16 +01:00
system FIX: Handle a member disabling chat in their preferences (#41805) 2026-07-17 16:21:12 +02:00
validators
plugin_helper.rb DEV: Enable some minor rubocop rules (#40094) 2026-05-19 15:29:38 +02:00
plugin_spec.rb FIX: show chat DM button when personal messages are restricted (#37920) 2026-02-19 12:37:25 +01:00