0
0
Fork 0

Add notifications for statuses deleted by moderators (#17204)

This commit is contained in:
Eugen Rochko 2022-01-17 09:41:33 +01:00 committed by GitHub
parent d5c9feb7b7
commit 14f436c457
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 1220 additions and 598 deletions

View file

@ -12,11 +12,11 @@ describe Admin::ReportNotesController do
describe 'POST #create' do
subject { post :create, params: params }
let(:report) { Fabricate(:report, action_taken: action_taken, action_taken_by_account_id: account_id) }
let(:report) { Fabricate(:report, action_taken_at: action_taken, action_taken_by_account_id: account_id) }
context 'when parameter is valid' do
context 'when report is unsolved' do
let(:action_taken) { false }
let(:action_taken) { nil }
let(:account_id) { nil }
context 'when create_and_resolve flag is on' do
@ -41,7 +41,7 @@ describe Admin::ReportNotesController do
end
context 'when report is resolved' do
let(:action_taken) { true }
let(:action_taken) { Time.now.utc }
let(:account_id) { user.account.id }
context 'when create_and_unresolve flag is on' do
@ -68,7 +68,7 @@ describe Admin::ReportNotesController do
context 'when parameter is invalid' do
let(:params) { { report_note: { content: '', report_id: report.id } } }
let(:action_taken) { false }
let(:action_taken) { nil }
let(:account_id) { nil }
it 'renders admin/reports/show' do

View file

@ -1,59 +0,0 @@
require 'rails_helper'
describe Admin::ReportedStatusesController do
render_views
let(:user) { Fabricate(:user, admin: true) }
let(:report) { Fabricate(:report, status_ids: [status.id]) }
let(:status) { Fabricate(:status) }
before do
sign_in user, scope: :user
end
describe 'POST #create' do
subject do
-> { post :create, params: { :report_id => report, action => '', :form_status_batch => { status_ids: status_ids } } }
end
let(:action) { 'nsfw_on' }
let(:status_ids) { [status.id] }
let(:status) { Fabricate(:status, sensitive: !sensitive) }
let(:sensitive) { true }
let!(:media_attachment) { Fabricate(:media_attachment, status: status) }
context 'when action is nsfw_on' do
it 'updates sensitive column' do
is_expected.to change {
status.reload.sensitive
}.from(false).to(true)
end
end
context 'when action is nsfw_off' do
let(:action) { 'nsfw_off' }
let(:sensitive) { false }
it 'updates sensitive column' do
is_expected.to change {
status.reload.sensitive
}.from(true).to(false)
end
end
context 'when action is delete' do
let(:action) { 'delete' }
it 'removes a status' do
allow(RemovalWorker).to receive(:perform_async)
subject.call
expect(RemovalWorker).to have_received(:perform_async).with(status_ids.first, immediate: true)
end
end
it 'redirects to report page' do
subject.call
expect(response).to redirect_to(admin_report_path(report))
end
end
end

View file

@ -10,8 +10,8 @@ describe Admin::ReportsController do
describe 'GET #index' do
it 'returns http success with no filters' do
specified = Fabricate(:report, action_taken: false)
Fabricate(:report, action_taken: true)
specified = Fabricate(:report, action_taken_at: nil)
Fabricate(:report, action_taken_at: Time.now.utc)
get :index
@ -22,10 +22,10 @@ describe Admin::ReportsController do
end
it 'returns http success with resolved filter' do
specified = Fabricate(:report, action_taken: true)
Fabricate(:report, action_taken: false)
specified = Fabricate(:report, action_taken_at: Time.now.utc)
Fabricate(:report, action_taken_at: nil)
get :index, params: { resolved: 1 }
get :index, params: { resolved: '1' }
reports = assigns(:reports).to_a
expect(reports.size).to eq 1
@ -54,15 +54,7 @@ describe Admin::ReportsController do
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
it 'sets trust level when the report is an antispam one' do
report = Fabricate(:report, account: Account.representative)
put :resolve, params: { id: report }
report.reload
expect(report.target_account.trust_level).to eq Account::TRUST_LEVELS[:trusted]
expect(report.action_taken?).to eq true
end
end
@ -74,7 +66,7 @@ describe Admin::ReportsController do
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
expect(report.action_taken?).to eq false
end
end

View file

@ -18,65 +18,46 @@ describe Admin::StatusesController do
end
describe 'GET #index' do
it 'returns http success with no media' do
get :index, params: { account_id: account.id }
context do
before do
get :index, params: { account_id: account.id }
end
statuses = assigns(:statuses).to_a
expect(statuses.size).to eq 4
expect(statuses.first.id).to eq last_status.id
expect(response).to have_http_status(200)
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
it 'returns http success with media' do
get :index, params: { account_id: account.id, media: true }
context 'filtering by media' do
before do
get :index, params: { account_id: account.id, media: '1' }
end
statuses = assigns(:statuses).to_a
expect(statuses.size).to eq 2
expect(statuses.first.id).to eq last_media_attached_status.id
expect(response).to have_http_status(200)
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
end
describe 'POST #create' do
subject do
-> { post :create, params: { :account_id => account.id, action => '', :form_status_batch => { status_ids: status_ids } } }
describe 'POST #batch' do
before do
post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } }
end
let(:action) { 'nsfw_on' }
let(:status_ids) { [media_attached_status.id] }
context 'when action is nsfw_on' do
it 'updates sensitive column' do
is_expected.to change {
media_attached_status.reload.sensitive
}.from(false).to(true)
context 'when action is report' do
let(:action) { 'report' }
it 'creates a report' do
report = Report.last
expect(report.target_account_id).to eq account.id
expect(report.status_ids).to eq status_ids
end
end
context 'when action is nsfw_off' do
let(:action) { 'nsfw_off' }
let(:sensitive) { false }
it 'updates sensitive column' do
is_expected.to change {
media_attached_status.reload.sensitive
}.from(true).to(false)
it 'redirects to report page' do
expect(response).to redirect_to(admin_report_path(Report.last.id))
end
end
context 'when action is delete' do
let(:action) { 'delete' }
it 'removes a status' do
allow(RemovalWorker).to receive(:perform_async)
subject.call
expect(RemovalWorker).to have_received(:perform_async).with(status_ids.first, immediate: true)
end
end
it 'redirects to account statuses page' do
subject.call
expect(response).to redirect_to(admin_account_statuses_path(account.id))
end
end
end