mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 19:46:55 +08:00
e62e93f83a
This will replace `enable_personal_messages` and `min_trust_to_send_messages`, this commit introduces the setting `personal_message_enabled_groups` and uses it in all places that `enable_personal_messages` and `min_trust_to_send_messages` currently apply. A migration is included to set `personal_message_enabled_groups` based on the following rules: * If `enable_personal_messages` was false, then set `personal_message_enabled_groups` to `3`, which is the staff auto group * If `min_trust_to_send_messages` is not default (1) and the above condition is false, then set the `personal_message_enabled_groups` setting to the appropriate auto group based on the trust level * Otherwise just set `personal_message_enabled_groups` to 11 which is the TL1 auto group After follow-up PRs to plugins using these old settings, we will be able to drop the old settings from core, in the meantime I've added DEPRECATED notices to their descriptions and added them to the deprecated site settings list. This commit also introduces a `_map` shortcut method definition for all `group_list` site settings, e.g. `SiteSetting.personal_message_enabled_groups` also has `SiteSetting.personal_message_enabled_groups_map` available, which automatically splits the setting by `|` and converts it into an array of integers.
69 lines
2.2 KiB
Ruby
69 lines
2.2 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'],
|
|
['min_trust_to_send_messages', 'personal_message_enabled_groups', false, '3.0'],
|
|
['enable_personal_messages', 'personal_message_enabled_groups', false, '3.0'],
|
|
]
|
|
|
|
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
|