From b72848513fd284aa98c1f860d06cbec214e23246 Mon Sep 17 00:00:00 2001 From: Pranav Date: Sun, 6 Jul 2025 19:30:27 -0700 Subject: [PATCH] fix: Show billing upgrade page if there is a mismatch in the user count (#11886) Disable features/show billing upgrade for accounts with more users than the one in the license. --------- Co-authored-by: Muhsin Keloth --- app/javascript/dashboard/i18n/locale/en/generalSettings.json | 2 +- app/javascript/dashboard/i18n/locale/ru/generalSettings.json | 2 +- .../dashboard/routes/dashboard/upgrade/UpgradePage.vue | 4 +++- .../app/controllers/enterprise/api/v1/accounts_controller.rb | 5 ++++- .../enterprise/api/v1/accounts_controller_spec.rb | 5 ++++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/javascript/dashboard/i18n/locale/en/generalSettings.json b/app/javascript/dashboard/i18n/locale/en/generalSettings.json index c0c4d247d..9055574c5 100644 --- a/app/javascript/dashboard/i18n/locale/en/generalSettings.json +++ b/app/javascript/dashboard/i18n/locale/en/generalSettings.json @@ -3,7 +3,7 @@ "LIMIT_MESSAGES": { "CONVERSATION": "You have exceeded the conversation limit. Hacker plan allows only 500 conversations.", "INBOXES": "You have exceeded the inbox limit. Hacker plan only supports website live-chat. Additional inboxes like email, WhatsApp etc. require a paid plan.", - "AGENTS": "You have exceeded the agent limit. Hacker plan allows only 2 agents.", + "AGENTS": "You have exceeded the agent limit. Your plan only allows {allowedAgents} agents.", "NON_ADMIN": "Please contact your administrator to upgrade the plan and continue using all features." }, "TITLE": "Account settings", diff --git a/app/javascript/dashboard/i18n/locale/ru/generalSettings.json b/app/javascript/dashboard/i18n/locale/ru/generalSettings.json index b46d06a9d..ea6b9fca1 100644 --- a/app/javascript/dashboard/i18n/locale/ru/generalSettings.json +++ b/app/javascript/dashboard/i18n/locale/ru/generalSettings.json @@ -3,7 +3,7 @@ "LIMIT_MESSAGES": { "CONVERSATION": "You have exceeded the conversation limit. Hacker plan allows only 500 conversations.", "INBOXES": "You have exceeded the inbox limit. Hacker plan only supports website live-chat. Additional inboxes like email, WhatsApp etc. require a paid plan.", - "AGENTS": "You have exceeded the agent limit. Hacker plan allows only 2 agents.", + "AGENTS": "You have exceeded the agent limit. Your plan only allows {allowedAgents} agents.", "NON_ADMIN": "Please contact your administrator to upgrade the plan and continue using all features." }, "TITLE": "Настройки аккаунта", diff --git a/app/javascript/dashboard/routes/dashboard/upgrade/UpgradePage.vue b/app/javascript/dashboard/routes/dashboard/upgrade/UpgradePage.vue index c23d3e76b..aa2686b83 100644 --- a/app/javascript/dashboard/routes/dashboard/upgrade/UpgradePage.vue +++ b/app/javascript/dashboard/routes/dashboard/upgrade/UpgradePage.vue @@ -58,7 +58,9 @@ const limitExceededMessage = computed(() => { } else if (testLimit(nonWebInboxes)) { message = t('GENERAL_SETTINGS.LIMIT_MESSAGES.INBOXES'); } else if (testLimit(agents)) { - message = t('GENERAL_SETTINGS.LIMIT_MESSAGES.AGENTS'); + message = t('GENERAL_SETTINGS.LIMIT_MESSAGES.AGENTS', { + allowedAgents: agents.allowed, + }); } return message; diff --git a/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb b/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb index 95b85a472..339fbdf3c 100644 --- a/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb +++ b/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb @@ -65,7 +65,10 @@ class Enterprise::Api::V1::AccountsController < Api::BaseController { 'conversation' => {}, 'non_web_inboxes' => {}, - 'agents' => {}, + 'agents' => { + 'allowed' => @account.usage_limits[:agents], + 'consumed' => agents(@account) + }, 'captain' => @account.usage_limits[:captain] } end diff --git a/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb b/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb index 0bd917c06..33941cee8 100644 --- a/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb +++ b/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb @@ -199,7 +199,10 @@ RSpec.describe 'Enterprise Billing APIs', type: :request do expected_response = { 'id' => account.id, 'limits' => { - 'agents' => {}, + 'agents' => { + 'allowed' => account.usage_limits[:agents], + 'consumed' => account.users.count + }, 'conversation' => {}, 'captain' => { 'documents' => { 'consumed' => 0, 'current_available' => ChatwootApp.max_limit, 'total_count' => ChatwootApp.max_limit },