Add account sensitized (#14361)

* Add account sensitized

* Fix i18n normalize

* Fix description and spec

* Fix spec

* Fix wording
This commit is contained in:
Takeshi Umeda
2020-11-05 04:45:01 +09:00
committed by GitHub
parent f90620b2f3
commit d6fe0c94ca
24 changed files with 136 additions and 13 deletions

View File

@ -50,6 +50,7 @@
# avatar_storage_schema_version :integer
# header_storage_schema_version :integer
# devices_url :string
# sensitized_at :datetime
#
class Account < ApplicationRecord
@ -92,6 +93,7 @@ class Account < ApplicationRecord
scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
scope :silenced, -> { where.not(silenced_at: nil) }
scope :suspended, -> { where.not(suspended_at: nil) }
scope :sensitized, -> { where.not(sensitized_at: nil) }
scope :without_suspended, -> { where(suspended_at: nil) }
scope :without_silenced, -> { where(silenced_at: nil) }
scope :recent, -> { reorder(id: :desc) }
@ -234,6 +236,18 @@ class Account < ApplicationRecord
end
end
def sensitized?
sensitized_at.present?
end
def sensitize!(date = Time.now.utc)
update!(sensitized_at: date)
end
def unsensitize!
update!(sensitized_at: nil)
end
def memorialize!
update!(memorial: true)
end

View File

@ -13,7 +13,7 @@
#
class AccountWarning < ApplicationRecord
enum action: %i(none disable silence suspend), _suffix: :action
enum action: %i(none disable sensitive silence suspend), _suffix: :action
belongs_to :account, inverse_of: :account_warnings
belongs_to :target_account, class_name: 'Account', inverse_of: :targeted_account_warnings

View File

@ -8,6 +8,7 @@ class Admin::AccountAction
TYPES = %w(
none
disable
sensitive
silence
suspend
).freeze
@ -64,6 +65,8 @@ class Admin::AccountAction
case type
when 'disable'
handle_disable!
when 'sensitive'
handle_sensitive!
when 'silence'
handle_silence!
when 'suspend'
@ -109,6 +112,12 @@ class Admin::AccountAction
target_account.user&.disable!
end
def handle_sensitive!
authorize(target_account, :sensitive?)
log_action(:sensitive, target_account)
target_account.sensitize!
end
def handle_silence!
authorize(target_account, :silence?)
log_action(:silence, target_account)

View File

@ -35,9 +35,11 @@ class Admin::ActionLogFilter
reopen_report: { target_type: 'Report', action: 'reopen' }.freeze,
reset_password_user: { target_type: 'User', action: 'reset_password' }.freeze,
resolve_report: { target_type: 'Report', action: 'resolve' }.freeze,
sensitive_account: { target_type: 'Account', action: 'sensitive' }.freeze,
silence_account: { target_type: 'Account', action: 'silence' }.freeze,
suspend_account: { target_type: 'Account', action: 'suspend' }.freeze,
unassigned_report: { target_type: 'Report', action: 'unassigned' }.freeze,
unsensitive_account: { target_type: 'Account', action: 'unsensitive' }.freeze,
unsilence_account: { target_type: 'Account', action: 'unsilence' }.freeze,
unsuspend_account: { target_type: 'Account', action: 'unsuspend' }.freeze,
update_announcement: { target_type: 'Announcement', action: 'update' }.freeze,