Add notifications for statuses deleted by moderators (#17204)
This commit is contained in:
parent
d5c9feb7b7
commit
14f436c457
59 changed files with 1220 additions and 598 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Fabricator(:report) do
|
||||
account
|
||||
target_account { Fabricate(:account) }
|
||||
comment "You nasty"
|
||||
action_taken false
|
||||
target_account { Fabricate(:account) }
|
||||
comment "You nasty"
|
||||
action_taken_at nil
|
||||
end
|
||||
|
|
|
@ -79,7 +79,7 @@ class UserMailerPreview < ActionMailer::Preview
|
|||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/warning
|
||||
def warning
|
||||
UserMailer.warning(User.first, AccountWarning.new(text: '', action: :silence), [Status.first.id])
|
||||
UserMailer.warning(User.first, AccountWarning.last)
|
||||
end
|
||||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/sign_in_token
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Form::StatusBatch do
|
||||
let(:form) { Form::StatusBatch.new(action: action, status_ids: status_ids) }
|
||||
let(:status) { Fabricate(:status) }
|
||||
|
||||
describe 'with nsfw action' do
|
||||
let(:status_ids) { [status.id, nonsensitive_status.id, sensitive_status.id] }
|
||||
let(:nonsensitive_status) { Fabricate(:status, sensitive: false) }
|
||||
let(:sensitive_status) { Fabricate(:status, sensitive: true) }
|
||||
let!(:shown_media_attachment) { Fabricate(:media_attachment, status: nonsensitive_status) }
|
||||
let!(:hidden_media_attachment) { Fabricate(:media_attachment, status: sensitive_status) }
|
||||
|
||||
context 'nsfw_on' do
|
||||
let(:action) { 'nsfw_on' }
|
||||
|
||||
it { expect(form.save).to be true }
|
||||
it { expect { form.save }.to change { nonsensitive_status.reload.sensitive }.from(false).to(true) }
|
||||
it { expect { form.save }.not_to change { sensitive_status.reload.sensitive } }
|
||||
it { expect { form.save }.not_to change { status.reload.sensitive } }
|
||||
end
|
||||
|
||||
context 'nsfw_off' do
|
||||
let(:action) { 'nsfw_off' }
|
||||
|
||||
it { expect(form.save).to be true }
|
||||
it { expect { form.save }.to change { sensitive_status.reload.sensitive }.from(true).to(false) }
|
||||
it { expect { form.save }.not_to change { nonsensitive_status.reload.sensitive } }
|
||||
it { expect { form.save }.not_to change { status.reload.sensitive } }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with delete action' do
|
||||
let(:status_ids) { [status.id] }
|
||||
let(:action) { 'delete' }
|
||||
let!(:another_status) { Fabricate(:status) }
|
||||
|
||||
before do
|
||||
allow(RemovalWorker).to receive(:perform_async)
|
||||
end
|
||||
|
||||
it 'call RemovalWorker' do
|
||||
form.save
|
||||
expect(RemovalWorker).to have_received(:perform_async).with(status.id, immediate: true)
|
||||
end
|
||||
|
||||
it 'do not call RemovalWorker' do
|
||||
form.save
|
||||
expect(RemovalWorker).not_to have_received(:perform_async).with(another_status.id, immediate: true)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -54,7 +54,7 @@ describe Report do
|
|||
end
|
||||
|
||||
describe 'resolve!' do
|
||||
subject(:report) { Fabricate(:report, action_taken: false, action_taken_by_account_id: nil) }
|
||||
subject(:report) { Fabricate(:report, action_taken_at: nil, action_taken_by_account_id: nil) }
|
||||
|
||||
let(:acting_account) { Fabricate(:account) }
|
||||
|
||||
|
@ -63,12 +63,13 @@ describe Report do
|
|||
end
|
||||
|
||||
it 'records action taken' do
|
||||
expect(report).to have_attributes(action_taken: true, action_taken_by_account_id: acting_account.id)
|
||||
expect(report.action_taken?).to be true
|
||||
expect(report.action_taken_by_account_id).to eq acting_account.id
|
||||
end
|
||||
end
|
||||
|
||||
describe 'unresolve!' do
|
||||
subject(:report) { Fabricate(:report, action_taken: true, action_taken_by_account_id: acting_account.id) }
|
||||
subject(:report) { Fabricate(:report, action_taken_at: Time.now.utc, action_taken_by_account_id: acting_account.id) }
|
||||
|
||||
let(:acting_account) { Fabricate(:account) }
|
||||
|
||||
|
@ -77,23 +78,24 @@ describe Report do
|
|||
end
|
||||
|
||||
it 'unresolves' do
|
||||
expect(report).to have_attributes(action_taken: false, action_taken_by_account_id: nil)
|
||||
expect(report.action_taken?).to be false
|
||||
expect(report.action_taken_by_account_id).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'unresolved?' do
|
||||
subject { report.unresolved? }
|
||||
|
||||
let(:report) { Fabricate(:report, action_taken: action_taken) }
|
||||
let(:report) { Fabricate(:report, action_taken_at: action_taken) }
|
||||
|
||||
context 'if action is taken' do
|
||||
let(:action_taken) { true }
|
||||
let(:action_taken) { Time.now.utc }
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
|
||||
context 'if action not is taken' do
|
||||
let(:action_taken) { false }
|
||||
let(:action_taken) { nil }
|
||||
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue