discourse/plugins/chat/app/serializers/chat_message_user_serializer.rb
Joffrey JAFFEUX 8144730ebb
FIX: correctly add user info data to message serializer (#20348)
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.
2023-02-17 17:07:44 +01:00

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