FEATURE: Add custom fields to members on group index (#24232)
* FEATURE: Add custom fields to members on group index
This commit is contained in:
parent
4a21411de2
commit
1d68ff430b
|
@ -101,6 +101,11 @@
|
|||
></div>
|
||||
{{/if}}
|
||||
|
||||
<PluginOutlet
|
||||
@name="group-index-table-header-after-username"
|
||||
@outletArgs={{hash group=this.model}}
|
||||
/>
|
||||
|
||||
<TableHeaderToggle
|
||||
@class="directory-table__column-header--added"
|
||||
@order={{this.order}}
|
||||
|
@ -179,6 +184,12 @@
|
|||
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<PluginOutlet
|
||||
@name="group-index-table-row-after-username"
|
||||
@outletArgs={{hash member=m}}
|
||||
/>
|
||||
|
||||
<div class="directory-table__cell directory-table__cell--added">
|
||||
<span class="directory-table__label">
|
||||
<span>{{i18n "groups.member_added"}}</span>
|
||||
|
|
|
@ -312,8 +312,11 @@ class GroupsController < ApplicationController
|
|||
members = users.limit(limit).offset(offset)
|
||||
owners = users.where("group_users.owner")
|
||||
|
||||
group_members_serializer =
|
||||
params[:include_custom_fields] ? GroupUserWithCustomFieldsSerializer : GroupUserSerializer
|
||||
|
||||
render json: {
|
||||
members: serialize_data(members, GroupUserSerializer),
|
||||
members: serialize_data(members, group_members_serializer),
|
||||
owners: serialize_data(owners, GroupUserSerializer),
|
||||
meta: {
|
||||
total: total,
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class GroupUserWithCustomFieldsSerializer < UserWithCustomFieldsSerializer
|
||||
include UserPrimaryGroupMixin
|
||||
|
||||
attributes :name, :title, :last_posted_at, :last_seen_at, :added_at, :timezone, :status
|
||||
|
||||
def timezone
|
||||
user.user_option.timezone
|
||||
end
|
||||
|
||||
def include_added_at?
|
||||
object.respond_to? :added_at
|
||||
end
|
||||
|
||||
def include_status?
|
||||
SiteSetting.enable_user_status && user.has_status?
|
||||
end
|
||||
|
||||
def status
|
||||
UserStatusSerializer.new(user.user_status, root: false)
|
||||
end
|
||||
end
|
|
@ -644,6 +644,27 @@ RSpec.describe GroupsController do
|
|||
expect(response.parsed_body["members"].map { |u| u["id"] }).to eq([user.id, other_user.id])
|
||||
expect(response.parsed_body["owners"].map { |u| u["id"] }).to eq([other_user.id])
|
||||
end
|
||||
|
||||
context "when include_custom_fields is true" do
|
||||
fab!(:user_field) { Fabricate(:user_field) }
|
||||
let(:user_field_name) { "user_field_#{user_field.id}" }
|
||||
let!(:custom_user_field) do
|
||||
UserCustomField.create!(user_id: user.id, name: user_field_name, value: "A custom field")
|
||||
end
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
SiteSetting.public_user_custom_fields = user_field_name
|
||||
end
|
||||
|
||||
it "shows custom the fields" do
|
||||
get "/groups/#{group.name}/members.json", params: { include_custom_fields: true }
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
response_custom_fields = response.parsed_body["members"].first["custom_fields"]
|
||||
expect(response_custom_fields[user_field_name]).to eq("A custom field")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#posts_feed" do
|
||||
|
|
Loading…
Reference in New Issue