discourse/lib/site_settings/deprecated_settings.rb
Martin Brennan 9db4eaa870
DEV: Change anonymous_posting_min_trust_level to a group-based setting (#24072)
No plugins or themes rely on anonymous_posting_min_trust_level so we
can just switch straight over to anonymous_posting_allowed_groups

This also adds an AUTO_GROUPS const which can be imported in JS
tests which is analogous to the one defined in group.rb. This can be used
to set the current user's groups where JS tests call for checking these groups
against site settings.

Finally a AtLeastOneGroupValidator validator is added for group_list site
settings which ensures that at least one group is always selected, since if
you want to allow all users to use a feature in this way you can just use
the everyone group.
2023-10-25 11:45:10 +10:00

75 lines
2.1 KiB
Ruby

# frozen_string_literal: true
module SiteSettings
end
module SiteSettings::DeprecatedSettings
SETTINGS = [
# [<old setting>, <new_setting>, <override>, <version to drop>]
["search_tokenize_chinese_japanese_korean", "search_tokenize_chinese", true, "2.9"],
["default_categories_regular", "default_categories_normal", true, "3.0"],
["anonymous_posting_min_trust_level", "anonymous_posting_allowed_groups", false, "3.3"],
]
def setup_deprecated_methods
SETTINGS.each do |old_setting, new_setting, override, version|
unless override
SiteSetting.singleton_class.public_send(
:alias_method,
:"_#{old_setting}",
:"#{old_setting}",
)
end
define_singleton_method old_setting do |warn: true|
if warn
Discourse.deprecate(
"`SiteSetting.#{old_setting}` has been deprecated. Please use `SiteSetting.#{new_setting}` instead.",
drop_from: version,
)
end
self.public_send(override ? new_setting : "_#{old_setting}")
end
unless override
SiteSetting.singleton_class.public_send(
:alias_method,
:"_#{old_setting}?",
:"#{old_setting}?",
)
end
define_singleton_method "#{old_setting}?" do |warn: true|
if warn
Discourse.deprecate(
"`SiteSetting.#{old_setting}?` has been deprecated. Please use `SiteSetting.#{new_setting}?` instead.",
drop_from: version,
)
end
self.public_send("#{override ? new_setting : "_" + old_setting}?")
end
unless override
SiteSetting.singleton_class.public_send(
:alias_method,
:"_#{old_setting}=",
:"#{old_setting}=",
)
end
define_singleton_method "#{old_setting}=" do |val, warn: true|
if warn
Discourse.deprecate(
"`SiteSetting.#{old_setting}=` has been deprecated. Please use `SiteSetting.#{new_setting}=` instead.",
drop_from: version,
)
end
self.public_send("#{override ? new_setting : "_" + old_setting}=", val)
end
end
end
end