DEV: Add auto map from TL -> group site settings in DeprecatedSettings (#24959)

When setting an old TL based site setting in the console e.g.:

SiteSetting.min_trust_level_to_allow_ignore = TrustLevel[3]

We will silently convert this to the corresponding Group::AUTO_GROUP. And vice-versa, when we read the value on the old setting, we will automatically get the lowest trust level corresponding to the lowest auto group for the new setting in the database.
This commit is contained in:
Martin Brennan
2023-12-26 16:39:18 +10:00
committed by GitHub
parent 12131c8e21
commit 89705be722
7 changed files with 377 additions and 49 deletions

View File

@@ -145,6 +145,15 @@ class Group < ActiveRecord::Base
@visibility_levels = Enum.new(public: 0, logged_on_users: 1, members: 2, staff: 3, owners: 4)
end
def self.auto_groups_between(lower, upper)
lower_group = Group::AUTO_GROUPS[lower.to_sym]
upper_group = Group::AUTO_GROUPS[upper.to_sym]
return [] if lower_group.blank? || upper_group.blank?
(lower_group..upper_group).to_a & AUTO_GROUPS.values
end
validates :mentionable_level, inclusion: { in: ALIAS_LEVELS.values }
validates :messageable_level, inclusion: { in: ALIAS_LEVELS.values }