闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
958 B

  1. # frozen_string_literal: true
  2. class Api::V1::ReportsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read }, except: [:create]
  4. before_action -> { doorkeeper_authorize! :write }, only: [:create]
  5. before_action :require_user!
  6. respond_to :json
  7. def index
  8. @reports = current_account.reports
  9. end
  10. def create
  11. @report = current_account.reports.create!(
  12. target_account: reported_account,
  13. status_ids: reported_status_ids,
  14. comment: report_params[:comment]
  15. )
  16. User.admins.includes(:account).each { |u| AdminMailer.new_report(u.account, @report).deliver_later }
  17. render :show
  18. end
  19. private
  20. def reported_status_ids
  21. Status.find(status_ids).pluck(:id)
  22. end
  23. def status_ids
  24. Array(report_params[:status_ids])
  25. end
  26. def reported_account
  27. Account.find(report_params[:account_id])
  28. end
  29. def report_params
  30. params.permit(:account_id, :comment, status_ids: [])
  31. end
  32. end