fix: enforce inbox limit at model level
This commit is contained in:
@@ -53,6 +53,7 @@ class Inbox < ApplicationRecord
|
||||
validates :out_of_office_message, length: { maximum: Limits::OUT_OF_OFFICE_MESSAGE_MAX_LENGTH }
|
||||
validates :greeting_message, length: { maximum: Limits::GREETING_MESSAGE_MAX_LENGTH }
|
||||
validate :ensure_valid_max_assignment_limit
|
||||
validate :ensure_inbox_limit, on: :create
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :portal, optional: true
|
||||
@@ -237,6 +238,13 @@ class Inbox < ApplicationRecord
|
||||
# overridden in enterprise/app/models/enterprise/inbox.rb
|
||||
end
|
||||
|
||||
def ensure_inbox_limit
|
||||
return unless account
|
||||
return unless account.inboxes.count >= account.usage_limits[:inboxes]
|
||||
|
||||
errors.add(:base, 'Account inbox limit exceeded. Upgrade to a higher plan')
|
||||
end
|
||||
|
||||
def delete_round_robin_agents
|
||||
::AutoAssignment::InboxRoundRobinService.new(inbox: self).clear_queue
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user