Merge remote-tracking branch 'parent/main' into upstream-20241009

This commit is contained in:
KMY 2024-10-09 12:32:11 +09:00
commit d021659cb7
130 changed files with 1120 additions and 917 deletions

View file

@ -95,6 +95,7 @@ class Account < ApplicationRecord
include Account::StatusesSearch
include Account::OtherSettings
include Account::MasterSettings
include Account::Suspensions
include Account::AttributionDomains
include DomainMaterializable
include DomainNormalizable
@ -134,10 +135,7 @@ class Account < ApplicationRecord
scope :local, -> { where(domain: nil) }
scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
scope :silenced, -> { where.not(silenced_at: nil) }
scope :suspended, -> { where.not(suspended_at: nil) }
scope :remote_pending, -> { where(remote_pending: true).where.not(suspended_at: nil) }
scope :sensitized, -> { where.not(sensitized_at: nil) }
scope :without_suspended, -> { where(suspended_at: nil) }
scope :without_silenced, -> { where(silenced_at: nil) }
scope :without_instance_actor, -> { where.not(id: INSTANCE_ACTOR_ID) }
scope :recent, -> { reorder(id: :desc) }
@ -283,58 +281,6 @@ class Account < ApplicationRecord
update!(silenced_at: nil)
end
def suspended?
suspended_at.present? && !instance_actor?
end
def suspended_locally?
suspended? && suspension_origin_local?
end
def suspended_permanently?
suspended? && deletion_request.nil?
end
def suspended_temporarily?
suspended? && deletion_request.present?
end
alias unavailable? suspended?
alias permanently_unavailable? suspended_permanently?
def suspend!(date: Time.now.utc, origin: :local, block_email: true)
transaction do
create_deletion_request!
update!(suspended_at: date, suspension_origin: origin)
create_canonical_email_block! if block_email
end
end
def unsuspend!
transaction do
deletion_request&.destroy!
update!(suspended_at: nil, suspension_origin: nil)
destroy_canonical_email_block!
end
end
def approve_remote!
return unless remote_pending
update!(remote_pending: false)
unsuspend!
ActivateRemoteAccountWorker.perform_async(id)
end
def reject_remote!
return unless remote_pending
update!(remote_pending: false, suspension_origin: :local)
pending_follow_requests.destroy_all
pending_statuses.destroy_all
suspend!
end
def sensitized?
sensitized_at.present?
end

View file

@ -35,7 +35,7 @@ class AccountAlias < ApplicationRecord
def set_uri
target_account = ResolveAccountService.new.call(acct)
self.uri = ActivityPub::TagManager.instance.uri_for(target_account) unless target_account.nil?
rescue Webfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS, Mastodon::Error
# Validation will take care of it
end

View file

@ -61,7 +61,7 @@ class AccountMigration < ApplicationRecord
def set_target_account
self.target_account = ResolveAccountService.new.call(acct, skip_cache: true)
rescue Webfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error, Addressable::URI::InvalidURIError
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS, Mastodon::Error, Addressable::URI::InvalidURIError
# Validation will take care of it
end

View file

@ -0,0 +1,62 @@
# frozen_string_literal: true
module Account::Suspensions
extend ActiveSupport::Concern
included do
scope :suspended, -> { where.not(suspended_at: nil) }
scope :without_suspended, -> { where(suspended_at: nil) }
scope :remote_pending, -> { where(remote_pending: true).where.not(suspended_at: nil) }
end
def suspended?
suspended_at.present? && !instance_actor?
end
alias unavailable? suspended?
def suspended_locally?
suspended? && suspension_origin_local?
end
def suspended_permanently?
suspended? && deletion_request.nil?
end
alias permanently_unavailable? suspended_permanently?
def suspended_temporarily?
suspended? && deletion_request.present?
end
def suspend!(date: Time.now.utc, origin: :local, block_email: true)
transaction do
create_deletion_request!
update!(suspended_at: date, suspension_origin: origin)
create_canonical_email_block! if block_email
end
end
def unsuspend!
transaction do
deletion_request&.destroy!
update!(suspended_at: nil, suspension_origin: nil)
destroy_canonical_email_block!
end
end
def approve_remote!
return unless remote_pending
update!(remote_pending: false)
unsuspend!
ActivateRemoteAccountWorker.perform_async(id)
end
def reject_remote!
return unless remote_pending
update!(remote_pending: false, suspension_origin: :local)
pending_follow_requests.destroy_all
pending_statuses.destroy_all
suspend!
end
end

View file

@ -26,7 +26,7 @@ module Remotable
public_send(:"#{attachment_name}=", ResponseWithLimit.new(response, limit))
end
rescue Mastodon::UnexpectedResponseError, HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError => e
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS => e
Rails.logger.debug { "Error fetching remote #{attachment_name}: #{e}" }
public_send(:"#{attachment_name}=", nil) if public_send(:"#{attachment_name}_file_name").present?
raise e unless suppress_errors

View file

@ -32,7 +32,7 @@ class Form::Redirect
def set_target_account
@target_account = ResolveAccountService.new.call(acct, skip_cache: true)
rescue Webfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error, Addressable::URI::InvalidURIError
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS, Mastodon::Error, Addressable::URI::InvalidURIError
# Validation will take care of it
end

View file

@ -66,7 +66,7 @@ class RemoteFollow
def acct_resource
@acct_resource ||= Webfinger.new("acct:#{acct}").perform
rescue Webfinger::Error, HTTP::ConnectionError
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS
nil
end