Reinstate action logging (#38211)
This commit is contained in:
@@ -46,6 +46,7 @@ class Admin::AccountAction < Admin::BaseAction
|
|||||||
ApplicationRecord.transaction do
|
ApplicationRecord.transaction do
|
||||||
handle_type!
|
handle_type!
|
||||||
process_strike!
|
process_strike!
|
||||||
|
create_log!
|
||||||
process_reports!
|
process_reports!
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -105,6 +106,12 @@ class Admin::AccountAction < Admin::BaseAction
|
|||||||
target_account.suspend!(origin: :local)
|
target_account.suspend!(origin: :local)
|
||||||
end
|
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
|
def text_for_warning
|
||||||
[warning_preset&.text, text].compact.join("\n\n")
|
[warning_preset&.text, text].compact.join("\n\n")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ RSpec.describe Admin::AccountAction do
|
|||||||
let(:account) { Fabricate(:admin_user).account }
|
let(:account) { Fabricate(:admin_user).account }
|
||||||
let(:target_account) { Fabricate(:account) }
|
let(:target_account) { Fabricate(:account) }
|
||||||
let(:type) { 'disable' }
|
let(:type) { 'disable' }
|
||||||
|
let(:text) { nil }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
account_action.assign_attributes(
|
account_action.assign_attributes(
|
||||||
type: type,
|
type: type,
|
||||||
current_account: account,
|
current_account: account,
|
||||||
target_account: target_account
|
target_account: target_account,
|
||||||
|
text:
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -53,6 +55,20 @@ RSpec.describe Admin::AccountAction do
|
|||||||
end
|
end
|
||||||
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
|
context 'when type is invalid' do
|
||||||
let(:type) { 'whatever' }
|
let(:type) { 'whatever' }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user