Merge pull request #1480 from ThibG/glitch-soc/merge-upstream

Merge upstream changes
This commit is contained in:
ThibG 2020-12-21 22:11:27 +01:00 committed by GitHub
commit 81f4c550b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 89 additions and 61 deletions

View File

@ -25,7 +25,7 @@ class Poll < ApplicationRecord
belongs_to :account belongs_to :account
belongs_to :status belongs_to :status
has_many :votes, class_name: 'PollVote', inverse_of: :poll, dependent: :destroy has_many :votes, class_name: 'PollVote', inverse_of: :poll, dependent: :delete_all
has_many :notifications, as: :activity, dependent: :destroy has_many :notifications, as: :activity, dependent: :destroy

View File

@ -83,7 +83,7 @@ class User < ApplicationRecord
has_one :invite_request, class_name: 'UserInviteRequest', inverse_of: :user, dependent: :destroy has_one :invite_request, class_name: 'UserInviteRequest', inverse_of: :user, dependent: :destroy
accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? && !Setting.require_invite_text } accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? && !Setting.require_invite_text }
validates :invite_request, presence: true, on: :create, if: -> { Setting.require_invite_text } validates :invite_request, presence: true, on: :create, if: -> { Setting.require_invite_text && !invited? }
validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale? validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale?
validates_with BlacklistedEmailValidator, on: :create validates_with BlacklistedEmailValidator, on: :create

View File

@ -4,8 +4,6 @@ class BatchedRemoveStatusService < BaseService
include Redisable include Redisable
# Delete given statuses and reblogs of them # Delete given statuses and reblogs of them
# Dispatch PuSH updates of the deleted statuses, but only local ones
# Dispatch Salmon deletes, unique per domain, of the deleted statuses, but only local ones
# Remove statuses from home feeds # Remove statuses from home feeds
# Push delete events to streaming API for home feeds and public feeds # Push delete events to streaming API for home feeds and public feeds
# @param [Enumerable<Status>] statuses A preferably batched array of statuses # @param [Enumerable<Status>] statuses A preferably batched array of statuses
@ -19,7 +17,6 @@ class BatchedRemoveStatusService < BaseService
@json_payloads = statuses.each_with_object({}) { |s, h| h[s.id] = Oj.dump(event: :delete, payload: s.id.to_s) } @json_payloads = statuses.each_with_object({}) { |s, h| h[s.id] = Oj.dump(event: :delete, payload: s.id.to_s) }
# Ensure that rendered XML reflects destroyed state
statuses.each do |status| statuses.each do |status|
status.mark_for_mass_destruction! status.mark_for_mass_destruction!
status.destroy status.destroy

View File

@ -122,7 +122,11 @@ class DeleteAccountService < BaseService
@account.polls.reorder(nil).find_each do |poll| @account.polls.reorder(nil).find_each do |poll|
next if @options[:reserve_username] && reported_status_ids.include?(poll.status_id) next if @options[:reserve_username] && reported_status_ids.include?(poll.status_id)
poll.destroy # We can safely delete the poll rather than destroy it, as any non-reported
# status should have been deleted already, as long as we take care of
# notifications.
Notification.where(poll: poll).delete_all
poll.delete
end end
associations_for_destruction.each do |association_name| associations_for_destruction.each do |association_name|

View File

@ -3,7 +3,7 @@
class AccountDeletionWorker class AccountDeletionWorker
include Sidekiq::Worker include Sidekiq::Worker
sidekiq_options queue: 'pull' sidekiq_options queue: 'pull', lock: :until_executed
def perform(account_id, options = {}) def perform(account_id, options = {})
reserve_username = options.with_indifferent_access.fetch(:reserve_username, true) reserve_username = options.with_indifferent_access.fetch(:reserve_username, true)

View File

@ -1,3 +1,8 @@
unless ENV.key?('RAILS_ENV')
STDERR.puts 'ERROR: Missing RAILS_ENV environment variable, please set it to "production", "development", or "test".'
exit 1
end
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile. require 'bundler/setup' # Set up gems listed in the Gemfile.

View File

@ -1,28 +1,31 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe DeleteAccountService, type: :service do RSpec.describe DeleteAccountService, type: :service do
describe '#call on local account' do shared_examples 'common behavior' do
before do let!(:status) { Fabricate(:status, account: account) }
stub_request(:post, "https://alice.com/inbox").to_return(status: 201) let!(:mention) { Fabricate(:mention, account: local_follower) }
stub_request(:post, "https://bob.com/inbox").to_return(status: 201) let!(:status_with_mention) { Fabricate(:status, account: account, mentions: [mention]) }
end let!(:media_attachment) { Fabricate(:media_attachment, account: account) }
let!(:notification) { Fabricate(:notification, account: account) }
let!(:favourite) { Fabricate(:favourite, account: account, status: Fabricate(:status, account: local_follower)) }
let!(:poll) { Fabricate(:poll, account: account) }
let!(:poll_vote) { Fabricate(:poll_vote, account: local_follower, poll: poll) }
let!(:active_relationship) { Fabricate(:follow, account: account, target_account: local_follower) }
let!(:passive_relationship) { Fabricate(:follow, account: local_follower, target_account: account) }
let!(:endorsement) { Fabricate(:account_pin, account: local_follower, target_account: account) }
let!(:mention_notification) { Fabricate(:notification, account: local_follower, activity: mention, type: :mention) }
let!(:status_notification) { Fabricate(:notification, account: local_follower, activity: status, type: :status) }
let!(:poll_notification) { Fabricate(:notification, account: local_follower, activity: poll, type: :poll) }
let!(:favourite_notification) { Fabricate(:notification, account: local_follower, activity: favourite, type: :favourite) }
let!(:follow_notification) { Fabricate(:notification, account: local_follower, activity: active_relationship, type: :follow) }
subject do subject do
-> { described_class.new.call(account) } -> { described_class.new.call(account) }
end end
let!(:account) { Fabricate(:account) } it 'deletes associated owned records' do
let!(:status) { Fabricate(:status, account: account) }
let!(:media_attachment) { Fabricate(:media_attachment, account: account) }
let!(:notification) { Fabricate(:notification, account: account) }
let!(:favourite) { Fabricate(:favourite, account: account) }
let!(:active_relationship) { Fabricate(:follow, account: account) }
let!(:passive_relationship) { Fabricate(:follow, target_account: account) }
let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox', protocol: :activitypub) }
let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
let!(:endorsment) { Fabricate(:account_pin, account: passive_relationship.account, target_account: account) }
it 'deletes associated records' do
is_expected.to change { is_expected.to change {
[ [
account.statuses, account.statuses,
@ -31,15 +34,46 @@ RSpec.describe DeleteAccountService, type: :service do
account.favourites, account.favourites,
account.active_relationships, account.active_relationships,
account.passive_relationships, account.passive_relationships,
AccountPin.where(target_account: account), account.polls,
].map(&:count) ].map(&:count)
}.from([1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0]) }.from([2, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0])
end end
it 'sends a delete actor activity to all known inboxes' do it 'deletes associated target records' do
subject.call is_expected.to change {
expect(a_request(:post, "https://alice.com/inbox")).to have_been_made.once [
expect(a_request(:post, "https://bob.com/inbox")).to have_been_made.once AccountPin.where(target_account: account),
].map(&:count)
}.from([1]).to([0])
end
it 'deletes associated target notifications' do
is_expected.to change {
[
'poll', 'favourite', 'status', 'mention', 'follow'
].map { |type| Notification.where(type: type).count }
}.from([1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0])
end
end
describe '#call on local account' do
before do
stub_request(:post, "https://alice.com/inbox").to_return(status: 201)
stub_request(:post, "https://bob.com/inbox").to_return(status: 201)
end
let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox', protocol: :activitypub) }
let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
include_examples 'common behavior' do
let!(:account) { Fabricate(:account) }
let!(:local_follower) { Fabricate(:account) }
it 'sends a delete actor activity to all known inboxes' do
subject.call
expect(a_request(:post, "https://alice.com/inbox")).to have_been_made.once
expect(a_request(:post, "https://bob.com/inbox")).to have_been_made.once
end
end end
end end
@ -49,36 +83,14 @@ RSpec.describe DeleteAccountService, type: :service do
stub_request(:post, "https://bob.com/inbox").to_return(status: 201) stub_request(:post, "https://bob.com/inbox").to_return(status: 201)
end end
subject do include_examples 'common behavior' do
-> { described_class.new.call(remote_bob) } let!(:account) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
end let!(:local_follower) { Fabricate(:account) }
let!(:account) { Fabricate(:account) } it 'sends a reject follow to follwer inboxes' do
let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox', protocol: :activitypub) } subject.call
let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) } expect(a_request(:post, account.inbox_url)).to have_been_made.once
let!(:status) { Fabricate(:status, account: remote_bob) } end
let!(:media_attachment) { Fabricate(:media_attachment, account: remote_bob) }
let!(:notification) { Fabricate(:notification, account: remote_bob) }
let!(:favourite) { Fabricate(:favourite, account: remote_bob) }
let!(:active_relationship) { Fabricate(:follow, account: remote_bob, target_account: account) }
let!(:passive_relationship) { Fabricate(:follow, target_account: remote_bob) }
it 'deletes associated records' do
is_expected.to change {
[
remote_bob.statuses,
remote_bob.media_attachments,
remote_bob.notifications,
remote_bob.favourites,
remote_bob.active_relationships,
remote_bob.passive_relationships,
].map(&:count)
}.from([1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0])
end
it 'sends a reject follow to follwer inboxes' do
subject.call
expect(a_request(:post, remote_bob.inbox_url)).to have_been_made.once
end end
end end
end end

View File

@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe RemoveStatusService, type: :service do RSpec.describe RemoveStatusService, type: :service do
subject { RemoveStatusService.new } subject { RemoveStatusService.new }
let!(:alice) { Fabricate(:account) } let!(:alice) { Fabricate(:account, user: Fabricate(:user)) }
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://example.com/salmon') } let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://example.com/salmon') }
let!(:jeff) { Fabricate(:account) } let!(:jeff) { Fabricate(:account) }
let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
@ -17,23 +17,33 @@ RSpec.describe RemoveStatusService, type: :service do
hank.follow!(alice) hank.follow!(alice)
@status = PostStatusService.new.call(alice, text: 'Hello @bob@example.com') @status = PostStatusService.new.call(alice, text: 'Hello @bob@example.com')
FavouriteService.new.call(jeff, @status)
Fabricate(:status, account: bill, reblog: @status, uri: 'hoge') Fabricate(:status, account: bill, reblog: @status, uri: 'hoge')
subject.call(@status)
end end
it 'removes status from author\'s home feed' do it 'removes status from author\'s home feed' do
subject.call(@status)
expect(HomeFeed.new(alice).get(10)).to_not include(@status.id) expect(HomeFeed.new(alice).get(10)).to_not include(@status.id)
end end
it 'removes status from local follower\'s home feed' do it 'removes status from local follower\'s home feed' do
subject.call(@status)
expect(HomeFeed.new(jeff).get(10)).to_not include(@status.id) expect(HomeFeed.new(jeff).get(10)).to_not include(@status.id)
end end
it 'sends delete activity to followers' do it 'sends delete activity to followers' do
subject.call(@status)
expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.twice expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.twice
end end
it 'sends delete activity to rebloggers' do it 'sends delete activity to rebloggers' do
subject.call(@status)
expect(a_request(:post, 'http://example2.com/inbox')).to have_been_made expect(a_request(:post, 'http://example2.com/inbox')).to have_been_made
end end
it 'remove status from notifications' do
expect { subject.call(@status) }.to change {
Notification.where(activity_type: 'Favourite', from_account: jeff, account: alice).count
}.from(1).to(0)
end
end end