From 297e144f33e7217c281999d54b256b625c9bdd0f Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Thu, 29 Dec 2022 19:37:36 -0800 Subject: [PATCH] fix: Update account limit selection logic (#6149) --- enterprise/app/models/enterprise/account.rb | 6 +++++- spec/enterprise/models/account_spec.rb | 22 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/enterprise/app/models/enterprise/account.rb b/enterprise/app/models/enterprise/account.rb index dac6bb7a1..2089247a6 100644 --- a/enterprise/app/models/enterprise/account.rb +++ b/enterprise/app/models/enterprise/account.rb @@ -15,7 +15,11 @@ module Enterprise::Account def get_limits(limit_name) config_name = "ACCOUNT_#{limit_name.to_s.upcase}_LIMIT" - self[:limits][limit_name.to_s] || GlobalConfig.get(config_name)[config_name] || ChatwootApp.max_limit + return self[:limits][limit_name.to_s] if self[:limits][limit_name.to_s].present? + + return GlobalConfig.get(config_name)[config_name] if GlobalConfig.get(config_name)[config_name].present? + + ChatwootApp.max_limit end def validate_limit_keys diff --git a/spec/enterprise/models/account_spec.rb b/spec/enterprise/models/account_spec.rb index 16a664ef5..feb87951b 100644 --- a/spec/enterprise/models/account_spec.rb +++ b/spec/enterprise/models/account_spec.rb @@ -38,5 +38,27 @@ RSpec.describe Account do } ) end + + it 'returns max limits from global config if account limit is absent' do + account.update(limits: { agents: '' }) + expect(account.usage_limits).to eq( + { + agents: 20, + inboxes: ChatwootApp.max_limit + } + ) + end + + it 'returns max limits from app limit if account limit and installation config is absent' do + account.update(limits: { agents: '' }) + InstallationConfig.where(name: 'ACCOUNT_AGENTS_LIMIT').update(value: '') + + expect(account.usage_limits).to eq( + { + agents: ChatwootApp.max_limit, + inboxes: ChatwootApp.max_limit + } + ) + end end end