chore: trim signals account payload
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user