mirror of
https://github.com/funamitech/mastodon
synced 2024-12-17 08:09:25 +09:00
502cf75b16
* Fix insufficient permission checking for public timeline endpoints Note that this changes unauthenticated access failure code from 401 to 422 * Add more tests for public timelines * Require user token in `/api/v1/statuses/:id/translate` and `/api/v1/scheduled_statuses`
29 lines
918 B
Ruby
29 lines
918 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Api::V1::Statuses::TranslationsController < Api::V1::Statuses::BaseController
|
|
before_action -> { doorkeeper_authorize! :read, :'read:statuses' }
|
|
before_action :require_user!
|
|
before_action :set_translation
|
|
|
|
rescue_from TranslationService::NotConfiguredError, with: :not_found
|
|
rescue_from TranslationService::UnexpectedResponseError, with: :service_unavailable
|
|
|
|
rescue_from TranslationService::QuotaExceededError do
|
|
render json: { error: I18n.t('translation.errors.quota_exceeded') }, status: 503
|
|
end
|
|
|
|
rescue_from TranslationService::TooManyRequestsError do
|
|
render json: { error: I18n.t('translation.errors.too_many_requests') }, status: 503
|
|
end
|
|
|
|
def create
|
|
render json: @translation, serializer: REST::TranslationSerializer
|
|
end
|
|
|
|
private
|
|
|
|
def set_translation
|
|
@translation = TranslateStatusService.new.call(@status, content_locale)
|
|
end
|
|
end
|