Record account suspend/silence time and keep track of domain blocks
This commit is contained in:
parent
6d44f2441b
commit
30296f1bb0
|
@ -45,6 +45,8 @@
|
||||||
# actor_type :string
|
# actor_type :string
|
||||||
# discoverable :boolean
|
# discoverable :boolean
|
||||||
# also_known_as :string is an Array
|
# also_known_as :string is an Array
|
||||||
|
# silenced_at :datetime
|
||||||
|
# suspended_at :datetime
|
||||||
#
|
#
|
||||||
|
|
||||||
class Account < ApplicationRecord
|
class Account < ApplicationRecord
|
||||||
|
@ -165,25 +167,27 @@ class Account < ApplicationRecord
|
||||||
ResolveAccountService.new.call(acct)
|
ResolveAccountService.new.call(acct)
|
||||||
end
|
end
|
||||||
|
|
||||||
def silence!
|
def silence!(date = nil)
|
||||||
update!(silenced: true)
|
date = Time.now.utc if date.nil?
|
||||||
|
update!(silenced: true, silenced_at: date)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unsilence!
|
def unsilence!
|
||||||
update!(silenced: false)
|
update!(silenced: false, silenced_at: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def suspend!
|
def suspend!(date = nil)
|
||||||
|
date = Time.now.utc if date.nil?
|
||||||
transaction do
|
transaction do
|
||||||
user&.disable! if local?
|
user&.disable! if local?
|
||||||
update!(suspended: true)
|
update!(suspended: true, suspended_at: date)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def unsuspend!
|
def unsuspend!
|
||||||
transaction do
|
transaction do
|
||||||
user&.enable! if local?
|
user&.enable! if local?
|
||||||
update!(suspended: false)
|
update!(suspended: false, suspended_at: nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,15 @@ class ActivityPub::ProcessAccountService < BaseService
|
||||||
@account.protocol = :activitypub
|
@account.protocol = :activitypub
|
||||||
@account.username = @username
|
@account.username = @username
|
||||||
@account.domain = @domain
|
@account.domain = @domain
|
||||||
@account.suspended = true if auto_suspend?
|
|
||||||
@account.silenced = true if auto_silence?
|
|
||||||
@account.private_key = nil
|
@account.private_key = nil
|
||||||
|
if auto_suspend?
|
||||||
|
@account.suspended = true
|
||||||
|
@account.suspended_at = domain_block.created_at
|
||||||
|
end
|
||||||
|
if auto_silence?
|
||||||
|
@account.silenced = true
|
||||||
|
@account.silenced_at = domain_block.created_at
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_account
|
def update_account
|
||||||
|
|
|
@ -29,7 +29,7 @@ class BlockDomainService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def silence_accounts!
|
def silence_accounts!
|
||||||
blocked_domain_accounts.in_batches.update_all(silenced: true)
|
blocked_domain_accounts.where(silenced: false).in_batches.update_all(silenced: true, silenced_at: @domain_block.created_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_media!
|
def clear_media!
|
||||||
|
@ -45,7 +45,7 @@ class BlockDomainService < BaseService
|
||||||
def suspend_accounts!
|
def suspend_accounts!
|
||||||
blocked_domain_accounts.where(suspended: false).reorder(nil).find_each do |account|
|
blocked_domain_accounts.where(suspended: false).reorder(nil).find_each do |account|
|
||||||
UnsubscribeService.new.call(account) if account.subscribed?
|
UnsubscribeService.new.call(account) if account.subscribed?
|
||||||
SuspendAccountService.new.call(account)
|
SuspendAccountService.new.call(account, suspended_at: @domain_block.created_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -119,9 +119,15 @@ class ResolveAccountService < BaseService
|
||||||
Rails.logger.debug "Creating new remote account for #{@username}@#{@domain}"
|
Rails.logger.debug "Creating new remote account for #{@username}@#{@domain}"
|
||||||
|
|
||||||
@account = Account.new(username: @username, domain: @domain)
|
@account = Account.new(username: @username, domain: @domain)
|
||||||
@account.suspended = true if auto_suspend?
|
|
||||||
@account.silenced = true if auto_silence?
|
|
||||||
@account.private_key = nil
|
@account.private_key = nil
|
||||||
|
if auto_suspend?
|
||||||
|
@account.suspended = true
|
||||||
|
@account.suspended_at = domain_block.created_at
|
||||||
|
end
|
||||||
|
if auto_silence?
|
||||||
|
@account.silenced = true
|
||||||
|
@account.silenced_at = domain_block.created_at
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_account
|
def update_account
|
||||||
|
|
|
@ -89,7 +89,9 @@ class SuspendAccountService < BaseService
|
||||||
return if @options[:destroy]
|
return if @options[:destroy]
|
||||||
|
|
||||||
@account.silenced = false
|
@account.silenced = false
|
||||||
|
@account.silenced_at = nil
|
||||||
@account.suspended = true
|
@account.suspended = true
|
||||||
|
@account.suspended_at = @options[:suspended_at] || Time.now.utc
|
||||||
@account.locked = false
|
@account.locked = false
|
||||||
@account.display_name = ''
|
@account.display_name = ''
|
||||||
@account.note = ''
|
@account.note = ''
|
||||||
|
|
|
@ -14,7 +14,12 @@ class UnblockDomainService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def blocked_accounts
|
def blocked_accounts
|
||||||
Account.where(domain: domain_block.domain)
|
scope = Account.where(domain: domain_block.domain)
|
||||||
|
if domain_block.silence?
|
||||||
|
scope.where(silenced_at: @domain_block.created_at)
|
||||||
|
else
|
||||||
|
scope.where(suspended_at: @domain_block.created_at)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_options
|
def update_options
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddSilencedAtSuspendedAtToAccounts < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :accounts, :silenced_at, :datetime
|
||||||
|
add_column :accounts, :suspended_at, :datetime
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2019_05_09_164208) do
|
ActiveRecord::Schema.define(version: 2019_05_11_134027) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -148,6 +148,8 @@ ActiveRecord::Schema.define(version: 2019_05_09_164208) do
|
||||||
t.string "actor_type"
|
t.string "actor_type"
|
||||||
t.boolean "discoverable"
|
t.boolean "discoverable"
|
||||||
t.string "also_known_as", array: true
|
t.string "also_known_as", array: true
|
||||||
|
t.datetime "silenced_at"
|
||||||
|
t.datetime "suspended_at"
|
||||||
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
|
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
|
||||||
t.index "lower((username)::text), lower((domain)::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
|
t.index "lower((username)::text), lower((domain)::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
|
||||||
t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id"
|
t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id"
|
||||||
|
|
Loading…
Reference in New Issue