mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 09:21:11 +00:00

Some checks are pending
Bundler Audit / security (push) Waiting to run
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.2) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
73 lines
1.7 KiB
Ruby
73 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Api::V1::Statuses::QuotesController < Api::V1::Statuses::BaseController
|
|
before_action -> { doorkeeper_authorize! :read, :'read:statuses' }, only: :index
|
|
before_action -> { doorkeeper_authorize! :write, :'write:statuses' }, only: :revoke
|
|
|
|
before_action :check_owner!
|
|
before_action :set_quote, only: :revoke
|
|
after_action :insert_pagination_headers, only: :index
|
|
|
|
def index
|
|
cache_if_unauthenticated!
|
|
@statuses = load_statuses
|
|
render json: @statuses, each_serializer: REST::StatusSerializer
|
|
end
|
|
|
|
def revoke
|
|
authorize @quote, :revoke?
|
|
|
|
RevokeQuoteService.new.call(@quote)
|
|
|
|
render json: @quote.status, serializer: REST::StatusSerializer
|
|
end
|
|
|
|
private
|
|
|
|
def check_owner!
|
|
authorize @status, :list_quotes?
|
|
end
|
|
|
|
def set_quote
|
|
@quote = @status.quotes.find_by!(status_id: params[:id])
|
|
end
|
|
|
|
def load_statuses
|
|
scope = default_statuses
|
|
scope = scope.not_excluded_by_account(current_account) unless current_account.nil?
|
|
scope.merge(paginated_quotes).to_a
|
|
end
|
|
|
|
def default_statuses
|
|
Status.includes(:quote).references(:quote)
|
|
end
|
|
|
|
def paginated_quotes
|
|
@status.quotes.accepted.paginate_by_max_id(
|
|
limit_param(DEFAULT_STATUSES_LIMIT),
|
|
params[:max_id],
|
|
params[:since_id]
|
|
)
|
|
end
|
|
|
|
def next_path
|
|
api_v1_status_quotes_url pagination_params(max_id: pagination_max_id) if records_continue?
|
|
end
|
|
|
|
def prev_path
|
|
api_v1_status_quotes_url pagination_params(since_id: pagination_since_id) unless @statuses.empty?
|
|
end
|
|
|
|
def pagination_max_id
|
|
@statuses.last.quote.id
|
|
end
|
|
|
|
def pagination_since_id
|
|
@statuses.first.quote.id
|
|
end
|
|
|
|
def records_continue?
|
|
@statuses.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
|
end
|
|
end
|