Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-23 04:02:09 +09:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Admin::AccountAction, type: :model do
|
2019-01-11 16:26:03 +09:00
|
|
|
let(:account_action) { described_class.new }
|
|
|
|
|
|
|
|
describe '#save!' do
|
|
|
|
subject { account_action.save! }
|
2022-07-05 09:41:40 +09:00
|
|
|
let(:account) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
|
2022-01-28 08:46:42 +09:00
|
|
|
let(:target_account) { Fabricate(:account) }
|
2019-01-11 16:26:03 +09:00
|
|
|
let(:type) { 'disable' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
account_action.assign_attributes(
|
|
|
|
type: type,
|
|
|
|
current_account: account,
|
|
|
|
target_account: target_account
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'type is "disable"' do
|
|
|
|
let(:type) { 'disable' }
|
|
|
|
|
|
|
|
it 'disable user' do
|
|
|
|
subject
|
|
|
|
expect(target_account.user).to be_disabled
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'type is "silence"' do
|
|
|
|
let(:type) { 'silence' }
|
|
|
|
|
|
|
|
it 'silences account' do
|
|
|
|
subject
|
|
|
|
expect(target_account).to be_silenced
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'type is "suspend"' do
|
|
|
|
let(:type) { 'suspend' }
|
|
|
|
|
|
|
|
it 'suspends account' do
|
|
|
|
subject
|
|
|
|
expect(target_account).to be_suspended
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'queues Admin::SuspensionWorker by 1' do
|
|
|
|
Sidekiq::Testing.fake! do
|
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.to change { Admin::SuspensionWorker.jobs.size }.by 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates Admin::ActionLog' do
|
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.to change { Admin::ActionLog.count }.by 1
|
|
|
|
end
|
|
|
|
|
2019-08-24 05:37:23 +09:00
|
|
|
it 'calls process_email!' do
|
|
|
|
expect(account_action).to receive(:process_email!)
|
2019-01-11 16:26:03 +09:00
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls process_reports!' do
|
|
|
|
expect(account_action).to receive(:process_reports!)
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#report' do
|
|
|
|
subject { account_action.report }
|
|
|
|
|
|
|
|
context 'report_id.present?' do
|
|
|
|
before do
|
|
|
|
account_action.report_id = Fabricate(:report).id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns Report' do
|
|
|
|
expect(subject).to be_instance_of Report
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '!report_id.present?' do
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#with_report?' do
|
|
|
|
subject { account_action.with_report? }
|
|
|
|
|
|
|
|
context '!report.nil?' do
|
|
|
|
before do
|
|
|
|
account_action.report_id = Fabricate(:report).id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(subject).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '!(!report.nil?)' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.types_for_account' do
|
|
|
|
subject { described_class.types_for_account(account) }
|
|
|
|
|
|
|
|
context 'account.local?' do
|
|
|
|
let(:account) { Fabricate(:account, domain: nil) }
|
|
|
|
|
2020-11-05 04:45:01 +09:00
|
|
|
it 'returns ["none", "disable", "sensitive", "silence", "suspend"]' do
|
|
|
|
expect(subject).to eq %w(none disable sensitive silence suspend)
|
2019-01-11 16:26:03 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '!account.local?' do
|
|
|
|
let(:account) { Fabricate(:account, domain: 'hoge.com') }
|
|
|
|
|
2020-11-05 04:45:01 +09:00
|
|
|
it 'returns ["sensitive", "silence", "suspend"]' do
|
|
|
|
expect(subject).to eq %w(sensitive silence suspend)
|
2019-01-11 16:26:03 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-23 04:02:09 +09:00
|
|
|
end
|