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:
15
lib/custom_exceptions/inbox/limit_exceeded.rb
Normal file
15
lib/custom_exceptions/inbox/limit_exceeded.rb
Normal 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
|
||||
Reference in New Issue
Block a user