Class: Collavre::SystemSetting
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ApplicationRecord
- Collavre::SystemSetting
- Defined in:
- app/models/collavre/system_setting.rb
Constant Summary collapse
- CACHE_EXPIRY =
Cache expiry time for settings
5.minutes
- DEFAULT_MAX_LOGIN_ATTEMPTS =
Default values for account lockout
5- DEFAULT_LOCKOUT_DURATION_MINUTES =
30- DEFAULT_SESSION_TIMEOUT_MINUTES =
Default values for session timeout (in minutes, 0 = no timeout)
0- DEFAULT_PASSWORD_MIN_LENGTH =
Default values for password policy
8- DEFAULT_PASSWORD_RESET_RATE_LIMIT =
Default values for rate limiting
5- DEFAULT_PASSWORD_RESET_RATE_PERIOD_MINUTES =
60- DEFAULT_API_RATE_LIMIT =
100- DEFAULT_API_RATE_PERIOD_MINUTES =
1- DEFAULT_CREATIVES_LOGIN_REQUIRED =
Default values for creatives access By default, public access is allowed (false)
false- DEFAULT_HOME_PAGE_PATH =
Default home page path for unauthenticated visitors (nil means use root_path “/”)
nil- DEFAULT_HOME_PAGE_PATH_AUTHENTICATED =
Default home page path for authenticated users. Signed-in visitors hitting “/” are redirected to this path when the admin has not configured a value. Set to “/” via the admin UI to disable the redirect and fall back to the unauthenticated rewrite.
"/creatives"- DEFAULT_LIGHT_THEME_ID =
Default theme IDs (nil means use built-in light/dark) These reference UserTheme IDs for admin-configured custom themes
nil- DEFAULT_DARK_THEME_ID =
nil- DEFAULT_LLM_REQUEST_TIMEOUT_SECONDS =
Default LLM request timeout (seconds)
1800- DEFAULT_DISPLAY_LEVEL =
Default creative display settings (system-wide)
6- DEFAULT_COMPLETION_MARK =
""
Class Method Summary collapse
-
.api_rate_limit ⇒ Object
Rate limiting settings - API.
- .api_rate_period ⇒ Object
- .api_rate_period_minutes ⇒ Object
-
.cached_value(key, default = nil) ⇒ Object
Cached setting retrieval.
- .clear_all_cache ⇒ Object
- .completion_mark ⇒ Object
- .creatives_login_required? ⇒ Boolean
- .default_dark_theme ⇒ Object
- .default_dark_theme_id ⇒ Object
- .default_light_theme ⇒ Object
-
.default_light_theme_id ⇒ Object
Default theme IDs for users without a personal theme preference.
-
.display_level ⇒ Object
Creative display settings (system-wide).
- .help_menu_link ⇒ Object
- .home_page_path ⇒ Object
- .home_page_path_authenticated ⇒ Object
-
.llm_request_timeout_seconds ⇒ Object
LLM request timeout (seconds).
- .lockout_duration ⇒ Object
- .lockout_duration_minutes ⇒ Object
-
.max_login_attempts ⇒ Object
Account lockout settings.
- .mcp_tool_approval_required? ⇒ Boolean
-
.password_min_length ⇒ Object
Password policy settings (capped at 72 due to bcrypt limit).
-
.password_reset_rate_limit ⇒ Object
Rate limiting settings - Password Reset.
- .password_reset_rate_period ⇒ Object
- .password_reset_rate_period_minutes ⇒ Object
- .session_timeout ⇒ Object
- .session_timeout_enabled? ⇒ Boolean
-
.session_timeout_minutes ⇒ Object
Session timeout settings.
Class Method Details
.api_rate_limit ⇒ Object
Rate limiting settings - API
156 157 158 |
# File 'app/models/collavre/system_setting.rb', line 156 def self.api_rate_limit cached_value("api_rate_limit")&.to_i || DEFAULT_API_RATE_LIMIT end |
.api_rate_period ⇒ Object
164 165 166 |
# File 'app/models/collavre/system_setting.rb', line 164 def self.api_rate_period api_rate_period_minutes.minutes end |
.api_rate_period_minutes ⇒ Object
160 161 162 |
# File 'app/models/collavre/system_setting.rb', line 160 def self.api_rate_period_minutes cached_value("api_rate_period_minutes")&.to_i || DEFAULT_API_RATE_PERIOD_MINUTES end |
.cached_value(key, default = nil) ⇒ Object
Cached setting retrieval
55 56 57 58 59 |
# File 'app/models/collavre/system_setting.rb', line 55 def self.cached_value(key, default = nil) Rails.cache.fetch("system_setting:#{key}", expires_in: CACHE_EXPIRY) do find_by(key: key)&.value end || default end |
.clear_all_cache ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/collavre/system_setting.rb', line 61 def self.clear_all_cache # Clear known setting keys %w[ help_menu_link mcp_tool_approval_required max_login_attempts lockout_duration_minutes session_timeout_minutes password_min_length password_reset_rate_limit password_reset_rate_period_minutes api_rate_limit api_rate_period_minutes auth_providers_disabled creatives_login_required home_page_path home_page_path_authenticated default_light_theme_id default_dark_theme_id display_level completion_mark llm_request_timeout_seconds ].each { |k| Rails.cache.delete("system_setting:#{k}") } end |
.completion_mark ⇒ Object
194 195 196 197 |
# File 'app/models/collavre/system_setting.rb', line 194 def self.completion_mark value = cached_value("completion_mark") value.nil? ? DEFAULT_COMPLETION_MARK : value end |
.creatives_login_required? ⇒ Boolean
88 89 90 |
# File 'app/models/collavre/system_setting.rb', line 88 def self.creatives_login_required? cached_value("creatives_login_required", DEFAULT_CREATIVES_LOGIN_REQUIRED.to_s) == "true" end |
.default_dark_theme ⇒ Object
184 185 186 187 |
# File 'app/models/collavre/system_setting.rb', line 184 def self.default_dark_theme id = default_dark_theme_id id ? Collavre::UserTheme.find_by(id: id) : nil end |
.default_dark_theme_id ⇒ Object
174 175 176 177 |
# File 'app/models/collavre/system_setting.rb', line 174 def self.default_dark_theme_id value = cached_value("default_dark_theme_id") value.present? && value.to_i.positive? ? value.to_i : nil end |
.default_light_theme ⇒ Object
179 180 181 182 |
# File 'app/models/collavre/system_setting.rb', line 179 def self.default_light_theme id = default_light_theme_id id ? Collavre::UserTheme.find_by(id: id) : nil end |
.default_light_theme_id ⇒ Object
Default theme IDs for users without a personal theme preference
169 170 171 172 |
# File 'app/models/collavre/system_setting.rb', line 169 def self.default_light_theme_id value = cached_value("default_light_theme_id") value.present? && value.to_i.positive? ? value.to_i : nil end |
.display_level ⇒ Object
Creative display settings (system-wide)
190 191 192 |
# File 'app/models/collavre/system_setting.rb', line 190 def self.display_level cached_value("display_level")&.to_i || DEFAULT_DISPLAY_LEVEL end |
.help_menu_link ⇒ Object
84 85 86 |
# File 'app/models/collavre/system_setting.rb', line 84 def self. cached_value("help_menu_link") end |
.home_page_path ⇒ Object
92 93 94 95 |
# File 'app/models/collavre/system_setting.rb', line 92 def self.home_page_path value = cached_value("home_page_path") value.presence end |
.home_page_path_authenticated ⇒ Object
97 98 99 100 |
# File 'app/models/collavre/system_setting.rb', line 97 def self.home_page_path_authenticated value = cached_value("home_page_path_authenticated") value.presence || DEFAULT_HOME_PAGE_PATH_AUTHENTICATED end |
.llm_request_timeout_seconds ⇒ Object
LLM request timeout (seconds)
200 201 202 203 |
# File 'app/models/collavre/system_setting.rb', line 200 def self.llm_request_timeout_seconds value = cached_value("llm_request_timeout_seconds")&.to_i value.nil? || value < 30 ? DEFAULT_LLM_REQUEST_TIMEOUT_SECONDS : value end |
.lockout_duration ⇒ Object
118 119 120 |
# File 'app/models/collavre/system_setting.rb', line 118 def self.lockout_duration lockout_duration_minutes.minutes end |
.lockout_duration_minutes ⇒ Object
114 115 116 |
# File 'app/models/collavre/system_setting.rb', line 114 def self.lockout_duration_minutes cached_value("lockout_duration_minutes")&.to_i || DEFAULT_LOCKOUT_DURATION_MINUTES end |
.max_login_attempts ⇒ Object
Account lockout settings
110 111 112 |
# File 'app/models/collavre/system_setting.rb', line 110 def self.max_login_attempts cached_value("max_login_attempts")&.to_i || DEFAULT_MAX_LOGIN_ATTEMPTS end |
.mcp_tool_approval_required? ⇒ Boolean
102 103 104 105 106 107 |
# File 'app/models/collavre/system_setting.rb', line 102 def self.mcp_tool_approval_required? if Current.mcp_tool_approval_required.nil? Current.mcp_tool_approval_required = cached_value("mcp_tool_approval_required") == "true" end Current.mcp_tool_approval_required end |
.password_min_length ⇒ Object
Password policy settings (capped at 72 due to bcrypt limit)
123 124 125 126 127 |
# File 'app/models/collavre/system_setting.rb', line 123 def self.password_min_length value = cached_value("password_min_length")&.to_i value = DEFAULT_PASSWORD_MIN_LENGTH if value.nil? || value < 1 [ value, 72 ].min end |
.password_reset_rate_limit ⇒ Object
Rate limiting settings - Password Reset
143 144 145 |
# File 'app/models/collavre/system_setting.rb', line 143 def self.password_reset_rate_limit cached_value("password_reset_rate_limit")&.to_i || DEFAULT_PASSWORD_RESET_RATE_LIMIT end |
.password_reset_rate_period ⇒ Object
151 152 153 |
# File 'app/models/collavre/system_setting.rb', line 151 def self.password_reset_rate_period password_reset_rate_period_minutes.minutes end |
.password_reset_rate_period_minutes ⇒ Object
147 148 149 |
# File 'app/models/collavre/system_setting.rb', line 147 def self.password_reset_rate_period_minutes cached_value("password_reset_rate_period_minutes")&.to_i || DEFAULT_PASSWORD_RESET_RATE_PERIOD_MINUTES end |
.session_timeout ⇒ Object
138 139 140 |
# File 'app/models/collavre/system_setting.rb', line 138 def self.session_timeout session_timeout_minutes.minutes end |
.session_timeout_enabled? ⇒ Boolean
134 135 136 |
# File 'app/models/collavre/system_setting.rb', line 134 def self.session_timeout_enabled? session_timeout_minutes > 0 end |
.session_timeout_minutes ⇒ Object
Session timeout settings
130 131 132 |
# File 'app/models/collavre/system_setting.rb', line 130 def self.session_timeout_minutes cached_value("session_timeout_minutes")&.to_i || DEFAULT_SESSION_TIMEOUT_MINUTES end |