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.

40 lines
851 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. render :show
  17. end
  18. private
  19. def reported_status_ids
  20. Status.find(status_ids).pluck(:id)
  21. end
  22. def status_ids
  23. Array(report_params[:status_ids])
  24. end
  25. def reported_account
  26. Account.find(report_params[:account_id])
  27. end
  28. def report_params
  29. params.permit(:account_id, :comment, status_ids: [])
  30. end
  31. end