* Refactor API user suspend, make room for more roles * Handle adding limited * Handle remove limited * And swagger docs * Update & refactor roles spec * Remove old route * Remove old specs
40 lines
1.1 KiB
Ruby
40 lines
1.1 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
|
|
relation = User.joins(:profile).select(SHOW_ATTRIBUTES_FOR_SERIALIZATION)
|
|
|
|
@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
|
|
render :show
|
|
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
|