Add missing action logging to `api/v1/admin/reports#update` (#29044)

pull/2647/head
Matt Jankowski 2024-02-06 06:34:11 -05:00 committed by GitHub
parent a31427a629
commit 4cf07ed78c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 5 deletions

View File

@ -35,6 +35,7 @@ class Api::V1::Admin::ReportsController < Api::BaseController
def update
authorize @report, :update?
@report.update!(report_params)
log_action :update, @report
render json: @report, serializer: REST::Admin::ReportSerializer
end

View File

@ -58,6 +58,7 @@ describe Admin::ReportsController do
report.reload
expect(report.action_taken_by_account).to eq user.account
expect(report.action_taken?).to be true
expect(last_action_log.target).to eq(report)
end
end
@ -70,6 +71,7 @@ describe Admin::ReportsController do
report.reload
expect(report.action_taken_by_account).to be_nil
expect(report.action_taken?).to be false
expect(last_action_log.target).to eq(report)
end
end
@ -81,6 +83,7 @@ describe Admin::ReportsController do
expect(response).to redirect_to(admin_report_path(report))
report.reload
expect(report.assigned_account).to eq user.account
expect(last_action_log.target).to eq(report)
end
end
@ -92,6 +95,13 @@ describe Admin::ReportsController do
expect(response).to redirect_to(admin_report_path(report))
report.reload
expect(report.assigned_account).to be_nil
expect(last_action_log.target).to eq(report)
end
end
private
def last_action_log
Admin::ActionLog.last
end
end

View File

@ -151,7 +151,9 @@ RSpec.describe 'Reports' do
let(:params) { { category: 'spam' } }
it 'updates the report category', :aggregate_failures do
expect { subject }.to change { report.reload.category }.from('other').to('spam')
expect { subject }
.to change { report.reload.category }.from('other').to('spam')
.and create_an_action_log
expect(response).to have_http_status(200)
@ -184,7 +186,9 @@ RSpec.describe 'Reports' do
it_behaves_like 'forbidden for wrong role', ''
it 'marks report as resolved', :aggregate_failures do
expect { subject }.to change { report.reload.unresolved? }.from(true).to(false)
expect { subject }
.to change { report.reload.unresolved? }.from(true).to(false)
.and create_an_action_log
expect(response).to have_http_status(200)
end
end
@ -200,7 +204,9 @@ RSpec.describe 'Reports' do
it_behaves_like 'forbidden for wrong role', ''
it 'marks report as unresolved', :aggregate_failures do
expect { subject }.to change { report.reload.unresolved? }.from(false).to(true)
expect { subject }
.to change { report.reload.unresolved? }.from(false).to(true)
.and create_an_action_log
expect(response).to have_http_status(200)
end
end
@ -216,7 +222,9 @@ RSpec.describe 'Reports' do
it_behaves_like 'forbidden for wrong role', ''
it 'assigns report to the requesting user', :aggregate_failures do
expect { subject }.to change { report.reload.assigned_account_id }.from(nil).to(user.account.id)
expect { subject }
.to change { report.reload.assigned_account_id }.from(nil).to(user.account.id)
.and create_an_action_log
expect(response).to have_http_status(200)
end
end
@ -232,8 +240,16 @@ RSpec.describe 'Reports' do
it_behaves_like 'forbidden for wrong role', ''
it 'unassigns report from assignee', :aggregate_failures do
expect { subject }.to change { report.reload.assigned_account_id }.from(user.account.id).to(nil)
expect { subject }
.to change { report.reload.assigned_account_id }.from(user.account.id).to(nil)
.and create_an_action_log
expect(response).to have_http_status(200)
end
end
private
def create_an_action_log
change(Admin::ActionLog, :count).by(1)
end
end