mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-10 15:25:33 +08:00
Move the AdminSearchController#index endpoint into a proper service class since it does a few different things now.
38 lines
1.2 KiB
Ruby
38 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Admin::SearchController < Admin::AdminController
|
|
RESULT_TYPES = %w[page setting theme component report].freeze
|
|
|
|
def index
|
|
respond_to do |format|
|
|
format.json do
|
|
Admin::Search::List.call(service_params) do |result|
|
|
on_success do |settings:, themes_and_components:, reports:, upcoming_changes:|
|
|
themes_and_components_json =
|
|
ActiveModel::ArraySerializer.new(
|
|
themes_and_components,
|
|
each_serializer: BasicThemeSerializer,
|
|
scope: guardian,
|
|
).as_json
|
|
|
|
render_json_dump(
|
|
settings:,
|
|
themes_and_components: themes_and_components_json,
|
|
reports:,
|
|
upcoming_changes:,
|
|
)
|
|
end
|
|
on_failed_contract do |contract|
|
|
render(
|
|
json: failed_json.merge(errors: contract.errors.full_messages),
|
|
status: :bad_request,
|
|
)
|
|
end
|
|
on_failed_policy(:current_user_is_admin) { raise Discourse::InvalidAccess }
|
|
end
|
|
end
|
|
|
|
format.html { render body: nil }
|
|
end
|
|
end
|
|
end
|