Skip to content

Use Auditor and add event type for project scheduled to be deleted due to inactivity

Description

Replace the use of AuditEventService with Gitlab::Audit::Auditor here and add a meaningful audit event type name for this event.

Proposal

Test if the below patch works. Compare the audit event created before and after this change. Also, verify that the new event is also streamed with the correct attributes.

diff --git a/ee/app/workers/ee/projects/inactive_projects_deletion_cron_worker.rb b/ee/app/workers/ee/projects/inactive_projects_deletion_cron_worker.rb
index 2964ccfa818b..6bb1cefd2ff2 100644
--- a/ee/app/workers/ee/projects/inactive_projects_deletion_cron_worker.rb
+++ b/ee/app/workers/ee/projects/inactive_projects_deletion_cron_worker.rb
@@ -26,12 +26,15 @@ def send_deletion_warning_email?(deletion_warning_email_sent_on, project)
       def send_notification(project, user)
         super

-        ::AuditEventService.new(
-          user,
-          project,
-          action: :custom,
-          custom_message: "Project is scheduled to be deleted on #{deletion_date} due to inactivity."
-        ).for_project.security_event
+        audit_context = {
+          name: 'inactive_project_scheduled_for_deletion',
+          author: user,
+          scope: project,
+          target: project,
+          message: "Project is scheduled to be deleted on #{deletion_date} due to inactivity."
+        }
+
+        ::Gitlab::Audit::Auditor.audit(audit_context)
       end
     end
   end
Edited by Huzaifa Iftikhar