From 9595e5578bc913b087a246d5b7eac158b21cea40 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Fri, 26 Jun 2026 14:44:31 -0700 Subject: [PATCH] chore: trim signals account payload --- .../api/v1/internal/accounts_controller.rb | 19 +++++++------------ .../v1/internal/accounts/index.json.jbuilder | 5 ++++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/enterprise/app/controllers/platform/api/v1/internal/accounts_controller.rb b/enterprise/app/controllers/platform/api/v1/internal/accounts_controller.rb index 450e7349d..4b2328fab 100644 --- a/enterprise/app/controllers/platform/api/v1/internal/accounts_controller.rb +++ b/enterprise/app/controllers/platform/api/v1/internal/accounts_controller.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class Platform::Api::V1::Internal::AccountsController < ActionController::API - include RequestExceptionHandler - CONFIG_KEY = 'CHATWOOT_CLOUD_SIGNALS_API_TOKEN' DEFAULT_LIMIT = 100 MAX_LIMIT = 1000 @@ -17,17 +15,20 @@ class Platform::Api::V1::Internal::AccountsController < ActionController::API private def ensure_chatwoot_cloud - render_not_found unless ChatwootApp.chatwoot_cloud? + render json: { error: 'Not found' }, status: :not_found unless ChatwootApp.chatwoot_cloud? end def authenticate_internal_token! - return if internal_token.present? && secure_token_match?(request_token, internal_token) + return if valid_token? render json: { error: 'Invalid access_token' }, status: :unauthorized end - def render_not_found - render json: { error: 'Not found' }, status: :not_found + def valid_token? + internal_token.present? && + request_token.present? && + request_token.bytesize == internal_token.bytesize && + ActiveSupport::SecurityUtils.secure_compare(request_token, internal_token) end def request_token @@ -42,12 +43,6 @@ class Platform::Api::V1::Internal::AccountsController < ActionController::API @internal_token ||= GlobalConfigService.load(CONFIG_KEY, nil) end - def secure_token_match?(token, configured_token) - return false if token.blank? || configured_token.blank? || token.bytesize != configured_token.bytesize - - ActiveSupport::SecurityUtils.secure_compare(token, configured_token) - end - def filtered_accounts scope = Account.order(:created_at, :id) scope = scope.where('created_at >= ?', Time.zone.at(params[:since].to_i)) if params[:since].present? diff --git a/enterprise/app/views/platform/api/v1/internal/accounts/index.json.jbuilder b/enterprise/app/views/platform/api/v1/internal/accounts/index.json.jbuilder index 445c0a8f0..9090591b6 100644 --- a/enterprise/app/views/platform/api/v1/internal/accounts/index.json.jbuilder +++ b/enterprise/app/views/platform/api/v1/internal/accounts/index.json.jbuilder @@ -5,7 +5,10 @@ json.array! @accounts do |account| json.updated_at account.updated_at json.status account.status json.plan_name account.custom_attributes['plan_name'] - json.custom_attributes account.custom_attributes + json.stripe_customer_id account.custom_attributes['stripe_customer_id'] + json.stripe_price_id account.custom_attributes['stripe_price_id'] + json.stripe_product_id account.custom_attributes['stripe_product_id'] + json.subscription_status account.custom_attributes['subscription_status'] json.limits account.limits json.marketing_attribution account.internal_attributes['marketing_attribution'] end