histories_controller.rb 656 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class Api::V1::Statuses::HistoriesController < Api::BaseController
  3. include Authorization
  4. before_action -> { authorize_if_got_token! :read, :'read:statuses' }
  5. before_action :set_status
  6. def show
  7. render json: status_edits, each_serializer: REST::StatusEditSerializer
  8. end
  9. private
  10. def status_edits
  11. @status.edits.includes(:account, status: [:account]).to_a.presence || [@status.build_snapshot(at_time: @status.edited_at || @status.created_at)]
  12. end
  13. def set_status
  14. @status = Status.find(params[:status_id])
  15. authorize @status, :show?
  16. rescue Mastodon::NotPermittedError
  17. not_found
  18. end
  19. end