mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 06:23:41 +08:00
41ee5b7c86
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
36 lines
584 B
Ruby
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
|