mirror of
https://github.com/yingziwu/mastodon.git
synced 2026-02-04 03:25:14 +00:00
Add support for local quote stamps (#35626)
This commit is contained in:
parent
483da67204
commit
591df1f205
18 changed files with 241 additions and 16 deletions
|
|
@ -888,7 +888,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
|
||||
context 'with an unverifiable quote of a known post' do
|
||||
let(:quoted_status) { Fabricate(:status) }
|
||||
let(:quoted_status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com')) }
|
||||
|
||||
let(:object_json) do
|
||||
build_object(
|
||||
|
|
|
|||
49
spec/requests/activitypub/quote_authorizations_spec.rb
Normal file
49
spec/requests/activitypub/quote_authorizations_spec.rb
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'ActivityPub QuoteAuthorization endpoint' do
|
||||
let(:account) { Fabricate(:account, domain: nil) }
|
||||
let(:status) { Fabricate :status, account: account }
|
||||
let(:quote) { Fabricate(:quote, quoted_status: status, state: :accepted) }
|
||||
|
||||
before { Fabricate :favourite, status: status }
|
||||
|
||||
describe 'GET /accounts/:account_username/quote_authorizations/:quote_id' do
|
||||
context 'with an accepted quote' do
|
||||
it 'returns http success and activity json' do
|
||||
get account_quote_authorization_url(quote.quoted_account, quote)
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.media_type)
|
||||
.to eq 'application/activity+json'
|
||||
|
||||
expect(response.parsed_body)
|
||||
.to include(type: 'QuoteAuthorization')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an incorrect quote authorization URL' do
|
||||
it 'returns http not found' do
|
||||
get account_quote_authorization_url(quote.account, quote)
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(404)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a rejected quote' do
|
||||
before do
|
||||
quote.reject!
|
||||
end
|
||||
|
||||
it 'returns http not found' do
|
||||
get account_quote_authorization_url(quote.quoted_account, quote)
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -7,13 +7,13 @@ RSpec.describe ActivityPub::DeleteQuoteAuthorizationSerializer do
|
|||
|
||||
describe 'serializing an object' do
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:quote) { Fabricate(:quote, quoted_status: status, state: :accepted, approval_uri: "https://#{Rails.configuration.x.web_domain}/approvals/1234") }
|
||||
let(:quote) { Fabricate(:quote, quoted_status: status, state: :accepted) }
|
||||
|
||||
it 'returns expected attributes' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
actor: eq(ActivityPub::TagManager.instance.uri_for(status.account)),
|
||||
object: quote.approval_uri,
|
||||
object: ActivityPub::TagManager.instance.approval_uri_for(quote, check_approval: false),
|
||||
type: 'Delete'
|
||||
)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -44,8 +44,7 @@ RSpec.describe ActivityPub::NoteSerializer do
|
|||
|
||||
context 'with a quote' do
|
||||
let(:quoted_status) { Fabricate(:status) }
|
||||
let(:approval_uri) { 'https://example.com/foo/bar' }
|
||||
let!(:quote) { Fabricate(:quote, status: parent, quoted_status: quoted_status, approval_uri: approval_uri) }
|
||||
let!(:quote) { Fabricate(:quote, status: parent, quoted_status: quoted_status, state: :accepted) }
|
||||
|
||||
it 'has the expected shape' do
|
||||
expect(subject).to include({
|
||||
|
|
@ -53,7 +52,7 @@ RSpec.describe ActivityPub::NoteSerializer do
|
|||
'quote' => ActivityPub::TagManager.instance.uri_for(quote.quoted_status),
|
||||
'quoteUri' => ActivityPub::TagManager.instance.uri_for(quote.quoted_status),
|
||||
'_misskey_quote' => ActivityPub::TagManager.instance.uri_for(quote.quoted_status),
|
||||
'quoteAuthorization' => approval_uri,
|
||||
'quoteAuthorization' => ActivityPub::TagManager.instance.approval_uri_for(quote),
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::QuoteAuthorizationSerializer do
|
||||
subject { serialized_record_json(quote, described_class, adapter: ActivityPub::Adapter) }
|
||||
|
||||
describe 'serializing an object' do
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:quote) { Fabricate(:quote, quoted_status: status, state: :accepted) }
|
||||
|
||||
it 'returns expected attributes' do
|
||||
expect(subject.deep_symbolize_keys)
|
||||
.to include(
|
||||
attributedTo: eq(ActivityPub::TagManager.instance.uri_for(status.account)),
|
||||
interactionTarget: ActivityPub::TagManager.instance.uri_for(status),
|
||||
interactingObject: ActivityPub::TagManager.instance.uri_for(quote.status),
|
||||
type: 'QuoteAuthorization'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -564,6 +564,80 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when an approved quote of a local post gets updated through an explicit update' do
|
||||
let(:quoted_account) { Fabricate(:account) }
|
||||
let(:quoted_status) { Fabricate(:status, account: quoted_account, quote_approval_policy: Status::QUOTE_APPROVAL_POLICY_FLAGS[:public] << 16) }
|
||||
let!(:quote) { Fabricate(:quote, status: status, quoted_status: quoted_status, state: :accepted) }
|
||||
let(:approval_uri) { ActivityPub::TagManager.instance.approval_uri_for(quote) }
|
||||
|
||||
let(:payload) do
|
||||
{
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
{
|
||||
'@id': 'https://w3id.org/fep/044f#quote',
|
||||
'@type': '@id',
|
||||
},
|
||||
{
|
||||
'@id': 'https://w3id.org/fep/044f#quoteAuthorization',
|
||||
'@type': '@id',
|
||||
},
|
||||
],
|
||||
id: 'foo',
|
||||
type: 'Note',
|
||||
summary: 'Show more',
|
||||
content: 'Hello universe',
|
||||
updated: '2021-09-08T22:39:25Z',
|
||||
quote: ActivityPub::TagManager.instance.uri_for(quoted_status),
|
||||
quoteAuthorization: approval_uri,
|
||||
}
|
||||
end
|
||||
|
||||
it 'updates the quote post without changing the quote status' do
|
||||
expect { subject.call(status, json, json) }
|
||||
.to not_change(quote, :approval_uri)
|
||||
.and not_change(quote, :state).from('accepted')
|
||||
.and change(status, :text).from('Hello world').to('Hello universe')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when an unapproved quote of a local post gets updated through an explicit update and claims approval' do
|
||||
let(:quoted_account) { Fabricate(:account) }
|
||||
let(:quoted_status) { Fabricate(:status, account: quoted_account, quote_approval_policy: 0) }
|
||||
let!(:quote) { Fabricate(:quote, status: status, quoted_status: quoted_status, state: :rejected) }
|
||||
let(:approval_uri) { ActivityPub::TagManager.instance.approval_uri_for(quote) }
|
||||
|
||||
let(:payload) do
|
||||
{
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
{
|
||||
'@id': 'https://w3id.org/fep/044f#quote',
|
||||
'@type': '@id',
|
||||
},
|
||||
{
|
||||
'@id': 'https://w3id.org/fep/044f#quoteAuthorization',
|
||||
'@type': '@id',
|
||||
},
|
||||
],
|
||||
id: 'foo',
|
||||
type: 'Note',
|
||||
summary: 'Show more',
|
||||
content: 'Hello universe',
|
||||
updated: '2021-09-08T22:39:25Z',
|
||||
quote: ActivityPub::TagManager.instance.uri_for(quoted_status),
|
||||
quoteAuthorization: approval_uri,
|
||||
}
|
||||
end
|
||||
|
||||
it 'updates the quote post without changing the quote status' do
|
||||
expect { subject.call(status, json, json) }
|
||||
.to not_change(quote, :approval_uri)
|
||||
.and not_change(quote, :state).from('rejected')
|
||||
.and change(status, :text).from('Hello world').to('Hello universe')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the status has an existing verified quote and removes an approval link through an explicit update' do
|
||||
let(:quoted_account) { Fabricate(:account, domain: 'quoted.example.com') }
|
||||
let(:quoted_status) { Fabricate(:status, account: quoted_account) }
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ RSpec.describe RevokeQuoteService do
|
|||
|
||||
let(:status) { Fabricate(:status, account: alice) }
|
||||
|
||||
let(:quote) { Fabricate(:quote, quoted_status: status, state: :accepted, approval_uri: "https://#{Rails.configuration.x.web_domain}/approvals/1234") }
|
||||
let(:quote) { Fabricate(:quote, quoted_status: status, state: :accepted) }
|
||||
|
||||
before do
|
||||
hank.follow!(alice)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue