2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
class SiteSetting < ActiveRecord::Base
|
2018-12-19 03:20:48 -06:00
|
|
|
extend GlobalPath
|
2013-02-05 13:16:51 -06:00
|
|
|
extend SiteSettingExtension
|
|
|
|
|
|
|
|
validates_presence_of :name
|
|
|
|
validates_presence_of :data_type
|
|
|
|
|
2014-12-11 10:08:47 -06:00
|
|
|
after_save do |site_setting|
|
|
|
|
DiscourseEvent.trigger(:site_setting_saved, site_setting)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2013-11-19 13:43:01 -06:00
|
|
|
def self.load_settings(file)
|
|
|
|
SiteSettings::YamlLoader.new(file).load do |category, name, default, opts|
|
2017-08-06 20:43:09 -05:00
|
|
|
setting(name, default, opts.merge(category: category))
|
2013-11-06 14:47:26 -06:00
|
|
|
end
|
|
|
|
end
|
2013-10-23 18:05:51 -05:00
|
|
|
|
2013-11-19 13:43:01 -06:00
|
|
|
load_settings(File.join(Rails.root, 'config', 'site_settings.yml'))
|
|
|
|
|
2014-12-11 10:08:47 -06:00
|
|
|
unless Rails.env.test? && ENV['LOAD_PLUGINS'] != "1"
|
|
|
|
Dir[File.join(Rails.root, "plugins", "*", "config", "settings.yml")].each do |file|
|
|
|
|
load_settings(file)
|
|
|
|
end
|
2013-11-19 13:43:01 -06:00
|
|
|
end
|
|
|
|
|
2018-11-14 03:32:32 -06:00
|
|
|
setup_deprecated_methods
|
2014-03-28 00:36:17 -05:00
|
|
|
client_settings << :available_locales
|
2014-02-07 21:24:10 -06:00
|
|
|
|
|
|
|
def self.available_locales
|
2017-12-13 15:17:36 -06:00
|
|
|
LocaleSiteSetting.values.to_json
|
2014-02-07 21:24:10 -06:00
|
|
|
end
|
2013-11-19 13:43:01 -06:00
|
|
|
|
2013-02-26 10:27:59 -06:00
|
|
|
def self.topic_title_length
|
|
|
|
min_topic_title_length..max_topic_title_length
|
|
|
|
end
|
|
|
|
|
2013-06-04 16:58:25 -05:00
|
|
|
def self.private_message_title_length
|
2018-01-30 23:56:00 -06:00
|
|
|
min_personal_message_title_length..max_topic_title_length
|
2013-06-04 16:58:25 -05:00
|
|
|
end
|
|
|
|
|
2013-02-28 12:54:12 -06:00
|
|
|
def self.post_length
|
|
|
|
min_post_length..max_post_length
|
|
|
|
end
|
2013-03-28 08:01:13 -05:00
|
|
|
|
2015-03-19 09:17:55 -05:00
|
|
|
def self.first_post_length
|
|
|
|
min_first_post_length..max_post_length
|
|
|
|
end
|
|
|
|
|
2013-06-13 03:18:17 -05:00
|
|
|
def self.private_message_post_length
|
2018-01-30 23:56:00 -06:00
|
|
|
min_personal_message_post_length..max_post_length
|
2013-06-13 03:18:17 -05:00
|
|
|
end
|
|
|
|
|
2013-06-21 15:31:40 -05:00
|
|
|
def self.top_menu_items
|
|
|
|
top_menu.split('|').map { |menu_item| TopMenuItem.new(menu_item) }
|
|
|
|
end
|
|
|
|
|
2013-03-28 08:01:13 -05:00
|
|
|
def self.homepage
|
2013-06-21 15:31:40 -05:00
|
|
|
top_menu_items[0].name
|
2013-03-28 08:01:13 -05:00
|
|
|
end
|
|
|
|
|
2013-07-15 18:59:23 -05:00
|
|
|
def self.anonymous_menu_items
|
2013-12-23 17:50:36 -06:00
|
|
|
@anonymous_menu_items ||= Set.new Discourse.anonymous_filters.map(&:to_s)
|
2013-07-15 18:59:23 -05:00
|
|
|
end
|
|
|
|
|
2013-03-28 08:01:13 -05:00
|
|
|
def self.anonymous_homepage
|
2013-07-15 18:59:23 -05:00
|
|
|
top_menu_items.map { |item| item.name }
|
2017-07-27 20:20:09 -05:00
|
|
|
.select { |item| anonymous_menu_items.include?(item) }
|
|
|
|
.first
|
2013-07-15 18:59:23 -05:00
|
|
|
end
|
|
|
|
|
2014-04-21 15:59:53 -05:00
|
|
|
def self.should_download_images?(src)
|
|
|
|
setting = disabled_image_download_domains
|
2019-06-03 13:17:25 -05:00
|
|
|
return true if setting.blank?
|
2014-04-21 15:59:53 -05:00
|
|
|
|
2014-05-07 12:49:16 -05:00
|
|
|
host = URI.parse(src).host
|
2019-06-03 13:17:25 -05:00
|
|
|
!setting.split("|").include?(host)
|
2018-08-14 05:23:32 -05:00
|
|
|
rescue URI::Error
|
2019-06-03 13:17:25 -05:00
|
|
|
true
|
2014-04-21 15:59:53 -05:00
|
|
|
end
|
|
|
|
|
2013-12-16 04:44:59 -06:00
|
|
|
def self.scheme
|
2016-06-27 04:26:43 -05:00
|
|
|
force_https? ? "https" : "http"
|
2013-12-16 04:44:59 -06:00
|
|
|
end
|
|
|
|
|
2016-10-11 12:22:43 -05:00
|
|
|
def self.min_redirected_to_top_period(duration)
|
2019-06-03 13:17:25 -05:00
|
|
|
ListController.best_period_with_topics_for(duration)
|
2015-09-21 13:28:20 -05:00
|
|
|
end
|
|
|
|
|
2019-03-14 10:39:10 -05:00
|
|
|
def self.queue_jobs=(val)
|
|
|
|
Discourse.deprecate("queue_jobs is deprecated. Please use Jobs.run_immediately! instead")
|
|
|
|
val ? Jobs.run_later! : Jobs.run_immediately!
|
|
|
|
end
|
|
|
|
|
2016-03-16 16:28:01 -05:00
|
|
|
def self.email_polling_enabled?
|
|
|
|
SiteSetting.manual_polling_enabled? || SiteSetting.pop3_polling_enabled?
|
|
|
|
end
|
2016-08-03 10:55:54 -05:00
|
|
|
|
2019-07-12 13:42:43 -05:00
|
|
|
WATCHED_SETTINGS ||= [
|
2019-10-01 13:41:03 -05:00
|
|
|
:default_locale,
|
2019-07-12 13:42:43 -05:00
|
|
|
:attachment_content_type_blacklist,
|
|
|
|
:attachment_filename_blacklist,
|
|
|
|
:unicode_username_character_whitelist,
|
|
|
|
:markdown_typographer_quotation_marks
|
|
|
|
]
|
|
|
|
|
|
|
|
def self.reset_cached_settings!
|
|
|
|
@attachment_content_type_blacklist_regex = nil
|
|
|
|
@attachment_filename_blacklist_regex = nil
|
|
|
|
@unicode_username_whitelist_regex = nil
|
|
|
|
end
|
|
|
|
|
2016-08-03 10:55:54 -05:00
|
|
|
def self.attachment_content_type_blacklist_regex
|
|
|
|
@attachment_content_type_blacklist_regex ||= Regexp.union(SiteSetting.attachment_content_type_blacklist.split("|"))
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.attachment_filename_blacklist_regex
|
|
|
|
@attachment_filename_blacklist_regex ||= Regexp.union(SiteSetting.attachment_filename_blacklist.split("|"))
|
|
|
|
end
|
2017-10-06 00:20:01 -05:00
|
|
|
|
2019-04-23 05:22:47 -05:00
|
|
|
def self.unicode_username_character_whitelist_regex
|
2019-07-12 13:42:43 -05:00
|
|
|
@unicode_username_whitelist_regex ||= SiteSetting.unicode_username_character_whitelist.present? \
|
2019-04-23 05:22:47 -05:00
|
|
|
? Regexp.new(SiteSetting.unicode_username_character_whitelist) : nil
|
|
|
|
end
|
|
|
|
|
2017-10-06 00:20:01 -05:00
|
|
|
# helpers for getting s3 settings that fallback to global
|
|
|
|
class Upload
|
|
|
|
def self.s3_cdn_url
|
|
|
|
SiteSetting.enable_s3_uploads ? SiteSetting.s3_cdn_url : GlobalSetting.s3_cdn_url
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.s3_region
|
|
|
|
SiteSetting.enable_s3_uploads ? SiteSetting.s3_region : GlobalSetting.s3_region
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.s3_upload_bucket
|
|
|
|
SiteSetting.enable_s3_uploads ? SiteSetting.s3_upload_bucket : GlobalSetting.s3_bucket
|
|
|
|
end
|
|
|
|
|
2018-07-15 23:44:55 -05:00
|
|
|
def self.s3_endpoint
|
|
|
|
SiteSetting.enable_s3_uploads ? SiteSetting.s3_endpoint : GlobalSetting.s3_endpoint
|
|
|
|
end
|
|
|
|
|
2017-10-06 00:20:01 -05:00
|
|
|
def self.enable_s3_uploads
|
|
|
|
SiteSetting.enable_s3_uploads || GlobalSetting.use_s3?
|
|
|
|
end
|
|
|
|
|
2018-07-06 02:52:23 -05:00
|
|
|
def self.s3_base_url
|
|
|
|
path = self.s3_upload_bucket.split("/", 2)[1]
|
|
|
|
"#{self.absolute_base_url}#{path ? '/' + path : ''}"
|
|
|
|
end
|
|
|
|
|
2017-10-06 00:20:01 -05:00
|
|
|
def self.absolute_base_url
|
2018-07-15 23:44:55 -05:00
|
|
|
url_basename = SiteSetting.s3_endpoint.split('/')[-1]
|
2018-05-16 15:10:15 -05:00
|
|
|
bucket = SiteSetting.enable_s3_uploads ? Discourse.store.s3_bucket_name : GlobalSetting.s3_bucket_name
|
2017-10-06 00:20:01 -05:00
|
|
|
|
2018-07-06 17:15:28 -05:00
|
|
|
# cf. http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
|
2019-02-05 10:50:27 -06:00
|
|
|
if SiteSetting.s3_endpoint.blank? || SiteSetting.s3_endpoint.end_with?("amazonaws.com")
|
2018-12-26 10:34:49 -06:00
|
|
|
if SiteSetting.Upload.s3_region.start_with?("cn-")
|
2018-08-26 20:22:46 -05:00
|
|
|
"//#{bucket}.s3.#{SiteSetting.Upload.s3_region}.amazonaws.com.cn"
|
2018-07-15 23:44:55 -05:00
|
|
|
else
|
2018-08-26 20:22:46 -05:00
|
|
|
"//#{bucket}.s3.dualstack.#{SiteSetting.Upload.s3_region}.amazonaws.com"
|
2018-07-15 23:44:55 -05:00
|
|
|
end
|
2018-07-06 17:15:28 -05:00
|
|
|
else
|
2018-07-15 23:44:55 -05:00
|
|
|
"//#{bucket}.#{url_basename}"
|
2018-07-06 17:15:28 -05:00
|
|
|
end
|
2017-10-06 00:20:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.Upload
|
|
|
|
SiteSetting::Upload
|
|
|
|
end
|
|
|
|
|
2020-03-15 05:17:28 -05:00
|
|
|
def self.require_invite_code
|
|
|
|
invite_code.present?
|
|
|
|
end
|
|
|
|
client_settings << :require_invite_code
|
|
|
|
|
2018-11-14 01:03:02 -06:00
|
|
|
%i{
|
|
|
|
site_logo_url
|
|
|
|
site_logo_small_url
|
|
|
|
site_mobile_logo_url
|
|
|
|
site_favicon_url
|
|
|
|
}.each { |client_setting| client_settings << client_setting }
|
|
|
|
|
2019-01-02 01:29:17 -06:00
|
|
|
%i{
|
|
|
|
logo
|
|
|
|
logo_small
|
|
|
|
digest_logo
|
|
|
|
mobile_logo
|
|
|
|
large_icon
|
2019-05-01 08:44:45 -05:00
|
|
|
manifest_icon
|
2019-01-02 01:29:17 -06:00
|
|
|
favicon
|
|
|
|
apple_touch_icon
|
|
|
|
twitter_summary_large_image
|
|
|
|
opengraph_image
|
|
|
|
push_notifications_icon
|
|
|
|
}.each do |setting_name|
|
|
|
|
define_singleton_method("site_#{setting_name}_url") do
|
2019-05-01 08:44:45 -05:00
|
|
|
if SiteIconManager.respond_to?("#{setting_name}_url")
|
|
|
|
return SiteIconManager.public_send("#{setting_name}_url")
|
|
|
|
end
|
|
|
|
|
2019-01-02 01:29:17 -06:00
|
|
|
upload = self.public_send(setting_name)
|
|
|
|
upload ? full_cdn_url(upload.url) : ''
|
2019-01-11 01:46:31 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-13 14:59:12 -05:00
|
|
|
def self.shared_drafts_enabled?
|
|
|
|
c = SiteSetting.shared_drafts_category
|
|
|
|
c.present? && c.to_i != SiteSetting.uncategorized_category_id.to_i
|
|
|
|
end
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
2013-05-23 21:48:32 -05:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: site_settings
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
2019-01-11 13:29:56 -06:00
|
|
|
# name :string not null
|
2013-05-23 21:48:32 -05:00
|
|
|
# data_type :integer not null
|
|
|
|
# value :text
|
2014-08-27 00:30:17 -05:00
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2013-05-23 21:48:32 -05:00
|
|
|
#
|
2019-04-02 00:17:55 -05:00
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_site_settings_on_name (name) UNIQUE
|
|
|
|
#
|