Add support for reversible suspensions through ActivityPub (#14989)
This commit is contained in:
parent
ee8cf246cf
commit
3134691948
47 changed files with 1049 additions and 204 deletions
|
@ -5,8 +5,6 @@ class ResolveAccountService < BaseService
|
|||
include DomainControlHelper
|
||||
include WebfingerHelper
|
||||
|
||||
class WebfingerRedirectError < StandardError; end
|
||||
|
||||
# Find or create an account record for a remote user. When creating,
|
||||
# look up the user's webfinger and fetch ActivityPub data
|
||||
# @param [String, Account] uri URI in the username@domain format or account record
|
||||
|
@ -40,13 +38,18 @@ class ResolveAccountService < BaseService
|
|||
|
||||
@account ||= Account.find_remote(@username, @domain)
|
||||
|
||||
return @account if @account&.local? || !webfinger_update_due?
|
||||
if gone_from_origin? && not_yet_deleted?
|
||||
queue_deletion!
|
||||
return
|
||||
end
|
||||
|
||||
return @account if @account&.local? || gone_from_origin? || !webfinger_update_due?
|
||||
|
||||
# Now it is certain, it is definitely a remote account, and it
|
||||
# either needs to be created, or updated from fresh data
|
||||
|
||||
process_account!
|
||||
rescue Webfinger::Error, WebfingerRedirectError, Oj::ParseError => e
|
||||
rescue Webfinger::Error, Oj::ParseError => e
|
||||
Rails.logger.debug "Webfinger query for #{@uri} failed: #{e}"
|
||||
nil
|
||||
end
|
||||
|
@ -86,10 +89,12 @@ class ResolveAccountService < BaseService
|
|||
elsif !redirected
|
||||
return process_webfinger!("#{confirmed_username}@#{confirmed_domain}", true)
|
||||
else
|
||||
raise WebfingerRedirectError, "The URI #{uri} tries to hijack #{@username}@#{@domain}"
|
||||
raise Webfinger::RedirectError, "The URI #{uri} tries to hijack #{@username}@#{@domain}"
|
||||
end
|
||||
|
||||
@domain = nil if TagManager.instance.local_domain?(@domain)
|
||||
rescue Webfinger::GoneError
|
||||
@gone = true
|
||||
end
|
||||
|
||||
def process_account!
|
||||
|
@ -131,6 +136,18 @@ class ResolveAccountService < BaseService
|
|||
@actor_json = supported_context?(json) && equals_or_includes_any?(json['type'], ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES) ? json : nil
|
||||
end
|
||||
|
||||
def gone_from_origin?
|
||||
@gone
|
||||
end
|
||||
|
||||
def not_yet_deleted?
|
||||
@account.present? && !@account.local?
|
||||
end
|
||||
|
||||
def queue_deletion!
|
||||
AccountDeletionWorker.perform_async(@account.id, reserve_username: false)
|
||||
end
|
||||
|
||||
def lock_options
|
||||
{ redis: Redis.current, key: "resolve:#{@username}@#{@domain}" }
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue