Merge branch 'master' into glitch-soc/merge-upstream

Conflicts:
- `.github/ISSUE_TEMPLATE/bug_report.md`:
  Upstream added the `bug` label to bug reports.
  Did the same.
- `app/services/fan_out_on_write_service.rb`:
  Upstream put DMs back into timelines, glitch-soc was already doing it.
  Ignored upstream changes.
This commit is contained in:
Thibaut Girka
2020-11-20 13:27:48 +01:00
42 changed files with 1362 additions and 320 deletions

View File

@@ -41,6 +41,7 @@ class DeleteAccountService < BaseService
# @option [Boolean] :reserve_email Keep user record. Only applicable for local accounts
# @option [Boolean] :reserve_username Keep account record
# @option [Boolean] :skip_side_effects Side effects are ActivityPub and streaming API payloads
# @option [Boolean] :skip_activitypub Skip sending ActivityPub payloads. Implied by :skip_side_effects
# @option [Time] :suspended_at Only applicable when :reserve_username is true
def call(account, **options)
@account = account
@@ -52,6 +53,8 @@ class DeleteAccountService < BaseService
@options[:skip_side_effects] = true
end
@options[:skip_activitypub] = true if @options[:skip_side_effects]
reject_follows!
purge_user!
purge_profile!
@@ -62,7 +65,7 @@ class DeleteAccountService < BaseService
private
def reject_follows!
return if @account.local? || !@account.activitypub?
return if @account.local? || !@account.activitypub? || @options[:skip_activitypub]
# When deleting a remote account, the account obviously doesn't
# actually become deleted on its origin server, i.e. unlike a

View File

@@ -18,6 +18,8 @@ class ImportService < BaseService
import_mutes!
when 'domain_blocking'
import_domain_blocks!
when 'bookmarks'
import_bookmarks!
end
end
@@ -88,6 +90,39 @@ class ImportService < BaseService
end
end
def import_bookmarks!
parse_import_data!(['#uri'])
items = @data.take(ROWS_PROCESSING_LIMIT).map { |row| row['#uri'].strip }
if @import.overwrite?
presence_hash = items.each_with_object({}) { |id, mapping| mapping[id] = true }
@account.bookmarks.find_each do |bookmark|
if presence_hash[bookmark.status.uri]
items.delete(bookmark.status.uri)
else
bookmark.destroy!
end
end
end
statuses = items.map do |uri|
status = ActivityPub::TagManager.instance.uri_to_resource(uri, Status)
next if status.nil? && ActivityPub::TagManager.instance.local_uri?(uri)
status || ActivityPub::FetchRemoteStatusService.new.call(uri)
end.compact
account_ids = statuses.map(&:account_id)
preloaded_relations = relations_map_for_account(@account, account_ids)
statuses.keep_if { |status| StatusPolicy.new(@account, status, preloaded_relations).show? }
statuses.each do |status|
@account.bookmarks.find_or_create_by!(account: @account, status: status)
end
end
def parse_import_data!(default_headers)
data = CSV.parse(import_data, headers: true)
data = CSV.parse(import_data, headers: default_headers) unless data.headers&.first&.strip&.include?(' ')
@@ -101,4 +136,14 @@ class ImportService < BaseService
def follow_limit
FollowLimitValidator.limit_for_account(@account)
end
def relations_map_for_account(account, account_ids)
{
blocking: {},
blocked_by: Account.blocked_by_map(account_ids, account.id),
muting: {},
following: Account.following_map(account_ids, account.id),
domain_blocking_by_domain: {},
}
end
end

View File

@@ -29,6 +29,7 @@ class ResolveAccountService < BaseService
# At this point we are in need of a Webfinger query, which may
# yield us a different username/domain through a redirect
process_webfinger!(@uri)
@domain = nil if TagManager.instance.local_domain?(@domain)
# Because the username/domain pair may be different than what
# we already checked, we need to check if we've already got
@@ -78,25 +79,31 @@ class ResolveAccountService < BaseService
@uri = [@username, @domain].compact.join('@')
end
def process_webfinger!(uri, redirected = false)
def process_webfinger!(uri)
@webfinger = webfinger!("acct:#{uri}")
confirmed_username, confirmed_domain = @webfinger.subject.gsub(/\Aacct:/, '').split('@')
confirmed_username, confirmed_domain = split_acct(@webfinger.subject)
if confirmed_username.casecmp(@username).zero? && confirmed_domain.casecmp(@domain).zero?
@username = confirmed_username
@domain = confirmed_domain
@uri = uri
elsif !redirected
return process_webfinger!("#{confirmed_username}@#{confirmed_domain}", true)
else
raise Webfinger::RedirectError, "The URI #{uri} tries to hijack #{@username}@#{@domain}"
return
end
@domain = nil if TagManager.instance.local_domain?(@domain)
# Account doesn't match, so it may have been redirected
@webfinger = webfinger!("acct:#{confirmed_username}@#{confirmed_domain}")
@username, @domain = split_acct(@webfinger.subject)
unless confirmed_username.casecmp(@username).zero? && confirmed_domain.casecmp(@domain).zero?
raise Webfinger::RedirectError, "The URI #{uri} tries to hijack #{@username}@#{@domain}"
end
rescue Webfinger::GoneError
@gone = true
end
def split_acct(acct)
acct.gsub(/\Aacct:/, '').split('@')
end
def process_account!
return unless activitypub_ready?
@@ -145,7 +152,7 @@ class ResolveAccountService < BaseService
end
def queue_deletion!
AccountDeletionWorker.perform_async(@account.id, reserve_username: false)
AccountDeletionWorker.perform_async(@account.id, reserve_username: false, skip_activitypub: true)
end
def lock_options

View File

@@ -78,6 +78,8 @@ class SuspendAccountService < BaseService
Rails.logger.warn "Tried to change permission on non-existent file #{attachment.path(style)}"
end
end
CacheBusterWorker.perform_async(attachment.path(style)) if Rails.configuration.x.cache_buster_enabled
end
end
end

View File

@@ -69,6 +69,8 @@ class UnsuspendAccountService < BaseService
Rails.logger.warn "Tried to change permission on non-existent file #{attachment.path(style)}"
end
end
CacheBusterWorker.perform_async(attachment.path(style)) if Rails.configuration.x.cache_buster_enabled
end
end
end