feat: allow limits from custom attributes
This commit is contained in:
@@ -37,8 +37,8 @@ module Enterprise::Account
|
||||
plan_features[plan_name]
|
||||
end
|
||||
|
||||
def captain_monthly_limit
|
||||
default_value = { documents: ChatwootApp.max_limit, generated_responses: ChatwootApp.max_limit }.with_indifferent_access
|
||||
def default_captain_limit
|
||||
default_value = { documents: ChatwootApp.max_limit, responses: ChatwootApp.max_limit }.with_indifferent_access
|
||||
return default_value if plan_name.blank?
|
||||
|
||||
plan_quota = InstallationConfig.find_by(name: 'CAPTAIN_CLOUD_PLAN_LIMITS')&.value
|
||||
@@ -48,6 +48,15 @@ module Enterprise::Account
|
||||
plan_quota[plan_name.downcase]
|
||||
end
|
||||
|
||||
def captain_monthly_limit
|
||||
default_limits = default_captain_limit
|
||||
|
||||
{
|
||||
documents: custom_attributes['captain_document_limit'] || default_limits['documents'],
|
||||
responses: custom_attributes['captain_response_limit'] || default_limits['responses']
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_captain_limits(type)
|
||||
|
||||
@@ -124,7 +124,7 @@ RSpec.describe Account, type: :model do
|
||||
it 'returns default values' do
|
||||
account.custom_attributes = { 'plan_name': 'unknown' }
|
||||
expect(account.captain_monthly_limit).to eq(
|
||||
{ documents: ChatwootApp.max_limit, generated_responses: ChatwootApp.max_limit }.with_indifferent_access
|
||||
{ documents: ChatwootApp.max_limit, responses: ChatwootApp.max_limit }.with_indifferent_access
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user