2023-02-21 19:55:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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-22 14:02:09 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-03 23:49:53 -04:00
|
|
|
RSpec.describe Admin::AccountAction do
|
2019-01-11 02:26:03 -05:00
|
|
|
let(:account_action) { described_class.new }
|
|
|
|
|
|
|
|
describe '#save!' do
|
|
|
|
subject { account_action.save! }
|
2023-02-19 20:46:00 -05:00
|
|
|
|
2022-07-04 20:41:40 -04:00
|
|
|
let(:account) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
|
2022-01-27 18:46:42 -05:00
|
|
|
let(:target_account) { Fabricate(:account) }
|
2019-01-11 02:26:03 -05:00
|
|
|
let(:type) { 'disable' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
account_action.assign_attributes(
|
2023-02-20 00:58:28 -05:00
|
|
|
type: type,
|
2019-01-11 02:26:03 -05:00
|
|
|
current_account: account,
|
2023-02-20 00:58:28 -05:00
|
|
|
target_account: target_account
|
2019-01-11 02:26:03 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'when type is "disable"' do
|
2019-01-11 02:26:03 -05:00
|
|
|
let(:type) { 'disable' }
|
|
|
|
|
|
|
|
it 'disable user' do
|
|
|
|
subject
|
|
|
|
expect(target_account.user).to be_disabled
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'when type is "silence"' do
|
2019-01-11 02:26:03 -05:00
|
|
|
let(:type) { 'silence' }
|
|
|
|
|
|
|
|
it 'silences account' do
|
|
|
|
subject
|
|
|
|
expect(target_account).to be_silenced
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'when type is "suspend"' do
|
2019-01-11 02:26:03 -05:00
|
|
|
let(:type) { 'suspend' }
|
|
|
|
|
|
|
|
it 'suspends account' do
|
|
|
|
subject
|
|
|
|
expect(target_account).to be_suspended
|
|
|
|
end
|
|
|
|
|
2024-01-10 06:06:58 -05:00
|
|
|
it 'queues Admin::SuspensionWorker by 1' do
|
2023-11-23 04:43:43 -05:00
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.to change { Admin::SuspensionWorker.jobs.size }.by 1
|
2019-01-11 02:26:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-14 09:21:36 -04:00
|
|
|
context 'when type is invalid' do
|
|
|
|
let(:type) { 'whatever' }
|
|
|
|
|
|
|
|
it 'raises an invalid record error' do
|
|
|
|
expect { subject }.to raise_error(ActiveRecord::RecordInvalid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when type is not given' do
|
|
|
|
let(:type) { '' }
|
|
|
|
|
|
|
|
it 'raises an invalid record error' do
|
|
|
|
expect { subject }.to raise_error(ActiveRecord::RecordInvalid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-11 02:26:03 -05:00
|
|
|
it 'creates Admin::ActionLog' do
|
|
|
|
expect do
|
|
|
|
subject
|
2023-05-24 05:23:40 -04:00
|
|
|
end.to change(Admin::ActionLog, :count).by 1
|
2019-01-11 02:26:03 -05:00
|
|
|
end
|
|
|
|
|
2019-08-23 16:37:23 -04:00
|
|
|
it 'calls process_email!' do
|
2023-11-07 04:46:28 -05:00
|
|
|
allow(account_action).to receive(:process_email!)
|
2019-01-11 02:26:03 -05:00
|
|
|
subject
|
2023-11-07 04:46:28 -05:00
|
|
|
expect(account_action).to have_received(:process_email!)
|
2019-01-11 02:26:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls process_reports!' do
|
2023-11-07 04:46:28 -05:00
|
|
|
allow(account_action).to receive(:process_reports!)
|
2019-01-11 02:26:03 -05:00
|
|
|
subject
|
2023-11-07 04:46:28 -05:00
|
|
|
expect(account_action).to have_received(:process_reports!)
|
2019-01-11 02:26:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#report' do
|
|
|
|
subject { account_action.report }
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'with report_id.present?' do
|
2019-01-11 02:26:03 -05:00
|
|
|
before do
|
|
|
|
account_action.report_id = Fabricate(:report).id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns Report' do
|
|
|
|
expect(subject).to be_instance_of Report
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'with !report_id.present?' do
|
2019-01-11 02:26:03 -05:00
|
|
|
it 'returns nil' do
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#with_report?' do
|
|
|
|
subject { account_action.with_report? }
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'with !report.nil?' do
|
2019-01-11 02:26:03 -05:00
|
|
|
before do
|
|
|
|
account_action.report_id = Fabricate(:report).id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(subject).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'with !(!report.nil?)' do
|
2019-01-11 02:26:03 -05:00
|
|
|
it 'returns false' do
|
|
|
|
expect(subject).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.types_for_account' do
|
|
|
|
subject { described_class.types_for_account(account) }
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'when Account.local?' do
|
2019-01-11 02:26:03 -05:00
|
|
|
let(:account) { Fabricate(:account, domain: nil) }
|
|
|
|
|
2020-11-04 14:45:01 -05:00
|
|
|
it 'returns ["none", "disable", "sensitive", "silence", "suspend"]' do
|
|
|
|
expect(subject).to eq %w(none disable sensitive silence suspend)
|
2019-01-11 02:26:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'with !account.local?' do
|
2019-01-11 02:26:03 -05:00
|
|
|
let(:account) { Fabricate(:account, domain: 'hoge.com') }
|
|
|
|
|
2020-11-04 14:45:01 -05:00
|
|
|
it 'returns ["sensitive", "silence", "suspend"]' do
|
|
|
|
expect(subject).to eq %w(sensitive silence suspend)
|
2019-01-11 02:26:03 -05: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-22 14:02:09 -05:00
|
|
|
end
|