mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 23:06:57 +08:00
d2f3c829db
* rename `User#password_required` to `User#password_required!` * emails with "i" @ something are a special case as well * get rid of `self.` and returns where possible * prefer "unless a" instead of "if !a" * `unread_notifications` without manually iterating * introduce `User#moderator?` * introduce `TrustLevel#valid_key?`, `TrustLevel#compare`, and `TrustLevel#level_key`
44 lines
745 B
Ruby
44 lines
745 B
Ruby
class TrustLevel
|
|
|
|
attr_reader :id, :name
|
|
|
|
class << self
|
|
def levels
|
|
{ new: 0,
|
|
basic: 1,
|
|
regular: 2,
|
|
experienced: 3,
|
|
advanced: 4,
|
|
moderator: 5 }
|
|
end
|
|
alias_method :Levels, :levels
|
|
|
|
def all
|
|
levels.map do |name_key, id|
|
|
TrustLevel.new(name_key, id)
|
|
end
|
|
end
|
|
|
|
def valid_level?(level)
|
|
levels.has_key?(level)
|
|
end
|
|
|
|
def compare(current_level, level)
|
|
(current_level || levels[:new]) >= levels[level]
|
|
end
|
|
|
|
def level_key(level)
|
|
levels.invert[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 }
|
|
end
|
|
end
|