fix: enforce inbox limits at model level (#14949)

Fixes https://linear.app/chatwoot/issue/CW-7559/inbox-limit-abuse

## Why

The regular inbox API checked limits in the controller, but WhatsApp
embedded signup creates inboxes through a service using `Inbox.create!`.
That let Enterprise account inbox limits be skipped for embedded signup.

## What this change does

- Adds an Inbox create-time validation hook in OSS and implements the
limit check in the Enterprise Inbox module.
- Removes the duplicate controller/helper limit check so the model is
the single enforcement point.
- Preserves the existing `402 Payment Required` API response for account
inbox limit failures.
- Keeps updates to existing inboxes allowed when an account is already
at its inbox limit.

## Validation

- `bundle exec rspec
spec/controllers/api/v1/accounts/inboxes_controller_spec.rb
spec/enterprise/models/inbox_spec.rb`
This commit is contained in:
Sojan Jose
2026-07-08 02:18:07 -07:00
committed by GitHub
parent ce8c8e9a11
commit 0e07a27c74
18 changed files with 151 additions and 28 deletions

View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
class CustomExceptions::Inbox::LimitExceeded < CustomExceptions::Base
def message
'Account limit exceeded. Upgrade to a higher plan'
end
def to_hash
{ error: message }
end
def http_status
:payment_required
end
end