Add: ホワイトリスト運用時、承認待ちリモートアカウントの概念ならびに操作画面 (#584)

* Add: ホワイトリスト運用時、承認待ちリモートアカウントの概念ならびに操作画面

* Fix test

* Fix test
This commit is contained in:
KMY(雪あすか) 2024-02-17 21:07:37 +09:00 committed by GitHub
parent 0048a8368e
commit 0f680a21b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 174 additions and 20 deletions

View file

@ -55,6 +55,7 @@
# settings :jsonb
# indexable :boolean default(FALSE), not null
# master_settings :jsonb
# remote_pending :boolean default(FALSE), not null
#
class Account < ApplicationRecord
@ -122,6 +123,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 :remote_pending, -> { where(remote_pending: true).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) }
@ -295,6 +297,16 @@ class Account < ApplicationRecord
end
end
def approve_remote!
update!(remote_pending: false)
unsuspend!
end
def reject_remote!
update!(remote_pending: false)
suspend!
end
def sensitized?
sensitized_at.present?
end

View file

@ -88,6 +88,8 @@ class AccountFilter
Account.without_suspended
when 'pending'
accounts_with_users.merge(User.pending)
when 'remote_pending'
Account.remote_pending
when 'suspended'
Account.suspended
when 'disabled'

View file

@ -23,6 +23,12 @@ class Form::AccountBatch
approve!
when 'reject'
reject!
when 'approve_remote'
approve_remote!
when 'approve_remote_domain'
approve_remote_domain!
when 'reject_remote'
reject_remote!
when 'suppress_follow_recommendation'
suppress_follow_recommendation!
when 'unsuppress_follow_recommendation'
@ -84,6 +90,29 @@ class Form::AccountBatch
end
end
def approve_remote!
accounts.find_each do |account|
approve_remote_account(account)
end
end
def approve_remote_domain!
domains = accounts.group_by(&:domain).pluck(0)
if (Setting.permit_new_account_domains || []).compact_blank.present?
list = ((Setting.permit_new_account_domains || []) + domains).compact_blank.uniq.join("\n")
Form::AdminSettings.new(permit_new_account_domains: list).save
end
Account.where(domain: domains, remote_pending: true).find_each do |account|
approve_remote_account(account)
end
end
def reject_remote!
accounts.find_each do |account|
reject_remote_account(account)
end
end
def suspend!
accounts.find_each do |account|
if account.user_pending?
@ -115,10 +144,21 @@ class Form::AccountBatch
AccountDeletionWorker.perform_async(account.id, { 'reserve_username' => false })
end
def reject_remote_account(account)
authorize(account, :reject_remote?)
log_action(:reject_remote, account)
account.reject_remote!
process_suspend(account)
end
def suspend_account(account)
authorize(account, :suspend?)
log_action(:suspend, account)
account.suspend!(origin: :local)
process_suspend(account)
end
def process_suspend(account)
account.strikes.create!(
account: current_account,
action: :suspend
@ -143,6 +183,12 @@ class Form::AccountBatch
account.user.approve!
end
def approve_remote_account(account)
authorize(account, :approve_remote?)
log_action(:approve_remote, account)
account.approve_remote!
end
def select_all_matching?
select_all_matching == '1'
end