mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FEATURE: add after-reviewable-post-user plugin outlet (#9397)
FEATURE: add after-reviewable-post-user plugin outlet Add a plugin outlet after reviewable post user Add a basic user serializer that includes custom fields. Allows review queue serializer to include custom fields for its users
This commit is contained in:
27
app/serializers/user_with_custom_fields_serializer.rb
Normal file
27
app/serializers/user_with_custom_fields_serializer.rb
Normal file
@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# A basic user serializer, with custom fields
|
||||
class UserWithCustomFieldsSerializer < BasicUserSerializer
|
||||
attributes :custom_fields
|
||||
|
||||
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
|
||||
User.whitelisted_user_custom_fields(scope)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user