Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo notification permissions on individual and domain blocks #29570

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/services/after_block_domain_from_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def call(account, domain)
@domain_block_event = nil

clear_notifications!
clear_notification_permissions!
remove_follows!
reject_existing_followers!
reject_pending_follow_requests!
Expand All @@ -31,6 +32,10 @@ def clear_notifications!
Notification.where(account: @account).where(from_account: Account.where(domain: @domain)).in_batches.delete_all
end

def clear_notification_permissions!
NotificationPermission.where(account: @account, from_account: Account.where(domain: @domain)).in_batches.delete_all
end

def reject_existing_followers!
@account.passive_relationships.where(account: Account.where(domain: @domain)).includes(:account).reorder(nil).in_batches do |follows|
domain_block_event.import_from_passive_follows!(follows)
Expand Down
2 changes: 2 additions & 0 deletions app/services/block_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def call(account, target_account)
UnfollowService.new.call(target_account, account) if target_account.following?(account)
RejectFollowService.new.call(target_account, account) if target_account.requested?(account)

NotificationPermission.where(account: account, from_account: target_account).destroy_all

block = account.block!(target_account)

BlockWorker.perform_async(account.id, target_account.id)
Expand Down
15 changes: 6 additions & 9 deletions spec/services/after_block_domain_from_account_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@
let(:alice) { Fabricate(:account, username: 'alice') }

before do
NotificationPermission.create!(account: alice, from_account: wolf)

wolf.follow!(alice)
alice.follow!(dog)
end

around do |example|
Sidekiq::Testing.fake! do
example.run
end
end

it 'purges followers from blocked domain, sends them Reject->Follow, and records severed relationships', :aggregate_failures do
subject.call(alice, 'evil.org')
it 'purge followers from blocked domain, remove notification permissions, sends `Reject->Follow`, and records severed relationships', :aggregate_failures do
expect { subject.call(alice, 'evil.org') }
.to change { wolf.following?(alice) }.from(true).to(false)
.and change { NotificationPermission.exists?(account: alice, from_account: wolf) }.from(true).to(false)

expect(wolf.following?(alice)).to be false
expect(ActivityPub::DeliveryWorker.jobs.pluck('args')).to contain_exactly(
[a_string_including('"type":"Reject"'), alice.id, wolf.inbox_url],
[a_string_including('"type":"Undo"'), alice.id, dog.inbox_url]
Expand Down
8 changes: 5 additions & 3 deletions spec/services/block_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
let(:bob) { Fabricate(:account, username: 'bob') }

before do
subject.call(sender, bob)
NotificationPermission.create!(account: sender, from_account: bob)
end

it 'creates a blocking relation' do
expect(sender.blocking?(bob)).to be true
it 'creates a blocking relation and removes notification permissions' do
expect { subject.call(sender, bob) }
.to change { sender.blocking?(bob) }.from(false).to(true)
.and change { NotificationPermission.exists?(account: sender, from_account: bob) }.from(true).to(false)
end
end

Expand Down