Commit 9cf33bc7 authored by Tan Le's avatar Tan Le

Fix incorrect ordering of audit events

The audit events should be built and persisted in the same order as when
they are emitted in the event queue. This bug only affects audit events
recorded for MR approval rule changes (i.e. add/remove approvers and
approval groups). Even that, this bug is not noticeable and causes any
major gap since users always make all these changes together when adding
or creating new MR approval rules.

Changelog: fixed
parent 835b633a
---
title: Fix incorrect ordering of audit events on MR approval changes
merge_request: 60508
author:
type: fixed
......@@ -50,7 +50,7 @@ module Gitlab
private
def record
events = ::Gitlab::Audit::EventQueue.current.reverse.map(&method(:build_event))
events = ::Gitlab::Audit::EventQueue.current.map { |message| build_event(message) }
log_to_database(events)
log_to_file(events)
......
......@@ -34,9 +34,9 @@ RSpec.describe Gitlab::Audit::Auditor do
end
it 'records audit events in correct order', :aggregate_failures do
expect { auditor.audit(context, &operation) }.to change { AuditEvent.count }.by(2)
expect { auditor.audit(context, &operation) }.to change(AuditEvent, :count).by(2)
event_messages = AuditEvent.all.order(created_at: :desc).map { |event| event.details[:custom_message] }
event_messages = AuditEvent.all.map { |event| event.details[:custom_message] }
expect(event_messages).to eq([add_message, remove_message])
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment