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
This commit is contained in:
Gerhard Schlager
2021-06-01 22:11:48 +02:00
committed by GitHub
parent 409c8585e4
commit 41ee5b7c86
17 changed files with 144 additions and 88 deletions

View File

@ -4,8 +4,6 @@ class InvalidTrustLevel < StandardError; end
class TrustLevel
attr_reader :id, :name
class << self
def [](level)
@ -17,12 +15,6 @@ class TrustLevel
@levels ||= Enum.new(:newuser, :basic, :member, :regular, :leader, start: 0)
end
def all
levels.map do |name_key, id|
TrustLevel.new(name_key, id)
end
end
def valid?(level)
valid_range === level
end
@ -35,15 +27,9 @@ class TrustLevel
(current_level || 0) >= level
end
end
def initialize(name_key, id)
@name = I18n.t("trust_levels.#{name_key}.title")
@id = id
end
def serializable_hash
{ id: @id, name: @name }
def name(level)
I18n.t("js.trust_levels.names.#{levels[level]}")
end
end
end