FIX: log warning when context is missing when a user is destroyed (#12182)

This commit is contained in:
Arpit Jalan 2021-02-23 16:47:54 +05:30 committed by GitHub
parent 1844bde57c
commit 73fa4263fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -93,6 +93,7 @@ class UserDestroyer
deleted_by = @actor
end
StaffActionLogger.new(deleted_by).log_user_deletion(user, opts.slice(:context))
Rails.logger.warn("User destroyed without context from: #{caller_locations(14, 1)[0]}") if opts.slice(:context).blank?
end
MessageBus.publish "/logout", result.id, user_ids: [result.id]
end

View File

@ -85,6 +85,15 @@ describe UserDestroyer do
end
end
context 'context is missing' do
it "logs warning message if context is missing" do
messages = track_log_messages(level: Logger::WARN) do
UserDestroyer.new(admin).destroy(user)
end
expect(messages[0][2]).to include("User destroyed without context from:")
end
end
context "with a reviewable post" do
let!(:reviewable) { Fabricate(:reviewable, created_by: user) }