Class: Collavre::Admin::SettingsController
- Inherits:
-
Collavre::ApplicationController
- Object
- ApplicationController
- Collavre::ApplicationController
- Collavre::Admin::SettingsController
- Defined in:
- app/controllers/collavre/admin/settings_controller.rb
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/collavre/admin/settings_controller.rb', line 8 def index @help_link = SystemSetting.find_by(key: "help_menu_link")&.value @mcp_tool_approval = SystemSetting.find_by(key: "mcp_tool_approval_required")&.value == "true" @creatives_login_required = SystemSetting.creatives_login_required? @home_page_path = SystemSetting.home_page_path @home_page_path_authenticated = SystemSetting.home_page_path_authenticated # Account lockout settings @max_login_attempts = SystemSetting.max_login_attempts @lockout_duration_minutes = SystemSetting.lockout_duration_minutes # Password policy settings @password_min_length = SystemSetting.password_min_length # Session timeout settings @session_timeout_minutes = SystemSetting.session_timeout_minutes # LLM settings @llm_request_timeout_seconds = SystemSetting.llm_request_timeout_seconds # Rate limiting settings @password_reset_rate_limit = SystemSetting.password_reset_rate_limit @password_reset_rate_period_minutes = SystemSetting.password_reset_rate_period_minutes @api_rate_limit = SystemSetting.api_rate_limit @api_rate_period_minutes = SystemSetting.api_rate_period_minutes # Storage is "disabled" list. View expects "enabled" list. all_provider_keys = Rails.application.config.auth_providers.map { |p| p[:key].to_s } disabled_providers = SystemSetting.find_by(key: "auth_providers_disabled")&.value&.split(",") || [] @enabled_auth_providers = all_provider_keys - disabled_providers end |
#uiux ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/controllers/collavre/admin/settings_controller.rb', line 40 def uiux @default_light_theme_id = SystemSetting.default_light_theme_id @default_dark_theme_id = SystemSetting.default_dark_theme_id @available_themes = Collavre::UserTheme.all.order(:name) @display_level = SystemSetting.display_level @completion_mark = SystemSetting.completion_mark end |
#update ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/collavre/admin/settings_controller.rb', line 80 def update SystemSetting.transaction do settings_from_params.each do |key, value| SystemSetting.find_or_initialize_by(key: key).update!(value: value) end # Home Page Paths (unauthenticated default + authenticated override). # Kept separate because they validate/normalize and may raise. save_home_page_path("home_page_path", params[:home_page_path]) save_home_page_path("home_page_path_authenticated", params[:home_page_path_authenticated]) save_auth_providers! end redirect_to collavre.admin_settings_path, notice: t("admin.settings.updated") rescue ActiveRecord::RecordInvalid => e flash.now[:alert] = e.record.errors..join(", ") @help_link = params[:help_link] @mcp_tool_approval = params[:mcp_tool_approval] == "1" @creatives_login_required = params[:creatives_login_required] == "1" @home_page_path = params[:home_page_path] @home_page_path_authenticated = params[:home_page_path_authenticated] @max_login_attempts = params[:max_login_attempts].to_i.positive? ? params[:max_login_attempts].to_i : SystemSetting::DEFAULT_MAX_LOGIN_ATTEMPTS @lockout_duration_minutes = params[:lockout_duration_minutes].to_i.positive? ? params[:lockout_duration_minutes].to_i : SystemSetting::DEFAULT_LOCKOUT_DURATION_MINUTES @password_min_length = [ [ params[:password_min_length].to_i, SystemSetting::DEFAULT_PASSWORD_MIN_LENGTH ].max, 72 ].min @session_timeout_minutes = [ params[:session_timeout_minutes].to_i, 0 ].max @password_reset_rate_limit = params[:password_reset_rate_limit].to_i.positive? ? params[:password_reset_rate_limit].to_i : SystemSetting::DEFAULT_PASSWORD_RESET_RATE_LIMIT @password_reset_rate_period_minutes = params[:password_reset_rate_period_minutes].to_i.positive? ? params[:password_reset_rate_period_minutes].to_i : SystemSetting::DEFAULT_PASSWORD_RESET_RATE_PERIOD_MINUTES @api_rate_limit = params[:api_rate_limit].to_i.positive? ? params[:api_rate_limit].to_i : SystemSetting::DEFAULT_API_RATE_LIMIT @api_rate_period_minutes = params[:api_rate_period_minutes].to_i.positive? ? params[:api_rate_period_minutes].to_i : SystemSetting::DEFAULT_API_RATE_PERIOD_MINUTES @llm_request_timeout_seconds = params[:llm_request_timeout_seconds].to_i.positive? ? params[:llm_request_timeout_seconds].to_i : SystemSetting::DEFAULT_LLM_REQUEST_TIMEOUT_SECONDS @enabled_auth_providers = params[:auth_providers] || [] render :index, status: :unprocessable_entity end |
#update_uiux ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/collavre/admin/settings_controller.rb', line 48 def update_uiux SystemSetting.transaction do light_theme_id = params[:default_light_theme_id].to_s.strip light_theme_setting = SystemSetting.find_or_initialize_by(key: "default_light_theme_id") light_theme_setting.value = light_theme_id.present? ? light_theme_id : nil light_theme_setting.save! dark_theme_id = params[:default_dark_theme_id].to_s.strip dark_theme_setting = SystemSetting.find_or_initialize_by(key: "default_dark_theme_id") dark_theme_setting.value = dark_theme_id.present? ? dark_theme_id : nil dark_theme_setting.save! # Creative display settings dl = params[:display_level].to_i dl = SystemSetting::DEFAULT_DISPLAY_LEVEL if dl < 1 SystemSetting.find_or_initialize_by(key: "display_level").tap { |s| s.value = dl.to_s; s.save! } cm = params[:completion_mark].to_s SystemSetting.find_or_initialize_by(key: "completion_mark").tap { |s| s.value = cm; s.save! } end redirect_to collavre.admin_uiux_path, notice: t("admin.settings.updated") rescue ActiveRecord::RecordInvalid => e flash.now[:alert] = e.record.errors..join(", ") @default_light_theme_id = params[:default_light_theme_id] @default_dark_theme_id = params[:default_dark_theme_id] @available_themes = Collavre::UserTheme.all.order(:name) @display_level = params[:display_level].to_i.positive? ? params[:display_level].to_i : SystemSetting::DEFAULT_DISPLAY_LEVEL @completion_mark = params[:completion_mark].to_s render :uiux, status: :unprocessable_entity end |