Support all ActivityPub actor types (#6997)

Fix #6973
rebase/4.0.0rc2
Eugen Rochko 2018-04-02 02:10:53 +02:00 committed by GitHub
parent 33513753b9
commit f890d2a766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 6 deletions

View File

@ -3,6 +3,8 @@
class ActivityPub::FetchRemoteAccountService < BaseService class ActivityPub::FetchRemoteAccountService < BaseService
include JsonLdHelper include JsonLdHelper
SUPPORTED_TYPES = %w(Application Group Organization Person Service).freeze
# Should be called when uri has already been checked for locality # Should be called when uri has already been checked for locality
# Does a WebFinger roundtrip on each call # Does a WebFinger roundtrip on each call
def call(uri, id: true, prefetched_body: nil) def call(uri, id: true, prefetched_body: nil)
@ -54,6 +56,6 @@ class ActivityPub::FetchRemoteAccountService < BaseService
end end
def expected_type? def expected_type?
@json['type'] == 'Person' SUPPORTED_TYPES.include?(@json['type'])
end end
end end

View File

@ -43,7 +43,7 @@ class ActivityPub::FetchRemoteKeyService < BaseService
end end
def person? def person?
@json['type'] == 'Person' ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(@json['type'])
end end
def public_key? def public_key?
@ -55,6 +55,6 @@ class ActivityPub::FetchRemoteKeyService < BaseService
end end
def confirmed_owner? def confirmed_owner?
@owner['type'] == 'Person' && value_or_id(@owner['publicKey']) == @json['id'] ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(@owner['type']) && value_or_id(@owner['publicKey']) == @json['id']
end end
end end

View File

@ -42,7 +42,7 @@ class FetchAtomService < BaseService
elsif ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(response.mime_type) elsif ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(response.mime_type)
body = response.body_with_limit body = response.body_with_limit
json = body_to_json(body) json = body_to_json(body)
if supported_context?(json) && json['type'] == 'Person' && json['inbox'].present? if supported_context?(json) && ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(json['type']) && json['inbox'].present?
[json['id'], { prefetched_body: body, id: true }, :activitypub] [json['id'], { prefetched_body: body, id: true }, :activitypub]
elsif supported_context?(json) && expected_type?(json) elsif supported_context?(json) && expected_type?(json)
[json['id'], { prefetched_body: body, id: true }, :activitypub] [json['id'], { prefetched_body: body, id: true }, :activitypub]

View File

@ -189,7 +189,7 @@ class ResolveAccountService < BaseService
return @actor_json if defined?(@actor_json) return @actor_json if defined?(@actor_json)
json = fetch_resource(actor_url, false) json = fetch_resource(actor_url, false)
@actor_json = supported_context?(json) && json['type'] == 'Person' ? json : nil @actor_json = supported_context?(json) && ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES.include?(json['type']) ? json : nil
end end
def atom def atom

View File

@ -17,7 +17,7 @@ class ResolveURLService < BaseService
def process_url def process_url
case type case type
when 'Person' when 'Application', 'Group', 'Organization', 'Person', 'Service'
FetchRemoteAccountService.new.call(atom_url, body, protocol) FetchRemoteAccountService.new.call(atom_url, body, protocol)
when 'Note', 'Article', 'Image', 'Video' when 'Note', 'Article', 'Image', 'Video'
FetchRemoteStatusService.new.call(atom_url, body, protocol) FetchRemoteStatusService.new.call(atom_url, body, protocol)