Fix nil author in organization transfer audit event

What does this MR do and why?

RootGroupOrganizationBackfillWorker transfers a top-level group into a newly created organization without an acting user. After a successful transfer, the EE override logs an audit event with author: current_user, which is nil on this path. AuditEvents::BuildService#initialize rejects a blank author and raises MissingAttributeError, failing the Sidekiq job.

This MR falls back to ::Gitlab::Audit::UnauthenticatedAuthor.new(name: '(System)') when there is no acting user — the established pattern used across ~10 other EE audit-logging services (for example ee/app/services/ee/members/create_service.rb).

Why it only failed on the backfill path

The two UI-driven callers always have a non-nil author by the time the audit fires:

  • GroupsController passes the logged-in current_user.
  • ConfirmService requires current_user&.can?(...) and errors out before the transfer if the user is nil.

The backfill worker is the only path that both bypasses authorization (so a nil user is not caught) and has no user to begin with. The audit also only fires on a successful transfer, so backfill runs that bail out earlier (path collision, group validation) never reach the audit line — which is why only a subset of runs crashed.

How to set up and validate locally

bundle exec rspec ee/spec/services/ee/organizations/transfer/top_level_group_service_spec.rb

A spec context covering the system-initiated (nil user) path was added: it asserts the system author is used and the audit event is created.

Resolves #628761 (closed)

Merge request reports

Loading
Loading