Add deprecation warnings for url based site settings.
This commit is contained in:
parent
44391ee8ab
commit
72370b9c36
|
@ -176,45 +176,45 @@ class SiteSetting < ActiveRecord::Base
|
|||
}.each { |client_setting| client_settings << client_setting }
|
||||
|
||||
def self.site_logo_url
|
||||
self.logo&.url || self.logo_url
|
||||
self.logo&.url || self.logo_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_logo_small_url
|
||||
self.logo_small&.url || self.logo_small_url
|
||||
self.logo_small&.url || self.logo_small_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_digest_logo_url
|
||||
self.digest_logo&.url || self.digest_logo_url
|
||||
self.digest_logo&.url || self.digest_logo_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_mobile_logo_url
|
||||
self.mobile_logo&.url || self.mobile_logo_url
|
||||
self.mobile_logo&.url || self.mobile_logo_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_large_icon_url
|
||||
self.large_icon&.url || self.large_icon_url
|
||||
self.large_icon&.url || self.large_icon_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_favicon_url
|
||||
self.favicon&.url || self.favicon_url
|
||||
self.favicon&.url || self.favicon_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_apple_touch_icon_url
|
||||
self.apple_touch_icon&.url || self.apple_touch_icon_url
|
||||
self.apple_touch_icon&.url || self.apple_touch_icon_url(warn: false)
|
||||
end
|
||||
|
||||
def self.opengraph_image_url
|
||||
self.opengraph_image&.url || self.default_opengraph_image_url
|
||||
self.opengraph_image&.url || self.default_opengraph_image_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_twitter_summary_large_image_url
|
||||
self.twitter_summary_large_image&.url ||
|
||||
self.twitter_summary_large_image_url
|
||||
self.twitter_summary_large_image_url(warn: false)
|
||||
end
|
||||
|
||||
def self.site_push_notifications_icon_url
|
||||
SiteSetting.push_notifications_icon&.url ||
|
||||
SiteSetting.push_notifications_icon_url
|
||||
SiteSetting.push_notifications_icon_url(warn: false)
|
||||
end
|
||||
|
||||
def self.shared_drafts_enabled?
|
||||
|
|
|
@ -2,22 +2,53 @@ module SiteSettings; end
|
|||
|
||||
module SiteSettings::DeprecatedSettings
|
||||
DEPRECATED_SETTINGS = [
|
||||
%w{logo_url logo 2.4},
|
||||
%w{logo_small_url logo_small 2.4},
|
||||
%w{digest_logo_url digest_logo 2.4},
|
||||
%w{mobile_logo_url mobile_logo 2.4},
|
||||
%w{large_icon_url large_icon 2.4},
|
||||
%w{favicon_url favicon 2.4},
|
||||
%w{apple_touch_icon_url apple_touch_icon 2.4},
|
||||
%w{default_opengraph_image_url opengraph_image 2.4},
|
||||
%w{twitter_summary_large_image_url twitter_summary_large_image 2.4},
|
||||
%w{push_notifications_icon_url push_notifications_icon 2.4}
|
||||
]
|
||||
|
||||
def setup_deprecated_methods
|
||||
DEPRECATED_SETTINGS.each do |old_setting, new_setting, version|
|
||||
define_singleton_method old_setting do
|
||||
logger.warn("`SiteSetting.#{old_setting}` has been deprecated and will be removed in the #{version} Release. Please use `SiteSetting.#{new_setting}` instead")
|
||||
define_singleton_method old_setting do |warn: true|
|
||||
if warn
|
||||
logger.warn(
|
||||
"`SiteSetting.#{old_setting}` has been deprecated and will be " +
|
||||
"removed in the #{version} Release. Please use " +
|
||||
"`SiteSetting.#{new_setting}` instead"
|
||||
)
|
||||
end
|
||||
|
||||
self.public_send new_setting
|
||||
end
|
||||
|
||||
define_singleton_method "#{old_setting}?" do
|
||||
logger.warn("`SiteSetting.#{old_setting}?` has been deprecated and will be removed in the #{version} Release. Please use `SiteSetting.#{new_setting}?` instead")
|
||||
define_singleton_method "#{old_setting}?" do |warn: true|
|
||||
if warn
|
||||
logger.warn(
|
||||
"`SiteSetting.#{old_setting}?` has been deprecated and will be " +
|
||||
"removed in the #{version} Release. Please use " +
|
||||
"`SiteSetting.#{new_setting}?` instead"
|
||||
)
|
||||
end
|
||||
|
||||
self.public_send "#{new_setting}?"
|
||||
end
|
||||
|
||||
define_singleton_method "#{old_setting}=" do |val|
|
||||
logger.warn("`SiteSetting.#{old_setting}=` has been deprecated and will be removed in the #{version} Release. Please use `SiteSetting.#{new_setting}=` instead")
|
||||
define_singleton_method "#{old_setting}=" do |val, warn: true|
|
||||
if warn
|
||||
logger.warn(
|
||||
"`SiteSetting.#{old_setting}=` has been deprecated and will be " +
|
||||
"removed in the #{version} Release. Please use " +
|
||||
"`SiteSetting.#{new_setting}=` instead"
|
||||
)
|
||||
end
|
||||
|
||||
self.public_send "#{new_setting}=", val
|
||||
end
|
||||
end
|
||||
|
|
|
@ -153,6 +153,12 @@ describe SiteSetting do
|
|||
context 'deprecated site settings' do
|
||||
before do
|
||||
SiteSetting.force_https = true
|
||||
@orig_logger = Rails.logger
|
||||
Rails.logger = @fake_logger = FakeLogger.new
|
||||
end
|
||||
|
||||
after do
|
||||
Rails.logger = @orig_logger
|
||||
end
|
||||
|
||||
it 'should act as a proxy to the new methods' do
|
||||
|
@ -163,8 +169,14 @@ describe SiteSetting do
|
|||
|
||||
SiteSetting.setup_deprecated_methods
|
||||
|
||||
expect(SiteSetting.use_https).to eq(true)
|
||||
expect(SiteSetting.use_https?).to eq(true)
|
||||
expect do
|
||||
expect(SiteSetting.use_https).to eq(true)
|
||||
expect(SiteSetting.use_https?).to eq(true)
|
||||
end.to change { @fake_logger.warnings.count }.by(2)
|
||||
|
||||
expect do
|
||||
expect(SiteSetting.use_https(warn: false))
|
||||
end.to_not change { @fake_logger.warnings }
|
||||
|
||||
SiteSetting.use_https = false
|
||||
|
||||
|
|
Loading…
Reference in New Issue