1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Record account suspend/silence time and keep track of domain blocks

This commit is contained in:
Thibaut Girka 2019-05-01 11:26:58 +02:00
parent 6d44f2441b
commit 30296f1bb0
8 changed files with 45 additions and 14 deletions

View file

@ -45,6 +45,8 @@
# actor_type :string
# discoverable :boolean
# also_known_as :string is an Array
# silenced_at :datetime
# suspended_at :datetime
#
class Account < ApplicationRecord
@ -165,25 +167,27 @@ class Account < ApplicationRecord
ResolveAccountService.new.call(acct)
end
def silence!
update!(silenced: true)
def silence!(date = nil)
date = Time.now.utc if date.nil?
update!(silenced: true, silenced_at: date)
end
def unsilence!
update!(silenced: false)
update!(silenced: false, silenced_at: nil)
end
def suspend!
def suspend!(date = nil)
date = Time.now.utc if date.nil?
transaction do
user&.disable! if local?
update!(suspended: true)
update!(suspended: true, suspended_at: date)
end
end
def unsuspend!
transaction do
user&.enable! if local?
update!(suspended: false)
update!(suspended: false, suspended_at: nil)
end
end

View file

@ -53,9 +53,15 @@ class ActivityPub::ProcessAccountService < BaseService
@account.protocol = :activitypub
@account.username = @username
@account.domain = @domain
@account.suspended = true if auto_suspend?
@account.silenced = true if auto_silence?
@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
def update_account

View file

@ -29,7 +29,7 @@ class BlockDomainService < BaseService
end
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
def clear_media!
@ -45,7 +45,7 @@ class BlockDomainService < BaseService
def suspend_accounts!
blocked_domain_accounts.where(suspended: false).reorder(nil).find_each do |account|
UnsubscribeService.new.call(account) if account.subscribed?
SuspendAccountService.new.call(account)
SuspendAccountService.new.call(account, suspended_at: @domain_block.created_at)
end
end

View file

@ -119,9 +119,15 @@ class ResolveAccountService < BaseService
Rails.logger.debug "Creating new remote account for #{@username}@#{@domain}"
@account = Account.new(username: @username, domain: @domain)
@account.suspended = true if auto_suspend?
@account.silenced = true if auto_silence?
@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
def update_account

View file

@ -89,7 +89,9 @@ class SuspendAccountService < BaseService
return if @options[:destroy]
@account.silenced = false
@account.silenced_at = nil
@account.suspended = true
@account.suspended_at = @options[:suspended_at] || Time.now.utc
@account.locked = false
@account.display_name = ''
@account.note = ''

View file

@ -14,7 +14,12 @@ class UnblockDomainService < BaseService
end
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
def update_options

View file

@ -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

View file

@ -10,7 +10,7 @@
#
# 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
enable_extension "plpgsql"
@ -148,6 +148,8 @@ ActiveRecord::Schema.define(version: 2019_05_09_164208) do
t.string "actor_type"
t.boolean "discoverable"
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 "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"