Module: CoreSystemConfiguration
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/app/models/concerns/core_system_configuration.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
The System configuration.
Instance Method Summary collapse
-
#aws_auto_scaling_configured? ⇒ Boolean
Determine if auto scaling group is configured.
-
#aws_configured? ⇒ Boolean
Determine if AWS is configured.
- #long_cache_time ⇒ Object
-
#mail_gun_configured? ⇒ Boolean
Determine if mailgun is configured.
- #medium_cache_time ⇒ Object
-
#secure_fields ⇒ Object
Make sure the password doesn’t get blanked out on an update.
-
#short_cache_time ⇒ Object
Cache times in minutes.
-
#slack_configured? ⇒ Boolean
Determine if Slack is configured.
-
#smtp_configured? ⇒ Boolean
Determine if SMTP is configured.
-
#switchboard_configured? ⇒ Boolean
Public: Determine if switchboard is configured.
-
#twilio_configured? ⇒ Boolean
Determine if twillio is configured at a system configuration.
-
#zendesk_configured? ⇒ Boolean
Is zendesk configured?.
-
#zendesk_documentation_url(user = nil) ⇒ Object
Return the zendesk documentation URL.
-
#zendesk_new_request_url(user = nil) ⇒ Object
Return the zendesk support URL.
-
#zendesk_requests_url(user = nil) ⇒ Object
Return the zendesk support URL.
-
#zendesk_updates_url(user = nil) ⇒ Object
Return the zendesk update URL.
-
#zendesk_url(forward_to: zendesk_documentation_path, user: nil) ⇒ Object
Generate a Zendesk URL.
Class Method Details
.included(base) ⇒ Object
The System configuration. Various configuration items that can be updated/defined at run time
Use of this class allows you to simply ask for the configuration parameter directly without first having to get an instance of it.
SystemConfiguration.queue_impl #=> ‘RedisQueue’
This method only is allowed for accessors, you should NEVER set values on the SystemConfiguration unless you are updating via the Admin or Stack UI, or during testing to setup a specific configuration for that.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 79 80 81 82 83 84 85 86 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 17 def self.included(base) base.class_eval do attr_accessor :configuration # # Fields # field :environment, type: String, default: 'test' field :fips_mode, type: Boolean, default: false field :fav_icon_path, { type: String, default: '/favicon.ico' } field :stack_logo_path, { type: String, default: 'ui-company-logo.png' } field :primary_stylesheet, { type: String, default: 'app47' } field :short_cache, { type: Integer, default: 1 } field :medium_cache, { type: Integer, default: 5 } field :long_cache, { type: Integer, default: 15 } # SMTP configuration field :default_email, type: String, default: '[email protected]' field :support_email, type: String, default: '[email protected]' field :smtp_name, type: String field :smtp_address, type: String field :smtp_domain, type: String field :smtp_port, type: Integer, default: 587 field :smtp_user_name, type: String field :smtp_password, type: String field :smtp_enable_starttls_auto, type: Boolean field :mailgun_api_key, type: String # Twillio support field :twilio_account_id, type: String field :twilio_auth_token, type: String field :twilio_phone_number, type: String # URLs field :base_url, type: String field :cdn_url, type: String # Slack support field :slack_api_url, type: String field :slack_support_channel, type: String, default: 'support' field :slack_sales_channel, type: String, default: 'sales' # Time Zone Support field :default_time_zone, type: String, default: 'US/Eastern' # AWS field :aws_region, type: String field :aws_access_key_id, type: String field :aws_secret_access_key, type: String field :aws_auto_scaling_group_name, type: String # Zendesk field :zendesk_token, type: String field :zendesk_base_url, type: String, default: 'https://app47.zendesk.com' field :zendesk_documentation_path, type: String, default: 'hc' field :zendesk_support_path, type: String, default: 'hc/en-us/requests' field :zendesk_updates_path, type: String, default: 'hc' # Switchboard field :switchboard_base_url, type: String, default: 'https://switchboard.app47.com' field :switchboard_stack_id, type: String field :switchboard_stack_api_token, type: String field :switchboard_last_sync_at, type: Time # TTLs field :user_model_audit_log_ttl, type: Integer, default: 365 field :slack_notification_ttl, type: Integer, default: 5 field :email_notification_ttl, type: Integer, default: 180 # # Validations # validates :environment, presence: true, uniqueness: true validates :slack_support_channel, presence: true validates :slack_sales_channel, presence: true validates :default_time_zone, presence: true validates :switchboard_base_url, url: true validates :zendesk_base_url, url: true end base.extend ClassMethods end |
Instance Method Details
#aws_auto_scaling_configured? ⇒ Boolean
Determine if auto scaling group is configured
175 176 177 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 175 def aws_auto_scaling_configured? aws_configured? && aws_auto_scaling_group_name.present? end |
#aws_configured? ⇒ Boolean
Determine if AWS is configured
168 169 170 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 168 def aws_configured? [aws_region.present?, aws_access_key_id.present?, aws_secret_access_key.present?].all? end |
#long_cache_time ⇒ Object
147 148 149 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 147 def long_cache_time long_cache.minutes end |
#mail_gun_configured? ⇒ Boolean
Determine if mailgun is configured
161 162 163 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 161 def mail_gun_configured? smtp_configured? && mailgun_api_key.present? end |
#medium_cache_time ⇒ Object
143 144 145 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 143 def medium_cache_time medium_cache.minutes end |
#secure_fields ⇒ Object
Make sure the password doesn’t get blanked out on an update
127 128 129 130 131 132 133 134 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 127 def secure_fields super + %i[smtp_password aws_access_secret mailgun_api_key switchboard_stack_api_token twilio_auth_token zendesk_token] end |
#short_cache_time ⇒ Object
Cache times in minutes
139 140 141 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 139 def short_cache_time short_cache.minutes end |
#slack_configured? ⇒ Boolean
Determine if Slack is configured
Examples
switchboard_configured?
# => true || false
272 273 274 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 272 def slack_configured? slack_api_url.present? end |
#smtp_configured? ⇒ Boolean
Determine if SMTP is configured
154 155 156 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 154 def smtp_configured? smtp_name.present? && smtp_address.present? && smtp_domain.present? end |
#switchboard_configured? ⇒ Boolean
Public: Determine if switchboard is configured
Examples
switchboard_configured?
# => true || false
248 249 250 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 248 def switchboard_configured? [switchboard_base_url.present?, switchboard_stack_api_token.present?, switchboard_stack_id.present?].all? end |
#twilio_configured? ⇒ Boolean
Determine if twillio is configured at a system configuration
Examples
switchboard_configured?
# => true || false
260 261 262 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 260 def twilio_configured? [twilio_account_id.present?, twilio_auth_token.present?, twilio_phone_number.present?].all? end |
#zendesk_configured? ⇒ Boolean
Is zendesk configured?
233 234 235 236 237 238 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 233 def zendesk_configured? [zendesk_token.present?, zendesk_base_url.present?, zendesk_documentation_path.present?, zendesk_support_path.present?].all? end |
#zendesk_documentation_url(user = nil) ⇒ Object
Return the zendesk documentation URL
182 183 184 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 182 def zendesk_documentation_url(user = nil) zendesk_url(forward_to: zendesk_documentation_path, user: user) end |
#zendesk_new_request_url(user = nil) ⇒ Object
Return the zendesk support URL
196 197 198 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 196 def zendesk_new_request_url(user = nil) zendesk_url(forward_to: "#{zendesk_support_path}/new", user: user) end |
#zendesk_requests_url(user = nil) ⇒ Object
Return the zendesk support URL
189 190 191 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 189 def zendesk_requests_url(user = nil) zendesk_url(forward_to: zendesk_support_path, user: user) end |
#zendesk_updates_url(user = nil) ⇒ Object
Return the zendesk update URL
203 204 205 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 203 def zendesk_updates_url(user = nil) zendesk_url(forward_to: zendesk_updates_path, user: user) end |
#zendesk_url(forward_to: zendesk_documentation_path, user: nil) ⇒ Object
Generate a Zendesk URL
If a user is passed in and Zendesk is configured then return a JWT enabled URL for SSO authentication to Zendesk.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/app/models/concerns/core_system_configuration.rb', line 213 def zendesk_url(forward_to: zendesk_documentation_path, user: nil) config = SystemConfiguration.configuration path = if config.zendesk_configured? && user.present? time_now = Time.now.to_i jti = "#{time_now}/#{rand(36 ** 64).to_s(36)}" payload = { jwt: JWT.encode({ iat: time_now, # Seconds since epoch, determine when this token is stale jti: jti, # Unique token identifier, helps prevent replay attacks name: user.name, email: user.email }, config.zendesk_token), return_to: CGI.escape([config.zendesk_base_url, forward_to].join('/')) } ['access/jwt', payload.to_query].join('?') else forward_to end [config.zendesk_base_url, path].join('/') end |