mirror of
https://github.com/discourse/discourse.git
synced 2025-01-08 20:03:44 +08:00
8144730ebb
Previous commit 479c0a3051
was done with the assumption that this info was defined on user serializer but it was actually defined on post serializer in core. This commit extends the user serializer for messages to add this data to the user.
Also correctly adds serializer test to ensure we actually have this data.
27 lines
530 B
Ruby
27 lines
530 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ChatMessageUserSerializer < BasicUserWithStatusSerializer
|
|
attributes :moderator?, :admin?, :staff?, :moderator?, :new_user?, :primary_group_name
|
|
|
|
def moderator?
|
|
!!(object&.moderator?)
|
|
end
|
|
|
|
def admin?
|
|
!!(object&.admin?)
|
|
end
|
|
|
|
def staff?
|
|
!!(object&.staff?)
|
|
end
|
|
|
|
def new_user?
|
|
object.trust_level == TrustLevel[0]
|
|
end
|
|
|
|
def primary_group_name
|
|
return nil unless object && object.primary_group_id
|
|
object.primary_group.name if object.primary_group
|
|
end
|
|
end
|