discourse/lib/trust_level.rb
Gerhard Schlager 41ee5b7c86
FIX: Don't store translated trust level names in anonymous cache (#13224)
Refactors `TrustLevel` and moves translations from server to client

Additional changes:
  * "staff" and "admin" wasn't translatable in site settings
  * it replaces a concatenated string with a translation
  * uses translation for trust levels in users_by_trust_level report
  * adds a DB migration to rename keys of translation overrides affected by this commit
2021-06-01 22:11:48 +02:00

36 lines
584 B
Ruby

# frozen_string_literal: true
class InvalidTrustLevel < StandardError; end
class TrustLevel
class << self
def [](level)
raise InvalidTrustLevel if !valid?(level)
level
end
def levels
@levels ||= Enum.new(:newuser, :basic, :member, :regular, :leader, start: 0)
end
def valid?(level)
valid_range === level
end
def valid_range
(0..4)
end
def compare(current_level, level)
(current_level || 0) >= level
end
def name(level)
I18n.t("js.trust_levels.names.#{levels[level]}")
end
end
end