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:
David Taylor
2020-03-06 12:23:22 +00:00
committed by GitHub
parent 29ccdf5d35
commit ff62911a89
4 changed files with 59 additions and 1 deletions

View File

@ -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