Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c518ea443 | ||
|
|
546e953513 | ||
|
|
9595e5578b | ||
|
|
c9bfc5c6a8 | ||
|
|
f5d80f2064 | ||
|
|
d5f46f922d |
@@ -265,6 +265,12 @@
|
||||
display_title: 'Analytics Token'
|
||||
description: 'The Amplitude analytics API key for Chatwoot cloud'
|
||||
type: secret
|
||||
- name: CHATWOOT_CLOUD_SIGNALS_API_TOKEN
|
||||
value:
|
||||
display_title: 'Signals API Token'
|
||||
description: 'Internal API token for Signals to sync Chatwoot cloud attribution data'
|
||||
locked: true
|
||||
type: secret
|
||||
- name: CLEARBIT_API_KEY
|
||||
value:
|
||||
display_title: 'Clearbit API Key'
|
||||
|
||||
@@ -555,6 +555,11 @@ Rails.application.routes.draw do
|
||||
end
|
||||
resources :email_channel_migrations, only: [:create]
|
||||
end
|
||||
if ChatwootApp.chatwoot_cloud?
|
||||
namespace :internal do
|
||||
resources :accounts, only: [:index]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,10 +34,10 @@ module Enterprise::SuperAdmin::AppConfigsController
|
||||
end
|
||||
|
||||
def internal_config_options
|
||||
%w[CHATWOOT_INBOX_TOKEN CHATWOOT_INBOX_HMAC_KEY CLOUD_ANALYTICS_TOKEN CLEARBIT_API_KEY CONTEXT_DEV_API_KEY DASHBOARD_SCRIPTS
|
||||
INACTIVE_WHATSAPP_NUMBERS SKIP_INCOMING_BCC_PROCESSING CAPTAIN_CLOUD_PLAN_LIMITS ACCOUNT_SECURITY_NOTIFICATION_WEBHOOK_URL
|
||||
CHATWOOT_INSTANCE_ADMIN_EMAIL OG_IMAGE_CDN_URL OG_IMAGE_CLIENT_REF CLOUDFLARE_API_KEY CLOUDFLARE_ZONE_ID BLOCKED_EMAIL_DOMAINS
|
||||
OTEL_PROVIDER LANGFUSE_PUBLIC_KEY LANGFUSE_SECRET_KEY LANGFUSE_BASE_URL]
|
||||
%w[CHATWOOT_INBOX_TOKEN CHATWOOT_INBOX_HMAC_KEY CLOUD_ANALYTICS_TOKEN CHATWOOT_CLOUD_SIGNALS_API_TOKEN CLEARBIT_API_KEY
|
||||
CONTEXT_DEV_API_KEY DASHBOARD_SCRIPTS INACTIVE_WHATSAPP_NUMBERS SKIP_INCOMING_BCC_PROCESSING CAPTAIN_CLOUD_PLAN_LIMITS
|
||||
ACCOUNT_SECURITY_NOTIFICATION_WEBHOOK_URL CHATWOOT_INSTANCE_ADMIN_EMAIL OG_IMAGE_CDN_URL OG_IMAGE_CLIENT_REF CLOUDFLARE_API_KEY
|
||||
CLOUDFLARE_ZONE_ID BLOCKED_EMAIL_DOMAINS OTEL_PROVIDER LANGFUSE_PUBLIC_KEY LANGFUSE_SECRET_KEY LANGFUSE_BASE_URL]
|
||||
end
|
||||
|
||||
def captain_config_options
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Platform::Api::V1::Internal::AccountsController < ActionController::API
|
||||
DEFAULT_LIMIT = 100
|
||||
MAX_LIMIT = 1000
|
||||
|
||||
before_action :ensure_chatwoot_cloud
|
||||
before_action :authenticate_internal_token!
|
||||
|
||||
def index
|
||||
@accounts = filtered_accounts.limit(limit)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensure_chatwoot_cloud
|
||||
render json: { error: 'Not found' }, status: :not_found unless ChatwootApp.chatwoot_cloud?
|
||||
end
|
||||
|
||||
def authenticate_internal_token!
|
||||
token = request.headers[:api_access_token] || request.headers[:HTTP_API_ACCESS_TOKEN]
|
||||
config_token = GlobalConfigService.load('CHATWOOT_CLOUD_SIGNALS_API_TOKEN', nil)
|
||||
return if token.present? && config_token.present? && ActiveSupport::SecurityUtils.secure_compare(token, config_token)
|
||||
|
||||
render json: { error: 'Invalid access_token' }, status: :unauthorized
|
||||
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?
|
||||
scope = scope.where('created_at <= ?', Time.zone.at(params[:until].to_i)) if params[:until].present?
|
||||
scope
|
||||
end
|
||||
|
||||
def limit
|
||||
params.fetch(:limit, DEFAULT_LIMIT).to_i.clamp(1, MAX_LIMIT)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
json.array! @accounts do |account|
|
||||
json.id account.id
|
||||
json.name account.name
|
||||
json.created_at account.created_at
|
||||
json.updated_at account.updated_at
|
||||
json.status account.status
|
||||
json.plan_name account.custom_attributes['plan_name']
|
||||
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