histories_controller.rb 686 B

1234567891011121314151617181920212223242526
  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. cache_if_unauthenticated!
  8. render json: status_edits, each_serializer: REST::StatusEditSerializer
  9. end
  10. private
  11. def status_edits
  12. @status.edits.includes(:account, status: [:account]).to_a.presence || [@status.build_snapshot(at_time: @status.edited_at || @status.created_at)]
  13. end
  14. def set_status
  15. @status = Status.find(params[:status_id])
  16. authorize @status, :show?
  17. rescue Mastodon::NotPermittedError
  18. not_found
  19. end
  20. end