logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

reports_controller.rb (1011B)


  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. render json: @reports, each_serializer: REST::ReportSerializer
  10. end
  11. def create
  12. @report = ReportService.new.call(
  13. current_account,
  14. reported_account,
  15. status_ids: reported_status_ids,
  16. comment: report_params[:comment],
  17. forward: report_params[:forward]
  18. )
  19. render json: @report, serializer: REST::ReportSerializer
  20. end
  21. private
  22. def reported_status_ids
  23. Status.find(status_ids).pluck(:id)
  24. end
  25. def status_ids
  26. Array(report_params[:status_ids])
  27. end
  28. def reported_account
  29. Account.find(report_params[:account_id])
  30. end
  31. def report_params
  32. params.permit(:account_id, :comment, :forward, status_ids: [])
  33. end
  34. end