polls_controller.rb 657 B

1234567891011121314151617181920212223242526
  1. # frozen_string_literal: true
  2. class Api::V1::PollsController < Api::BaseController
  3. include Authorization
  4. before_action -> { authorize_if_got_token! :read, :'read:statuses' }, only: :show
  5. before_action :set_poll
  6. before_action :refresh_poll
  7. def show
  8. render json: @poll, serializer: REST::PollSerializer, include_results: true
  9. end
  10. private
  11. def set_poll
  12. @poll = Poll.attached.find(params[:id])
  13. authorize @poll.status, :show?
  14. rescue Mastodon::NotPermittedError
  15. not_found
  16. end
  17. def refresh_poll
  18. ActivityPub::FetchRemotePollService.new.call(@poll, current_account) if user_signed_in? && @poll.possibly_stale?
  19. end
  20. end