discourse/lib/site_settings/deprecated_settings.rb
Krzysztof Kotlarek 7dd150bc95
DEV: Convert min_trust_to_edit_wiki_post to groups (#24766)
This change converts the min_trust_to_edit_wiki_post site setting to edit_wiki_post_allowed_groups.

See: https://meta.discourse.org/t/283408

Hides the old setting
Adds the new site setting
Add a deprecation warning
Updates to use the new setting
Adds a migration to fill in the new setting if the old setting was changed
Adds an entry to the site_setting.keywords section
Updates tests to account for the new change
After a couple of months, we will remove the email_in_min_trust setting entirely.

Internal ref: /t/117248
2023-12-12 15:20:37 +11:00

86 lines
2.7 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"],
["shared_drafts_min_trust_level", "shared_drafts_allowed_groups", false, "3.3"],
["min_trust_level_for_here_mention", "here_mention_allowed_groups", false, "3.3"],
["approve_unless_trust_level", "approve_unless_allowed_groups", false, "3.3"],
[
"approve_new_topics_unless_trust_level",
"approve_new_topics_unless_allowed_groups",
false,
"3.3",
],
["email_in_min_trust", "email_in_allowed_groups", false, "3.3"],
["min_trust_to_edit_wiki_post", "edit_wiki_post_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