1
0

polls_controller.rb 687 B

123456789101112131415161718192021222324252627
  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. cache_if_unauthenticated!
  9. render json: @poll, serializer: REST::PollSerializer, include_results: true
  10. end
  11. private
  12. def set_poll
  13. @poll = Poll.attached.find(params[:id])
  14. authorize @poll.status, :show?
  15. rescue Mastodon::NotPermittedError
  16. not_found
  17. end
  18. def refresh_poll
  19. ActivityPub::FetchRemotePollService.new.call(@poll, current_account) if user_signed_in? && @poll.possibly_stale?
  20. end
  21. end