Domain blocks now have varying severity - auto-suspend vs auto-silence
This commit is contained in:
parent
ef2b924679
commit
6d98a73180
8 changed files with 25 additions and 12 deletions
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DomainBlock < ApplicationRecord
|
||||
enum severity: [:silence, :suspend]
|
||||
|
||||
validates :domain, presence: true, uniqueness: true
|
||||
|
||||
def self.blocked?(domain)
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class BlockDomainService < BaseService
|
||||
def call(domain)
|
||||
DomainBlock.find_or_create_by!(domain: domain)
|
||||
def call(domain, severity)
|
||||
DomainBlock.where(domain: domain).first_or_create!(domain: domain, severity: severity)
|
||||
|
||||
Account.where(domain: domain).find_each do |account|
|
||||
if account.subscribed?
|
||||
account.subscription(api_subscription_url(account.id)).unsubscribe
|
||||
if severity == :silence
|
||||
Account.where(domain: domain).update_all(silenced: true)
|
||||
else
|
||||
Account.where(domain: domain).find_each do |account|
|
||||
account.subscription(api_subscription_url(account.id)).unsubscribe if account.subscribed?
|
||||
SuspendAccountService.new.call(account)
|
||||
end
|
||||
|
||||
account.destroy!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,12 +35,15 @@ class FollowRemoteAccountService < BaseService
|
|||
|
||||
Rails.logger.debug "Creating new remote account for #{uri}"
|
||||
|
||||
domain_block = DomainBlock.find_by(domain: domain)
|
||||
|
||||
account.remote_url = data.link('http://schemas.google.com/g/2010#updates-from').href
|
||||
account.salmon_url = data.link('salmon').href
|
||||
account.url = data.link('http://webfinger.net/rel/profile-page').href
|
||||
account.public_key = magic_key_to_pem(data.link('magic-public-key').href)
|
||||
account.private_key = nil
|
||||
account.suspended = true if DomainBlock.blocked?(domain)
|
||||
account.suspended = true if domain_block && domain_block.suspend?
|
||||
account.silenced = true if domain_block && domain_block.silence?
|
||||
|
||||
xml = get_feed(account.remote_url)
|
||||
hubs = get_hubs(xml)
|
||||
|
|
|
@ -18,7 +18,6 @@ class SuspendAccountService < BaseService
|
|||
|
||||
@account.media_attachments.destroy_all
|
||||
@account.stream_entries.destroy_all
|
||||
@account.mentions.destroy_all
|
||||
@account.notifications.destroy_all
|
||||
@account.favourites.destroy_all
|
||||
@account.active_relationships.destroy_all
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
%thead
|
||||
%tr
|
||||
%th Domain
|
||||
%th Severity
|
||||
%tbody
|
||||
- @blocks.each do |block|
|
||||
%tr
|
||||
%td
|
||||
%samp= block.domain
|
||||
%td= block.severity
|
||||
|
||||
= will_paginate @blocks, pagination_options
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue