reports_controller.rb 891 Bytes
Newer Older
1 2
# frozen_string_literal: true

3
class Api::V1::ReportsController < Api::BaseController
4
  before_action -> { doorkeeper_authorize! :write, :'write:reports' }, only: [:create]
5 6 7 8 9
  before_action :require_user!

  respond_to :json

  def create
Eugen Rochko's avatar
Eugen Rochko committed
10 11
    raise Mastodon::NotPermittedError

Eugen Rochko's avatar
Eugen Rochko committed
12 13 14
    @report = ReportService.new.call(
      current_account,
      reported_account,
15
      status_ids: reported_status_ids,
Eugen Rochko's avatar
Eugen Rochko committed
16 17
      comment: report_params[:comment],
      forward: report_params[:forward]
18
    )
19

20
    render json: @report, serializer: REST::ReportSerializer
21
  end
22 23 24

  private

25
  def reported_status_ids
26
    reported_account.statuses.find(status_ids).pluck(:id)
27 28 29 30 31 32 33 34 35 36
  end

  def status_ids
    Array(report_params[:status_ids])
  end

  def reported_account
    Account.find(report_params[:account_id])
  end

37
  def report_params
Eugen Rochko's avatar
Eugen Rochko committed
38
    params.permit(:account_id, :comment, :forward, status_ids: [])
39
  end
40
end