Add OpenAI token configuration to self-hosting settings (#122)

* feat: add OpenAI settings partial
This commit is contained in:
Juan José Mata
2025-08-22 23:04:59 -07:00
committed by GitHub
parent d054cd0bb2
commit 5d6915a994
10 changed files with 82 additions and 12 deletions

View File

@@ -3,7 +3,7 @@ class Settings::HostingsController < ApplicationController
guard_feature unless: -> { self_hosted? }
before_action :ensure_admin, only: :clear_cache
before_action :ensure_admin, only: [ :update, :clear_cache ]
def show
@breadcrumbs = [
@@ -31,6 +31,17 @@ class Settings::HostingsController < ApplicationController
Setting.twelve_data_api_key = hosting_params[:twelve_data_api_key]
end
if hosting_params.key?(:openai_access_token)
Setting.openai_access_token = hosting_params[:openai_access_token]
end
if hosting_params.key?(:openai_access_token)
token_param = hosting_params[:openai_access_token].to_s.strip
# Ignore blanks and redaction placeholders to prevent accidental overwrite
unless token_param.blank? || token_param == "********"
Setting.openai_access_token = token_param
end
end
redirect_to settings_hosting_path, notice: t(".success")
rescue ActiveRecord::RecordInvalid => error
flash.now[:alert] = t(".failure")
@@ -44,7 +55,7 @@ class Settings::HostingsController < ApplicationController
private
def hosting_params
params.require(:setting).permit(:require_invite_for_signup, :require_email_confirmation, :brand_fetch_client_id, :twelve_data_api_key)
params.require(:setting).permit(:require_invite_for_signup, :require_email_confirmation, :brand_fetch_client_id, :twelve_data_api_key, :openai_access_token)
end
def ensure_admin