docbrown/app/controllers/concerns/api/users_controller.rb
Anna Buianova df0b134ec4
Added followers count to /api/users/me endpoint (#20378)
* Added followers_count to /api/users/me

* Updated the api user docs

* Rubocop fixes fro swagger_helper

* Added me jbuilder view for api/v0
2023-11-22 20:22:06 +00:00

39 lines
1.2 KiB
Ruby

module Api
module UsersController
extend ActiveSupport::Concern
SHOW_ATTRIBUTES_FOR_SERIALIZATION = %i[
id username name summary twitter_username github_username website_url
location created_at profile_image registered
].freeze
def show
attributes_for_select = SHOW_ATTRIBUTES_FOR_SERIALIZATION + %i[display_email_on_profile email]
relation = User.joins(:profile).joins(:setting).select(attributes_for_select)
@user = if params[:id] == "by_username"
relation.find_by!(username: params[:url])
else
relation.find(params[:id])
end
not_found unless @user.registered
end
def me; end
def unpublish
authorize(@user, :unpublish_all_articles?)
target_user = User.find(params[:id].to_i)
Moderator::UnpublishAllArticlesWorker.perform_async(target_user.id, @user.id)
note_content = params[:note].presence || "#{@user.username} requested unpublish all articles via API"
Note.create(noteable: target_user, reason: "unpublish_all_articles",
content: note_content, author: @user)
render status: :no_content
end
end
end