mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-25 06:18:07 +01:00
fce8464077
Use Rails smart boolean cast to account for values such as "f", "0", "false", etc. Previously, if a param was present in the request, it would count as true.
40 lines
752 B
Ruby
40 lines
752 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Api::V1::SearchController < Api::BaseController
|
|
include Authorization
|
|
|
|
RESULTS_LIMIT = 5
|
|
|
|
before_action -> { doorkeeper_authorize! :read }
|
|
before_action :require_user!
|
|
|
|
respond_to :json
|
|
|
|
def index
|
|
@search = Search.new(search)
|
|
render json: @search, serializer: REST::SearchSerializer
|
|
end
|
|
|
|
private
|
|
|
|
def search
|
|
search_results.tap do |search|
|
|
search[:statuses].keep_if do |status|
|
|
begin
|
|
authorize status, :show?
|
|
rescue Mastodon::NotPermittedError
|
|
false
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
def search_results
|
|
SearchService.new.call(
|
|
params[:q],
|
|
RESULTS_LIMIT,
|
|
truthy_param?(:resolve),
|
|
current_account
|
|
)
|
|
end
|
|
end
|