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:
parent
8b46f14744
commit
5ccbc5f3ee
|
@ -9,4 +9,7 @@
|
|||
{{i18n "review.deleted_user"}}
|
||||
{{/if}}
|
||||
</span>
|
||||
{{plugin-outlet name="after-reviewable-post-user"
|
||||
tagName=""
|
||||
args=(hash user=user)}}
|
||||
</div>
|
||||
|
|
|
@ -19,13 +19,13 @@ class ReviewableSerializer < ApplicationSerializer
|
|||
:version,
|
||||
)
|
||||
|
||||
has_one :created_by, serializer: BasicUserSerializer, root: 'users'
|
||||
has_one :target_created_by, serializer: BasicUserSerializer, root: 'users'
|
||||
has_one :created_by, serializer: UserWithCustomFieldsSerializer, root: 'users'
|
||||
has_one :target_created_by, serializer: UserWithCustomFieldsSerializer, root: 'users'
|
||||
has_one :topic, serializer: ListableTopicSerializer
|
||||
has_many :editable_fields, serializer: ReviewableEditableFieldSerializer, embed: :objects
|
||||
has_many :reviewable_scores, serializer: ReviewableScoreSerializer
|
||||
has_many :bundled_actions, serializer: ReviewableBundledActionSerializer
|
||||
has_one :claimed_by, serializer: BasicUserSerializer, root: 'users'
|
||||
has_one :claimed_by, serializer: UserWithCustomFieldsSerializer, root: 'users'
|
||||
|
||||
# Used to keep track of our payload attributes
|
||||
class_attribute :_payload_for_serialization
|
||||
|
|
|
@ -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
|
|
@ -192,6 +192,32 @@ describe ReviewablesController do
|
|||
expect(json_review['id']).to eq(reviewable.id)
|
||||
end
|
||||
end
|
||||
|
||||
context "with user custom field" do
|
||||
before do
|
||||
plugin = Plugin::Instance.new
|
||||
plugin.whitelist_public_user_custom_field :public_field
|
||||
end
|
||||
|
||||
after do
|
||||
User.plugin_public_user_custom_fields.clear
|
||||
end
|
||||
|
||||
it "returns user data with custom fields" do
|
||||
user = Fabricate(:user)
|
||||
user.custom_fields["public_field"] = "public"
|
||||
user.custom_fields["private_field"] = "private"
|
||||
user.save!
|
||||
|
||||
reviewable = Fabricate(:reviewable, target_created_by: user)
|
||||
|
||||
get "/review.json"
|
||||
json = response.parsed_body
|
||||
expect(json['users']).to be_present
|
||||
expect(json['users'].any? { |u| u['id'] == reviewable.target_created_by_id && u['custom_fields']['public_field'] == 'public' }).to eq(true)
|
||||
expect(json['users'].any? { |u| u['id'] == reviewable.target_created_by_id && u['custom_fields']['private_field'] == 'private' }).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#show" do
|
||||
|
|
Loading…
Reference in New Issue