Adding domain blocks
This commit is contained in:
parent
52d7f862d3
commit
22a8801dbc
13 changed files with 92 additions and 10 deletions
|
@ -13,8 +13,9 @@ class Api::SubscriptionsController < ApiController
|
|||
|
||||
def update
|
||||
body = request.body.read
|
||||
subscription = @account.subscription(api_subscription_url(@account.id))
|
||||
|
||||
if @account.subscription(api_subscription_url(@account.id)).verify(body, request.headers['HTTP_X_HUB_SIGNATURE'])
|
||||
if subscription.verify(body, request.headers['HTTP_X_HUB_SIGNATURE'])
|
||||
ProcessFeedService.new.call(body, @account)
|
||||
head 201
|
||||
else
|
||||
|
|
|
@ -24,10 +24,10 @@ class Account < ApplicationRecord
|
|||
validates :note, length: { maximum: 124 }, if: 'local?'
|
||||
|
||||
# Timelines
|
||||
has_many :stream_entries, inverse_of: :account
|
||||
has_many :statuses, inverse_of: :account
|
||||
has_many :favourites, inverse_of: :account
|
||||
has_many :mentions, inverse_of: :account
|
||||
has_many :stream_entries, inverse_of: :account, dependent: :destroy
|
||||
has_many :statuses, inverse_of: :account, dependent: :destroy
|
||||
has_many :favourites, inverse_of: :account, dependent: :destroy
|
||||
has_many :mentions, inverse_of: :account, dependent: :destroy
|
||||
|
||||
# Follow relations
|
||||
has_many :active_relationships, class_name: 'Follow', foreign_key: 'account_id', dependent: :destroy
|
||||
|
|
7
app/models/domain_block.rb
Normal file
7
app/models/domain_block.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class DomainBlock < ApplicationRecord
|
||||
validates :domain, presence: true, uniqueness: true
|
||||
|
||||
def self.blocked?(domain)
|
||||
where(domain: domain).exists?
|
||||
end
|
||||
end
|
13
app/services/block_domain_service.rb
Normal file
13
app/services/block_domain_service.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class BlockDomainService < BaseService
|
||||
def call(domain)
|
||||
block = DomainBlock.find_or_create_by!(domain: domain)
|
||||
|
||||
Account.where(domain: domain).find_each do |account|
|
||||
if account.subscribed?
|
||||
account.subscription('').unsubscribe
|
||||
end
|
||||
|
||||
account.destroy!
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,6 +8,7 @@ class FollowRemoteAccountService < BaseService
|
|||
username, domain = uri.split('@')
|
||||
|
||||
return Account.find_local(username) if TagManager.instance.local_domain?(domain)
|
||||
return nil if DomainBlock.blocked?(domain)
|
||||
|
||||
account = Account.find_remote(username, domain)
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ class ProcessInteractionService < BaseService
|
|||
domain = Addressable::URI.parse(url).host
|
||||
account = Account.find_by(username: username, domain: domain)
|
||||
|
||||
return if DomainBlock.blocked?(domain)
|
||||
|
||||
if account.nil?
|
||||
account = follow_remote_account_service.call("#{username}@#{domain}")
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue