# Pull Request Template ## Description Prevents Chatwoot Cloud accounts from exceeding their daily non-channel email allowance through agent invitations. New-user invitations atomically reserve email capacity before mail is queued; when the budget is exhausted, agent creation rolls back and returns HTTP 429. This covers single and bulk agent creation. Self-hosted installations remain unaffected, and adding an existing user does not consume capacity when no invitation is sent. Related to [CW-7637](https://linear.app/chatwoot/issue/CW-7637/prevent-agent-invitation-email-abuse-after-july-20-incident). ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? Verified single and bulk creation at an exhausted budget, successful invitation enqueueing below the limit, no capacity usage for existing users, and no enforcement on self-hosted installations. A concurrent Redis probe admitted exactly five of twenty simultaneous reservations against a limit of five. ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
60 lines
1.2 KiB
Ruby
60 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module CustomExceptions::Account
|
|
class InvalidEmail < CustomExceptions::Base
|
|
def message
|
|
if @data[:domain_blocked]
|
|
I18n.t 'errors.signup.blocked_domain'
|
|
elsif @data[:disposable]
|
|
I18n.t 'errors.signup.disposable_email'
|
|
elsif !@data[:valid]
|
|
I18n.t 'errors.signup.invalid_email'
|
|
end
|
|
end
|
|
end
|
|
|
|
class UserExists < CustomExceptions::Base
|
|
def message
|
|
I18n.t('errors.signup.email_already_exists', email: @data[:email])
|
|
end
|
|
end
|
|
|
|
class InvalidParams < CustomExceptions::Base
|
|
def message
|
|
I18n.t 'errors.signup.invalid_params'
|
|
end
|
|
end
|
|
|
|
class UserErrors < CustomExceptions::Base
|
|
def message
|
|
@data[:errors].full_messages.join(',')
|
|
end
|
|
end
|
|
|
|
class SignupFailed < CustomExceptions::Base
|
|
def message
|
|
I18n.t 'errors.signup.failed'
|
|
end
|
|
end
|
|
|
|
class PlanUpgradeRequired < CustomExceptions::Base
|
|
def message
|
|
I18n.t 'errors.plan_upgrade_required.failed'
|
|
end
|
|
end
|
|
|
|
class EmailLimitExceeded < CustomExceptions::Base
|
|
def message
|
|
I18n.t('errors.account.email_limit_exceeded')
|
|
end
|
|
|
|
def to_hash
|
|
{ error: message }
|
|
end
|
|
|
|
def http_status
|
|
:too_many_requests
|
|
end
|
|
end
|
|
end
|