Remove instance variables from helper usage (#24203)

This commit is contained in:
Matt Jankowski
2023-04-23 16:35:54 -04:00
committed by GitHub
parent e1b4eeb636
commit 0a5f0a8b20
19 changed files with 53 additions and 45 deletions

View File

@ -17,7 +17,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
private
def create_encrypted_message
return reject_payload! if invalid_origin?(object_uri) || @options[:delivered_to_account_id].blank?
return reject_payload! if non_matching_uri_hosts?(@account.uri, object_uri) || @options[:delivered_to_account_id].blank?
target_account = Account.find(@options[:delivered_to_account_id])
target_device = target_account.devices.find_by(device_id: @object.dig('to', 'deviceId'))
@ -45,7 +45,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
end
def create_status
return reject_payload! if unsupported_object_type? || invalid_origin?(object_uri) || tombstone_exists? || !related_to_local_activity?
return reject_payload! if unsupported_object_type? || non_matching_uri_hosts?(@account.uri, object_uri) || tombstone_exists? || !related_to_local_activity?
with_lock("create:#{object_uri}") do
return if delete_arrived_first?(object_uri) || poll_vote?

View File

@ -21,7 +21,7 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
return if object_uri.nil?
with_lock("delete_status_in_progress:#{object_uri}", raise_on_failure: false) do
unless invalid_origin?(object_uri)
unless non_matching_uri_hosts?(@account.uri, object_uri)
# This lock ensures a concurrent `ActivityPub::Activity::Create` either
# does not create a status at all, or has finished saving it to the
# database before we try to load it.

View File

@ -33,6 +33,6 @@ class ActivityPub::Activity::Flag < ActivityPub::Activity
end
def report_uri
@json['id'] unless @json['id'].nil? || invalid_origin?(@json['id'])
@json['id'] unless @json['id'].nil? || non_matching_uri_hosts?(@account.uri, @json['id'])
end
end

View File

@ -22,7 +22,7 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
end
def update_status
return reject_payload! if invalid_origin?(object_uri)
return reject_payload! if non_matching_uri_hosts?(@account.uri, object_uri)
@status = Status.find_by(uri: object_uri, account_id: @account.id)

View File

@ -40,7 +40,7 @@ class ActivityPub::Dereferencer
end
def perform_request(uri, headers: nil)
return if invalid_origin?(uri)
return if non_matching_uri_hosts?(@permitted_origin, uri)
req = Request.new(:get, uri)
@ -57,13 +57,4 @@ class ActivityPub::Dereferencer
end
end
end
def invalid_origin?(uri)
return true if unsupported_uri_scheme?(uri)
needle = Addressable::URI.parse(uri).host
haystack = Addressable::URI.parse(@permitted_origin).host
!haystack.casecmp(needle).zero?
end
end