You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
657 B

  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