2021-08-24 02:46:28 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class TrustLevelAndStaffAndDisabledSetting < TrustLevelAndStaffSetting
|
|
|
|
def self.valid_value?(val)
|
|
|
|
valid_values.include?(val) || (val.to_i.to_s == val.to_s && valid_values.include?(val.to_i))
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.valid_values
|
2023-01-09 06:20:10 -06:00
|
|
|
["disabled"] + TrustLevel.valid_range.to_a + special_groups
|
2021-08-24 02:46:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.translation(value)
|
2023-01-09 06:20:10 -06:00
|
|
|
if value == "disabled"
|
|
|
|
I18n.t("site_settings.disabled")
|
2021-08-24 02:46:28 -05:00
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.matches?(value, user)
|
|
|
|
case value
|
2023-01-09 06:20:10 -06:00
|
|
|
when "disabled"
|
2021-08-24 02:46:28 -05:00
|
|
|
false
|
2023-01-09 06:20:10 -06:00
|
|
|
when "staff"
|
2021-08-24 02:46:28 -05:00
|
|
|
user.staff?
|
2023-01-09 06:20:10 -06:00
|
|
|
when "admin"
|
2021-08-24 02:46:28 -05:00
|
|
|
user.admin?
|
|
|
|
else
|
|
|
|
user.has_trust_level?(value.to_i) || user.staff?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|