mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 06:13:26 +08:00
FEATURE: New route for loading multiple user cards simultaneously (#9078)
Introduces `/user-cards.json` Also allows the client-side user model to be passed an existing promise when loading, so that multiple models can share the same AJAX request
This commit is contained in:
@ -99,6 +99,30 @@ class UsersController < ApplicationController
|
||||
show(for_card: true)
|
||||
end
|
||||
|
||||
def cards
|
||||
return redirect_to path('/login') if SiteSetting.hide_user_profiles_from_public && !current_user
|
||||
|
||||
user_ids = params.require(:user_ids).split(",").map(&:to_i)
|
||||
raise Discourse::InvalidParameters.new(:user_ids) if user_ids.length > 50
|
||||
|
||||
users = User.where(id: user_ids).includes(:user_option,
|
||||
:user_stat,
|
||||
:default_featured_user_badges,
|
||||
:user_profile,
|
||||
:card_background_upload,
|
||||
:primary_group,
|
||||
:primary_email
|
||||
)
|
||||
|
||||
users = users.filter { |u| guardian.can_see_profile?(u) }
|
||||
|
||||
preload_fields = User.whitelisted_user_custom_fields(guardian) + UserField.all.pluck(:id).map { |fid| "#{User::USER_FIELD_PREFIX}#{fid}" }
|
||||
User.preload_custom_fields(users, preload_fields)
|
||||
User.preload_recent_time_read(users)
|
||||
|
||||
render json: users, each_serializer: UserCardSerializer
|
||||
end
|
||||
|
||||
def badges
|
||||
raise Discourse::NotFound unless SiteSetting.enable_badges?
|
||||
show
|
||||
|
Reference in New Issue
Block a user