fix: capture user and ip details on Inbox delete (#7395)
Fixes: https://linear.app/chatwoot/issue/CW-1772/ip-address-and-user-details-are-missing-in-some-of-the-logs Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
@@ -287,6 +287,8 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
|
||||
it 'deletes inbox' do
|
||||
expect(DeleteObjectJob).to receive(:perform_later).with(inbox, admin, anything).once
|
||||
|
||||
perform_enqueued_jobs(only: DeleteObjectJob) do
|
||||
delete "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
|
||||
headers: admin.create_new_auth_token,
|
||||
|
||||
29
spec/enterprise/jobs/enterprise/delete_object_job_spec.rb
Normal file
29
spec/enterprise/jobs/enterprise/delete_object_job_spec.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DeleteObjectJob, type: :job do
|
||||
include ActiveJob::TestHelper
|
||||
subject(:job) { described_class.perform_later(account) }
|
||||
|
||||
let(:account) { create(:account) }
|
||||
let(:user) { create(:user) }
|
||||
let(:team) { create(:team, account: account) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
|
||||
context 'when an object is passed to the job with arguments' do
|
||||
it 'creates log with associated data if its an inbox' do
|
||||
described_class.perform_later(inbox, user, '127.0.0.1')
|
||||
perform_enqueued_jobs
|
||||
|
||||
audit_log = Audited::Audit.where(auditable_type: 'Inbox', action: 'destroy', username: user.uid, remote_address: '127.0.0.1').first
|
||||
expect(audit_log).to be_present
|
||||
expect(audit_log.audited_changes.keys).to include('id', 'name', 'account_id')
|
||||
expect { inbox.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it 'will not create logs for other objects' do
|
||||
described_class.perform_later(account, user, '127.0.0.1')
|
||||
perform_enqueued_jobs
|
||||
expect(Audited::Audit.where(auditable_type: 'Team', action: 'destroy').count).to eq 0
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -50,12 +50,5 @@ RSpec.describe Inbox do
|
||||
expect(Audited::Audit.where(auditable_type: 'Inbox', action: 'update').count).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'when inbox is deleted' do
|
||||
it 'has associated audit log created' do
|
||||
inbox.destroy!
|
||||
expect(Audited::Audit.where(auditable_type: 'Inbox', action: 'destroy').count).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user