forked from berserker/microblog
Fix domain hiding logic (#7765)
* Send rejections to followers when user hides domain they're on * Use account domain blocks for "authorized followers" action Replace soft-blocking (block & unblock) behaviour with follow rejection * Split sync and async work of account domain blocking Do not create domain block when removing followers by domain, that is probably unexpected from the user's perspective. * Adjust confirmation message for domain block * yarn manage:translationslocal
parent
91e5d9f8af
commit
10f51c9886
12 changed files with 84 additions and 63 deletions
@ -0,0 +1,42 @@ |
|||||||
|
# frozen_string_literal: true |
||||||
|
|
||||||
|
class AfterBlockDomainFromAccountService < BaseService |
||||||
|
# This service does not create an AccountDomainBlock record, |
||||||
|
# it's meant to be called after such a record has been created |
||||||
|
# synchronously, to "clean up" |
||||||
|
def call(account, domain) |
||||||
|
@account = account |
||||||
|
@domain = domain |
||||||
|
|
||||||
|
reject_existing_followers! |
||||||
|
reject_pending_follow_requests! |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def reject_existing_followers! |
||||||
|
@account.passive_relationships.where(account: Account.where(domain: @domain)).includes(:account).find_each do |follow| |
||||||
|
reject_follow!(follow) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def reject_pending_follow_requests! |
||||||
|
FollowRequest.where(target_account: @account).where(account: Account.where(domain: @domain)).includes(:account).find_each do |follow_request| |
||||||
|
reject_follow!(follow_request) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def reject_follow!(follow) |
||||||
|
follow.destroy |
||||||
|
|
||||||
|
return unless follow.account.activitypub? |
||||||
|
|
||||||
|
json = Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new( |
||||||
|
follow, |
||||||
|
serializer: ActivityPub::RejectFollowSerializer, |
||||||
|
adapter: ActivityPub::Adapter |
||||||
|
).as_json).sign!(@account)) |
||||||
|
|
||||||
|
ActivityPub::DeliveryWorker.perform_async(json, @account.id, follow.account.inbox_url) |
||||||
|
end |
||||||
|
end |
@ -1,8 +0,0 @@ |
|||||||
# frozen_string_literal: true |
|
||||||
|
|
||||||
class BlockDomainFromAccountService < BaseService |
|
||||||
def call(account, domain) |
|
||||||
account.block_domain!(domain) |
|
||||||
account.passive_relationships.where(account: Account.where(domain: domain)).delete_all |
|
||||||
end |
|
||||||
end |
|
@ -0,0 +1,11 @@ |
|||||||
|
# frozen_string_literal: true |
||||||
|
|
||||||
|
class AfterAccountDomainBlockWorker |
||||||
|
include Sidekiq::Worker |
||||||
|
|
||||||
|
def perform(account_id, domain) |
||||||
|
AfterBlockDomainFromAccountService.new.call(Account.find(account_id), domain) |
||||||
|
rescue ActiveRecord::RecordNotFound |
||||||
|
true |
||||||
|
end |
||||||
|
end |
@ -1,14 +0,0 @@ |
|||||||
# frozen_string_literal: true |
|
||||||
|
|
||||||
class SoftBlockDomainFollowersWorker |
|
||||||
include Sidekiq::Worker |
|
||||||
|
|
||||||
sidekiq_options queue: 'pull' |
|
||||||
|
|
||||||
def perform(account_id, domain) |
|
||||||
followers_id = Account.find(account_id).followers.where(domain: domain).pluck(:id) |
|
||||||
SoftBlockWorker.push_bulk(followers_id) do |follower_id| |
|
||||||
[account_id, follower_id] |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,17 +0,0 @@ |
|||||||
# frozen_string_literal: true |
|
||||||
|
|
||||||
class SoftBlockWorker |
|
||||||
include Sidekiq::Worker |
|
||||||
|
|
||||||
sidekiq_options queue: 'pull' |
|
||||||
|
|
||||||
def perform(account_id, target_account_id) |
|
||||||
account = Account.find(account_id) |
|
||||||
target_account = Account.find(target_account_id) |
|
||||||
|
|
||||||
BlockService.new.call(account, target_account) |
|
||||||
UnblockService.new.call(account, target_account) |
|
||||||
rescue ActiveRecord::RecordNotFound |
|
||||||
true |
|
||||||
end |
|
||||||
end |
|
@ -0,0 +1,25 @@ |
|||||||
|
require 'rails_helper' |
||||||
|
|
||||||
|
RSpec.describe AfterBlockDomainFromAccountService, type: :service do |
||||||
|
let!(:wolf) { Fabricate(:account, username: 'wolf', domain: 'evil.org', inbox_url: 'https://evil.org/inbox', protocol: :activitypub) } |
||||||
|
let!(:alice) { Fabricate(:account, username: 'alice') } |
||||||
|
|
||||||
|
subject { AfterBlockDomainFromAccountService.new } |
||||||
|
|
||||||
|
before do |
||||||
|
stub_jsonld_contexts! |
||||||
|
allow(ActivityPub::DeliveryWorker).to receive(:perform_async) |
||||||
|
end |
||||||
|
|
||||||
|
it 'purge followers from blocked domain' do |
||||||
|
wolf.follow!(alice) |
||||||
|
subject.call(alice, 'evil.org') |
||||||
|
expect(wolf.following?(alice)).to be false |
||||||
|
end |
||||||
|
|
||||||
|
it 'sends Reject->Follow to followers from blocked domain' do |
||||||
|
wolf.follow!(alice) |
||||||
|
subject.call(alice, 'evil.org') |
||||||
|
expect(ActivityPub::DeliveryWorker).to have_received(:perform_async).once |
||||||
|
end |
||||||
|
end |
@ -1,19 +0,0 @@ |
|||||||
require 'rails_helper' |
|
||||||
|
|
||||||
RSpec.describe BlockDomainFromAccountService, type: :service do |
|
||||||
let!(:wolf) { Fabricate(:account, username: 'wolf', domain: 'evil.org') } |
|
||||||
let!(:alice) { Fabricate(:account, username: 'alice') } |
|
||||||
|
|
||||||
subject { BlockDomainFromAccountService.new } |
|
||||||
|
|
||||||
it 'creates domain block' do |
|
||||||
subject.call(alice, 'evil.org') |
|
||||||
expect(alice.domain_blocking?('evil.org')).to be true |
|
||||||
end |
|
||||||
|
|
||||||
it 'purge followers from blocked domain' do |
|
||||||
wolf.follow!(alice) |
|
||||||
subject.call(alice, 'evil.org') |
|
||||||
expect(wolf.following?(alice)).to be false |
|
||||||
end |
|
||||||
end |
|
Loading…
Reference in new issue