discourse/lib/site_settings/deprecated_settings.rb
Ted Johansson 48116186af
DEV: Convert tl4_delete_posts_and_topics to groups (#24866)
We're changing the implementation of trust levels to use groups. Part of this is to have site settings that reference trust levels use groups instead. It converts the tl4_delete_posts_and_topics  site setting to delete_all_posts_and_topics_allowed_groups.

This one is a bit different from previous ones, as it's a boolean flag, and the default should be no group. Pay special attention to the migration during review.
2023-12-14 09:56:42 +08:00

91 lines
3.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"],
["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"],
["allow_uploaded_avatars", "uploaded_avatars_allowed_groups", false, "3.3"],
["min_trust_to_create_topic", "create_topic_allowed_groups", false, "3.3"],
["min_trust_to_edit_post", "edit_post_allowed_groups", false, "3.3"],
["min_trust_to_flag_posts", "flag_post_allowed_groups", false, "3.3"],
["tl4_delete_posts_and_topics", "delete_all_posts_and_topics_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