Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/lib/activitypub/tag_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def uri_for(target, group: false)

def approval_uri_for(quote, check_approval: true)
unless quote.quoted_account&.local?
return 'http://kmy.blue/ns#LegacyQuote' if Setting.auto_accept_legacy_quotes && !quote.approval_uri && quote.quoted_account&.domain && InstanceInfo.legacy_quote_software?(quote.quoted_account.domain)
return 'http://kmy.blue/ns#LegacyQuote' if Setting.auto_accept_legacy_quotes && quote.approval_uri.nil? && InstanceInfo.legacy_quote_software?(quote.quoted_account.domain)

return quote.approval_uri
end
Expand Down
6 changes: 0 additions & 6 deletions app/models/quote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ class Quote < ApplicationRecord
after_destroy_commit :decrement_counter_caches!
after_update_commit :update_counter_caches!

def legacy_accepted?
return false if !accepted? || !quoted_account || quoted_account.local?

InstanceInfo.legacy_quote_software?(quoted_account.domain)
end

def accept!
update!(state: :accepted)
end
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/activitypub/note_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def quote?
end

def quote_authorization?
object.quote.present? && (Setting.auto_accept_legacy_quotes ? object.quote.legacy_accepted? : ActivityPub::TagManager.instance.approval_uri_for(object.quote).present?)
object.quote.present? && ActivityPub::TagManager.instance.approval_uri_for(object.quote).present?
end

def quote
Expand Down
76 changes: 76 additions & 0 deletions spec/serializers/activitypub/note_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,82 @@ def reply_items
end
end

context 'with a pending quote' do
let(:quoted_account) { Fabricate(:account) }
let(:quoted_status) { Fabricate(:status, account: quoted_account) }
let!(:quote) { Fabricate(:quote, status: parent, quoted_status: quoted_status, state: :accepted) }

shared_examples 'quote is authorized' do
it 'has the expected shape' do
expect(subject).to include({
'type' => 'Note',
'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' => ActivityPub::TagManager.instance.approval_uri_for(quote),
})
end
end

shared_examples 'quote is not authorized' do
it 'has the expected shape' do
expect(subject).to include({
'type' => 'Note',
'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),
})
expect(subject).to_not have_key('quoteAuthorization')
end
end

it_behaves_like 'quote is authorized'

context 'when quote is pending' do
let(:quote) { Fabricate(:quote, status: parent, quoted_status: quoted_status, state: :pending) }

it_behaves_like 'quote is not authorized'
end

context 'when quote is from misskey and approval_uri is nil' do
let(:quoted_account) { Fabricate(:account, uri: 'https://example.com/actor', domain: 'example.com') }

before { Fabricate(:instance_info, domain: 'example.com', software: 'misskey') }

it_behaves_like 'quote is not authorized'
end

context 'when quote is from misskey and approval_uri is nil, auto_accept_legacy_quotes is enabled' do
let(:quoted_account) { Fabricate(:account, uri: 'https://example.com/actor', domain: 'example.com') }

before do
Fabricate(:instance_info, domain: 'example.com', software: 'misskey')
Setting.auto_accept_legacy_quotes = true
end

it_behaves_like 'quote is authorized'
end

context 'when quote is from mastodon and approval_uri is nil' do
let(:quoted_account) { Fabricate(:account, uri: 'https://example.com/actor', domain: 'example.com') }

before { Fabricate(:instance_info, domain: 'example.com', software: 'mastodon') }

it_behaves_like 'quote is not authorized'
end

context 'when quote is from mastodon and approval_uri is nil, auto_accept_legacy_quotes is enabled' do
let(:quoted_account) { Fabricate(:account, uri: 'https://example.com/actor', domain: 'example.com') }

before do
Fabricate(:instance_info, domain: 'example.com', software: 'mastodon')
Setting.auto_accept_legacy_quotes = true
end

it_behaves_like 'quote is not authorized'
end
end

context 'with a quote policy', feature: :outgoing_quotes do
let(:parent) { Fabricate(:status, quote_approval_policy: Status::QUOTE_APPROVAL_POLICY_FLAGS[:followers] << 16) }

Expand Down