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 (nil means use root_path “/”)
nil- 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
-
.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
145 146 147 |
# File 'app/models/collavre/system_setting.rb', line 145 def self.api_rate_limit cached_value("api_rate_limit")&.to_i || DEFAULT_API_RATE_LIMIT end |
.api_rate_period ⇒ Object
153 154 155 |
# File 'app/models/collavre/system_setting.rb', line 153 def self.api_rate_period api_rate_period_minutes.minutes end |
.api_rate_period_minutes ⇒ Object
149 150 151 |
# File 'app/models/collavre/system_setting.rb', line 149 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
49 50 51 52 53 |
# File 'app/models/collavre/system_setting.rb', line 49 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
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/collavre/system_setting.rb', line 55 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 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
183 184 185 186 |
# File 'app/models/collavre/system_setting.rb', line 183 def self.completion_mark value = cached_value("completion_mark") value.nil? ? DEFAULT_COMPLETION_MARK : value end |
.creatives_login_required? ⇒ Boolean
82 83 84 |
# File 'app/models/collavre/system_setting.rb', line 82 def self.creatives_login_required? cached_value("creatives_login_required", DEFAULT_CREATIVES_LOGIN_REQUIRED.to_s) == "true" end |
.default_dark_theme ⇒ Object
173 174 175 176 |
# File 'app/models/collavre/system_setting.rb', line 173 def self.default_dark_theme id = default_dark_theme_id id ? Collavre::UserTheme.find_by(id: id) : nil end |
.default_dark_theme_id ⇒ Object
163 164 165 166 |
# File 'app/models/collavre/system_setting.rb', line 163 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
168 169 170 171 |
# File 'app/models/collavre/system_setting.rb', line 168 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
158 159 160 161 |
# File 'app/models/collavre/system_setting.rb', line 158 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)
179 180 181 |
# File 'app/models/collavre/system_setting.rb', line 179 def self.display_level cached_value("display_level")&.to_i || DEFAULT_DISPLAY_LEVEL end |
.help_menu_link ⇒ Object
78 79 80 |
# File 'app/models/collavre/system_setting.rb', line 78 def self. cached_value("help_menu_link") end |
.home_page_path ⇒ Object
86 87 88 89 |
# File 'app/models/collavre/system_setting.rb', line 86 def self.home_page_path value = cached_value("home_page_path") value.presence end |
.llm_request_timeout_seconds ⇒ Object
LLM request timeout (seconds)
189 190 191 192 |
# File 'app/models/collavre/system_setting.rb', line 189 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
107 108 109 |
# File 'app/models/collavre/system_setting.rb', line 107 def self.lockout_duration lockout_duration_minutes.minutes end |
.lockout_duration_minutes ⇒ Object
103 104 105 |
# File 'app/models/collavre/system_setting.rb', line 103 def self.lockout_duration_minutes cached_value("lockout_duration_minutes")&.to_i || DEFAULT_LOCKOUT_DURATION_MINUTES end |
.max_login_attempts ⇒ Object
Account lockout settings
99 100 101 |
# File 'app/models/collavre/system_setting.rb', line 99 def self.max_login_attempts cached_value("max_login_attempts")&.to_i || DEFAULT_MAX_LOGIN_ATTEMPTS end |
.mcp_tool_approval_required? ⇒ Boolean
91 92 93 94 95 96 |
# File 'app/models/collavre/system_setting.rb', line 91 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)
112 113 114 115 116 |
# File 'app/models/collavre/system_setting.rb', line 112 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
132 133 134 |
# File 'app/models/collavre/system_setting.rb', line 132 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
140 141 142 |
# File 'app/models/collavre/system_setting.rb', line 140 def self.password_reset_rate_period password_reset_rate_period_minutes.minutes end |
.password_reset_rate_period_minutes ⇒ Object
136 137 138 |
# File 'app/models/collavre/system_setting.rb', line 136 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
127 128 129 |
# File 'app/models/collavre/system_setting.rb', line 127 def self.session_timeout session_timeout_minutes.minutes end |
.session_timeout_enabled? ⇒ Boolean
123 124 125 |
# File 'app/models/collavre/system_setting.rb', line 123 def self.session_timeout_enabled? session_timeout_minutes > 0 end |
.session_timeout_minutes ⇒ Object
Session timeout settings
119 120 121 |
# File 'app/models/collavre/system_setting.rb', line 119 def self.session_timeout_minutes cached_value("session_timeout_minutes")&.to_i || DEFAULT_SESSION_TIMEOUT_MINUTES end |