2021-08-24 03:46:28 -04: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 07:20:10 -05:00
|
|
|
["disabled"] + TrustLevel.valid_range.to_a + special_groups
|
2021-08-24 03:46:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.translation(value)
|
2023-01-09 07:20:10 -05:00
|
|
|
if value == "disabled"
|
|
|
|
I18n.t("site_settings.disabled")
|
2021-08-24 03:46:28 -04:00
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.matches?(value, user)
|
|
|
|
case value
|
2023-01-09 07:20:10 -05:00
|
|
|
when "disabled"
|
2021-08-24 03:46:28 -04:00
|
|
|
false
|
2023-01-09 07:20:10 -05:00
|
|
|
when "staff"
|
2021-08-24 03:46:28 -04:00
|
|
|
user.staff?
|
2023-01-09 07:20:10 -05:00
|
|
|
when "admin"
|
2021-08-24 03:46:28 -04:00
|
|
|
user.admin?
|
|
|
|
else
|
|
|
|
user.has_trust_level?(value.to_i) || user.staff?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|