diff --git a/app/models/admin/account_action.rb b/app/models/admin/account_action.rb index eed17c9a87..e132571da0 100644 --- a/app/models/admin/account_action.rb +++ b/app/models/admin/account_action.rb @@ -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 diff --git a/spec/models/admin/account_action_spec.rb b/spec/models/admin/account_action_spec.rb index 6032594850..f25ddd6fe4 100644 --- a/spec/models/admin/account_action_spec.rb +++ b/spec/models/admin/account_action_spec.rb @@ -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' }