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
This commit is contained in:
@ -191,58 +191,6 @@ RSpec.describe Admin::AccountsController, type: :controller do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #disable' do
|
||||
subject { post :disable, params: { id: account.id } }
|
||||
|
||||
let(:current_user) { Fabricate(:user, admin: current_user_admin) }
|
||||
let(:account) { Fabricate(:account, user: user) }
|
||||
let(:user) { Fabricate(:user, disabled: false, admin: target_user_admin) }
|
||||
|
||||
context 'when user is admin' do
|
||||
let(:current_user_admin) { true }
|
||||
|
||||
context 'when target user is admin' do
|
||||
let(:target_user_admin) { true }
|
||||
|
||||
it 'fails to disable account' do
|
||||
is_expected.to have_http_status :forbidden
|
||||
expect(user.reload).not_to be_disabled
|
||||
end
|
||||
end
|
||||
|
||||
context 'when target user is not admin' do
|
||||
let(:target_user_admin) { false }
|
||||
|
||||
it 'succeeds in disabling account' do
|
||||
is_expected.to redirect_to admin_account_path(account.id)
|
||||
expect(user.reload).to be_disabled
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is not admin' do
|
||||
let(:current_user_admin) { false }
|
||||
|
||||
context 'when target user is admin' do
|
||||
let(:target_user_admin) { true }
|
||||
|
||||
it 'fails to disable account' do
|
||||
is_expected.to have_http_status :forbidden
|
||||
expect(user.reload).not_to be_disabled
|
||||
end
|
||||
end
|
||||
|
||||
context 'when target user is not admin' do
|
||||
let(:target_user_admin) { false }
|
||||
|
||||
it 'fails to disable account' do
|
||||
is_expected.to have_http_status :forbidden
|
||||
expect(user.reload).not_to be_disabled
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #redownload' do
|
||||
subject { post :redownload, params: { id: account.id } }
|
||||
|
||||
|
@ -46,73 +46,37 @@ describe Admin::ReportsController do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
describe 'with an unknown outcome' do
|
||||
it 'rejects the change' do
|
||||
report = Fabricate(:report)
|
||||
put :update, params: { id: report, outcome: 'unknown' }
|
||||
describe 'POST #reopen' do
|
||||
it 'reopens the report' do
|
||||
report = Fabricate(:report)
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
put :reopen, params: { id: report }
|
||||
expect(response).to redirect_to(admin_report_path(report))
|
||||
report.reload
|
||||
expect(report.action_taken_by_account).to eq nil
|
||||
expect(report.action_taken).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an outcome of `resolve`' do
|
||||
it 'resolves the report' do
|
||||
report = Fabricate(:report)
|
||||
describe 'POST #assign_to_self' do
|
||||
it 'reopens the report' do
|
||||
report = Fabricate(:report)
|
||||
|
||||
put :update, params: { id: report, outcome: 'resolve' }
|
||||
expect(response).to redirect_to(admin_reports_path)
|
||||
report.reload
|
||||
expect(report.action_taken_by_account).to eq user.account
|
||||
expect(report.action_taken).to eq true
|
||||
end
|
||||
put :assign_to_self, params: { id: report }
|
||||
expect(response).to redirect_to(admin_report_path(report))
|
||||
report.reload
|
||||
expect(report.assigned_account).to eq user.account
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an outsome of `silence`' do
|
||||
it 'silences the reported account' do
|
||||
report = Fabricate(:report)
|
||||
describe 'POST #unassign' do
|
||||
it 'reopens the report' do
|
||||
report = Fabricate(:report)
|
||||
|
||||
put :update, params: { id: report, outcome: 'silence' }
|
||||
expect(response).to redirect_to(admin_reports_path)
|
||||
report.reload
|
||||
expect(report.action_taken_by_account).to eq user.account
|
||||
expect(report.action_taken).to eq true
|
||||
expect(report.target_account).to be_silenced
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an outsome of `reopen`' do
|
||||
it 'reopens the report' do
|
||||
report = Fabricate(:report)
|
||||
|
||||
put :update, params: { id: report, outcome: 'reopen' }
|
||||
expect(response).to redirect_to(admin_report_path(report))
|
||||
report.reload
|
||||
expect(report.action_taken_by_account).to eq nil
|
||||
expect(report.action_taken).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an outsome of `assign_to_self`' do
|
||||
it 'reopens the report' do
|
||||
report = Fabricate(:report)
|
||||
|
||||
put :update, params: { id: report, outcome: 'assign_to_self' }
|
||||
expect(response).to redirect_to(admin_report_path(report))
|
||||
report.reload
|
||||
expect(report.assigned_account).to eq user.account
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an outsome of `unassign`' do
|
||||
it 'reopens the report' do
|
||||
report = Fabricate(:report)
|
||||
|
||||
put :update, params: { id: report, outcome: 'unassign' }
|
||||
expect(response).to redirect_to(admin_report_path(report))
|
||||
report.reload
|
||||
expect(report.assigned_account).to eq nil
|
||||
end
|
||||
put :unassign, params: { id: report }
|
||||
expect(response).to redirect_to(admin_report_path(report))
|
||||
report.reload
|
||||
expect(report.assigned_account).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,33 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::SilencesController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'redirects to admin accounts page' do
|
||||
account = Fabricate(:account, silenced: false)
|
||||
|
||||
post :create, params: { account_id: account.id }
|
||||
|
||||
account.reload
|
||||
expect(account.silenced?).to eq true
|
||||
expect(response).to redirect_to(admin_accounts_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
it 'redirects to admin accounts page' do
|
||||
account = Fabricate(:account, silenced: true)
|
||||
|
||||
delete :destroy, params: { account_id: account.id }
|
||||
|
||||
account.reload
|
||||
expect(account.silenced?).to eq false
|
||||
expect(response).to redirect_to(admin_accounts_path)
|
||||
end
|
||||
end
|
||||
end
|
@ -1,39 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::SuspensionsController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'returns 200' do
|
||||
get :new, params: { account_id: Fabricate(:account).id, report_id: Fabricate(:report).id }
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'redirects to admin accounts page' do
|
||||
account = Fabricate(:account, suspended: false)
|
||||
expect(Admin::SuspensionWorker).to receive(:perform_async).with(account.id)
|
||||
|
||||
post :create, params: { account_id: account.id, form_admin_suspension_confirmation: { acct: account.acct } }
|
||||
|
||||
expect(response).to redirect_to(admin_accounts_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
it 'redirects to admin accounts page' do
|
||||
account = Fabricate(:account, suspended: true)
|
||||
|
||||
delete :destroy, params: { account_id: account.id }
|
||||
|
||||
account.reload
|
||||
expect(account.suspended?).to eq false
|
||||
expect(response).to redirect_to(admin_accounts_path)
|
||||
end
|
||||
end
|
||||
end
|
5
spec/fabricators/account_warning_fabricator.rb
Normal file
5
spec/fabricators/account_warning_fabricator.rb
Normal file
@ -0,0 +1,5 @@
|
||||
Fabricator(:account_warning) do
|
||||
account nil
|
||||
target_account nil
|
||||
text "MyText"
|
||||
end
|
3
spec/fabricators/account_warning_preset_fabricator.rb
Normal file
3
spec/fabricators/account_warning_preset_fabricator.rb
Normal file
@ -0,0 +1,3 @@
|
||||
Fabricator(:account_warning_preset) do
|
||||
text "MyText"
|
||||
end
|
@ -39,4 +39,9 @@ class UserMailerPreview < ActionMailer::Preview
|
||||
def backup_ready
|
||||
UserMailer.backup_ready(User.first, Backup.first)
|
||||
end
|
||||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/warning
|
||||
def warning
|
||||
UserMailer.warning(User.first, AccountWarning.new(text: '', action: :silence))
|
||||
end
|
||||
end
|
||||
|
5
spec/models/account_warning_preset_spec.rb
Normal file
5
spec/models/account_warning_preset_spec.rb
Normal file
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountWarningPreset, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
5
spec/models/account_warning_spec.rb
Normal file
5
spec/models/account_warning_spec.rb
Normal file
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountWarning, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
4
spec/models/admin/account_action_spec.rb
Normal file
4
spec/models/admin/account_action_spec.rb
Normal file
@ -0,0 +1,4 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::AccountAction, type: :model do
|
||||
end
|
Reference in New Issue
Block a user