Reinstate action logging (#38211)

This commit is contained in:
David Roetzel
2026-03-16 09:42:06 +01:00
committed by GitHub
parent f561014aa8
commit 2f989c780a
2 changed files with 24 additions and 1 deletions

View File

@@ -46,6 +46,7 @@ class Admin::AccountAction < Admin::BaseAction
ApplicationRecord.transaction do
handle_type!
process_strike!
create_log!
process_reports!
end
@@ -105,6 +106,12 @@ class Admin::AccountAction < Admin::BaseAction
target_account.suspend!(origin: :local)
end
def create_log!
# A log entry is only interesting if the warning contains
# custom text from someone. Otherwise it's just noise.
log_action(:create, @warning) if @warning&.text.present? && type == 'none'
end
def text_for_warning
[warning_preset&.text, text].compact.join("\n\n")
end

View File

@@ -11,12 +11,14 @@ RSpec.describe Admin::AccountAction do
let(:account) { Fabricate(:admin_user).account }
let(:target_account) { Fabricate(:account) }
let(:type) { 'disable' }
let(:text) { nil }
before do
account_action.assign_attributes(
type: type,
current_account: account,
target_account: target_account
target_account: target_account,
text:
)
end
@@ -53,6 +55,20 @@ RSpec.describe Admin::AccountAction do
end
end
context 'when type is `none`' do
let(:type) { 'none' }
context 'when a custom text is given' do
let(:text) { 'custom' }
it 'logs the action' do
expect { subject }.to change(Admin::ActionLog, :count).by(1)
expect(Admin::ActionLog.last.target.text).to eq 'custom'
end
end
end
context 'when type is invalid' do
let(:type) { 'whatever' }