Some checks failed
Frontend Lint & Test / test (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / security-scan (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
The OpenAI Custom Server request targets the per-account OpenAI integration
(/app/accounts/{id}/settings/integrations/openai), not the instance-level
Captain config. The CAPTAIN_OPEN_AI_PROVIDER provider-switch added in 46fe70398
was out of the intended scope and is new behavior that did not previously exist,
so it is removed. This restores the original Captain behavior (CAPTAIN_OPEN_AI_ENDPOINT
remains usable as before, no provider gating). The correct implementation goes in
config/integration/apps.yml for the per-account openai integration.
82 lines
3.5 KiB
Ruby
82 lines
3.5 KiB
Ruby
class SuperAdmin::AppConfigsController < SuperAdmin::ApplicationController
|
|
GENERAL_CONFIGS = %w[ENABLE_ACCOUNT_SIGNUP FIREBASE_PROJECT_ID FIREBASE_CREDENTIALS WEBHOOK_TIMEOUT MAXIMUM_FILE_UPLOAD_SIZE
|
|
WIDGET_TOKEN_EXPIRY].freeze
|
|
META_INCIDENT_CONFIGS = %w[DISABLE_META_INBOX_CREATION DISABLE_META_MESSAGE_SENDING].freeze
|
|
|
|
before_action :set_config
|
|
before_action :allowed_configs
|
|
def show
|
|
# ref: https://github.com/rubocop/rubocop/issues/7767
|
|
# rubocop:disable Style/HashTransformValues
|
|
@app_config = InstallationConfig.where(name: @allowed_configs)
|
|
.pluck(:name, :serialized_value)
|
|
.map { |name, serialized_value| [name, serialized_value['value']] }
|
|
.to_h
|
|
# rubocop:enable Style/HashTransformValues
|
|
@installation_configs = ConfigLoader.new.general_configs.each_with_object({}) do |config_hash, result|
|
|
result[config_hash['name']] = config_hash.except('name')
|
|
end
|
|
end
|
|
|
|
def create
|
|
errors = []
|
|
params['app_config'].each do |key, value|
|
|
next unless @allowed_configs.include?(key)
|
|
|
|
i = InstallationConfig.where(name: key).first_or_create(value: value, locked: false)
|
|
i.value = value
|
|
errors.concat(i.errors.full_messages) unless i.save
|
|
end
|
|
|
|
if errors.any?
|
|
redirect_to super_admin_app_config_path(config: @config), alert: errors.join(', ')
|
|
else
|
|
redirect_to super_admin_settings_path, flash: success_flash
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def set_config
|
|
@config = params[:config] || 'general'
|
|
end
|
|
|
|
def allowed_configs
|
|
general_configs = GENERAL_CONFIGS + (ChatwootApp.chatwoot_cloud? ? META_INCIDENT_CONFIGS : [])
|
|
|
|
mapping = {
|
|
'facebook' => %w[FB_APP_ID FB_VERIFY_TOKEN FB_APP_SECRET IG_VERIFY_TOKEN FACEBOOK_API_VERSION ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT],
|
|
'shopify' => %w[SHOPIFY_CLIENT_ID SHOPIFY_CLIENT_SECRET],
|
|
'microsoft' => %w[AZURE_APP_ID AZURE_APP_SECRET],
|
|
'email' => %w[MAILER_INBOUND_EMAIL_DOMAIN ACCOUNT_EMAILS_LIMIT ACCOUNT_EMAILS_PLAN_LIMITS],
|
|
'linear' => %w[LINEAR_CLIENT_ID LINEAR_CLIENT_SECRET],
|
|
'slack' => %w[SLACK_CLIENT_ID SLACK_CLIENT_SECRET],
|
|
'instagram' => %w[INSTAGRAM_APP_ID INSTAGRAM_APP_SECRET INSTAGRAM_VERIFY_TOKEN INSTAGRAM_API_VERSION ENABLE_INSTAGRAM_CHANNEL_HUMAN_AGENT],
|
|
'tiktok' => %w[TIKTOK_APP_ID TIKTOK_APP_SECRET TIKTOK_API_VERSION],
|
|
'whatsapp_embedded' => %w[WHATSAPP_APP_ID WHATSAPP_APP_SECRET WHATSAPP_CONFIGURATION_ID WHATSAPP_API_VERSION],
|
|
'notion' => %w[NOTION_CLIENT_ID NOTION_CLIENT_SECRET],
|
|
'google' => %w[GOOGLE_OAUTH_CLIENT_ID GOOGLE_OAUTH_CLIENT_SECRET GOOGLE_OAUTH_REDIRECT_URI ENABLE_GOOGLE_OAUTH_LOGIN],
|
|
'captain' => %w[CAPTAIN_OPEN_AI_API_KEY CAPTAIN_OPEN_AI_MODEL CAPTAIN_OPEN_AI_ENDPOINT]
|
|
}
|
|
|
|
@allowed_configs = mapping.fetch(@config, general_configs)
|
|
end
|
|
|
|
def success_notice
|
|
message = "#{@config.titleize} settings updated successfully"
|
|
return message unless restart_required_config_saved?
|
|
|
|
"#{message.delete_suffix('.')}. Restart Chatwoot web and worker processes to apply this change everywhere."
|
|
end
|
|
|
|
def success_flash
|
|
restart_required_config_saved? ? { success: success_notice } : { notice: success_notice }
|
|
end
|
|
|
|
def restart_required_config_saved?
|
|
params.fetch('app_config', {}).keys.intersect?(InstallationConfig::RESTART_REQUIRED_CONFIG_KEYS)
|
|
end
|
|
end
|
|
|
|
SuperAdmin::AppConfigsController.prepend_mod_with('SuperAdmin::AppConfigsController')
|