2
0

Change API behavior of reblogs wrt. quotes for consistency (#36559)

This commit is contained in:
Claire
2025-10-28 09:05:23 +01:00
committed by GitHub
parent 3bf99b8a4a
commit 4b42fe6aba
4 changed files with 28 additions and 4 deletions

View File

@@ -157,7 +157,7 @@ class Api::V1::StatusesController < Api::BaseController
end
def set_quoted_status
@quoted_status = Status.find(status_params[:quoted_status_id]) if status_params[:quoted_status_id].present?
@quoted_status = Status.find(status_params[:quoted_status_id])&.proper if status_params[:quoted_status_id].present?
authorize(@quoted_status, :quote?) if @quoted_status.present?
rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
# TODO: distinguish between non-existing and non-quotable posts

View File

@@ -61,6 +61,7 @@ class StatusCacheHydrator
payload[:filtered] = payload[:reblog][:filtered]
payload[:favourited] = payload[:reblog][:favourited]
payload[:reblogged] = payload[:reblog][:reblogged]
payload[:quote_approval] = payload[:reblog][:quote_approval]
end
end

View File

@@ -168,9 +168,9 @@ class REST::StatusSerializer < ActiveModel::Serializer
def quote_approval
{
automatic: object.quote_policy_as_keys(:automatic),
manual: object.quote_policy_as_keys(:manual),
current_user: object.quote_policy_for_account(current_user&.account),
automatic: object.proper.quote_policy_as_keys(:automatic),
manual: object.proper.quote_policy_as_keys(:manual),
current_user: object.proper.quote_policy_for_account(current_user&.account),
}
end

View File

@@ -248,6 +248,29 @@ RSpec.describe '/api/v1/statuses' do
end
end
context 'with a quote of a reblog' do
let(:quoted_status) { Fabricate(:status, quote_approval_policy: Status::QUOTE_APPROVAL_POLICY_FLAGS[:public] << 16) }
let(:reblog) { Fabricate(:status, reblog: quoted_status) }
let(:params) do
{
status: 'Hello world, this is a self-quote',
quoted_status_id: reblog.id,
}
end
it 'returns a quote post, as well as rate limit headers', :aggregate_failures do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(response.parsed_body[:quote]).to be_present
expect(response.parsed_body[:quote][:quoted_status][:id]).to eq quoted_status.id.to_s
expect(response.headers['X-RateLimit-Limit']).to eq RateLimiter::FAMILIES[:statuses][:limit].to_s
expect(response.headers['X-RateLimit-Remaining']).to eq (RateLimiter::FAMILIES[:statuses][:limit] - 1).to_s
end
end
context 'with a self-quote post and a CW but no text' do
let(:quoted_status) { Fabricate(:status, account: user.account) }
let(:params) do