Files
mastodon/app/services/activitypub/verify_featured_item_service.rb
jcoffey-dev 4dfbb64241
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Import Mastodon v4.7.4
Snapshot of upstream tag v4.7.4 (commit d04059fc80be5cbba6b4dd5a8b94d63ffff09f2c) from
https://github.com/mastodon/mastodon, unmodified.
2026-10-29 08:11:58 -07:00

42 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class ActivityPub::VerifyFeaturedItemService
include JsonLdHelper
def call(collection_item, approval_uri, request_id: nil)
@collection_item = collection_item
@authorization = fetch_resource(approval_uri, raise_on_error: :temporary)
if @authorization.nil?
@collection_item.update!(state: :rejected)
return
end
@collection_uri = value_or_id(@authorization['interactingObject'])
@actor_uri = value_or_id(@authorization['interactionTarget'])
return if non_matching_uri_hosts?(approval_uri, @actor_uri)
return unless matching_type? && matching_collection_uri? && matching_actors?
account = Account.where(uri: @collection_item.object_uri).first
account ||= ActivityPub::FetchRemoteAccountService.new.call(@collection_item.object_uri, request_id:)
return if account.blank?
@collection_item.update!(account:, approval_uri:, state: :accepted)
end
private
def matching_type?
supported_context?(@authorization) && equals_or_includes?(@authorization['type'], 'FeatureAuthorization')
end
def matching_collection_uri?
@collection_item.collection.uri == @collection_uri
end
def matching_actors?
@collection_item.object_uri == @actor_uri
end
end