mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-18 11:32:24 -05:00
b64a4100fa
I blame me for this mistake.. visitor means other stuff in practice. New User is correct meaning.
36 lines
673 B
Ruby
36 lines
673 B
Ruby
require_dependency 'enum'
|
|
|
|
class TrustLevel
|
|
attr_reader :id, :name
|
|
|
|
class << self
|
|
def levels
|
|
@levels ||= Enum.new(
|
|
:newuser, :basic, :regular, :leader, :elder, start: 0
|
|
)
|
|
end
|
|
|
|
def all
|
|
levels.map do |name_key, id|
|
|
TrustLevel.new(name_key, id)
|
|
end
|
|
end
|
|
|
|
def valid_level?(level)
|
|
levels.valid?(level)
|
|
end
|
|
|
|
def compare(current_level, level)
|
|
(current_level || levels[:newuser]) >= levels[level] rescue binding.pry
|
|
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 }
|
|
end
|
|
end
|