0
0
Fork 0

Record account suspend/silence time and keep track of domain blocks (#10660)

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

* Also unblock users who were suspended/silenced before dates were recorded

* Add tests

* Keep track of suspending date for users suspended through the CLI

* Show accurate number of accounts that would be affected by unsuspending an instance

* Change migration to set silenced_at and suspended_at

* Revert "Also unblock users who were suspended/silenced before dates were recorded"

This reverts commit a015c65d2d1e28c7b7cfab8b3f8cd5fb48b8b71c.

* Switch from using suspended and silenced to suspended_at and silenced_at

* Add post-deployment migration script to remove `suspended` and `silenced` columns

* Use Account#silence! and Account#suspend! instead of updating the underlying property

* Add silenced_at and suspended_at migration to post-migration

* Change account fabricator to translate suspended and silenced attributes

* Minor fixes

* Make unblocking domains always retroactive
This commit is contained in:
ThibG 2019-05-14 19:05:02 +02:00 committed by Eugen Rochko
parent 564106c5d6
commit 14f6ce2885
30 changed files with 226 additions and 115 deletions

View file

@ -28,8 +28,6 @@
# header_updated_at :datetime
# avatar_remote_url :string
# subscription_expires_at :datetime
# silenced :boolean default(FALSE), not null
# suspended :boolean default(FALSE), not null
# locked :boolean default(FALSE), not null
# header_remote_url :string default(""), not null
# last_webfingered_at :datetime
@ -45,6 +43,8 @@
# actor_type :string
# discoverable :boolean
# also_known_as :string is an Array
# silenced_at :datetime
# suspended_at :datetime
#
class Account < ApplicationRecord
@ -82,10 +82,10 @@ class Account < ApplicationRecord
scope :local, -> { where(domain: nil) }
scope :expiring, ->(time) { remote.where.not(subscription_expires_at: nil).where('subscription_expires_at < ?', time) }
scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
scope :silenced, -> { where(silenced: true) }
scope :suspended, -> { where(suspended: true) }
scope :without_suspended, -> { where(suspended: false) }
scope :without_silenced, -> { where(silenced: false) }
scope :silenced, -> { where.not(silenced_at: nil) }
scope :suspended, -> { where.not(suspended_at: nil) }
scope :without_suspended, -> { where(suspended_at: nil) }
scope :without_silenced, -> { where(silenced_at: nil) }
scope :recent, -> { reorder(id: :desc) }
scope :bots, -> { where(actor_type: %w(Application Service)) }
scope :alphabetic, -> { order(domain: :asc, username: :asc) }
@ -165,25 +165,35 @@ class Account < ApplicationRecord
ResolveAccountService.new.call(acct)
end
def silence!
update!(silenced: true)
def silenced?
silenced_at.present?
end
def silence!(date = nil)
date ||= Time.now.utc
update!(silenced_at: date)
end
def unsilence!
update!(silenced: false)
update!(silenced_at: nil)
end
def suspend!
def suspended?
suspended_at.present?
end
def suspend!(date = nil)
date ||= Time.now.utc
transaction do
user&.disable! if local?
update!(suspended: true)
update!(suspended_at: date)
end
end
def unsuspend!
transaction do
user&.enable! if local?
update!(suspended: false)
update!(suspended_at: nil)
end
end
@ -399,7 +409,7 @@ class Account < ApplicationRecord
ts_rank_cd(#{textsearch}, #{query}, 32) AS rank
FROM accounts
WHERE #{query} @@ #{textsearch}
AND accounts.suspended = false
AND accounts.suspended_at IS NULL
AND accounts.moved_to_account_id IS NULL
ORDER BY rank DESC
LIMIT ? OFFSET ?
@ -427,7 +437,7 @@ class Account < ApplicationRecord
LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = ?) OR (accounts.id = f.target_account_id AND f.account_id = ?)
WHERE accounts.id IN (SELECT * FROM first_degree)
AND #{query} @@ #{textsearch}
AND accounts.suspended = false
AND accounts.suspended_at IS NULL
AND accounts.moved_to_account_id IS NULL
GROUP BY accounts.id
ORDER BY rank DESC
@ -443,7 +453,7 @@ class Account < ApplicationRecord
FROM accounts
LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = ?) OR (accounts.id = f.target_account_id AND f.account_id = ?)
WHERE #{query} @@ #{textsearch}
AND accounts.suspended = false
AND accounts.suspended_at IS NULL
AND accounts.moved_to_account_id IS NULL
GROUP BY accounts.id
ORDER BY rank DESC