2020-04-09 14:32:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# A basic user serializer, with custom fields
|
|
|
|
class UserWithCustomFieldsSerializer < BasicUserSerializer
|
2024-02-26 08:40:48 -05:00
|
|
|
include UserStatusMixin
|
|
|
|
attribute :custom_fields
|
2020-04-09 14:32:39 -04:00
|
|
|
|
|
|
|
def custom_fields
|
|
|
|
fields = custom_field_keys
|
|
|
|
|
|
|
|
if fields.present?
|
|
|
|
if object.custom_fields_preloaded?
|
|
|
|
{}.tap { |h| fields.each { |f| h[f] = object.custom_fields[f] } }
|
|
|
|
else
|
|
|
|
User.custom_fields_for_ids([object.id], fields)[object.id] || {}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def custom_field_keys
|
|
|
|
# Can be extended by other serializers
|
2020-07-26 20:23:54 -04:00
|
|
|
User.allowed_user_custom_fields(scope)
|
2020-04-09 14:32:39 -04:00
|
|
|
end
|
|
|
|
end
|