fix(api): enforce AuditAction enum and structured metadata on audit logs - #474
Open
irefavor15-dotcom wants to merge 1 commit into
Open
fix(api): enforce AuditAction enum and structured metadata on audit logs#474irefavor15-dotcom wants to merge 1 commit into
irefavor15-dotcom wants to merge 1 commit into
Conversation
…ogs (XStreamRollz#326) - Add AuditAction enum (api/src/audit/audit-action.enum.ts) covering all existing action strings used across auth and interceptor callers - Update AuditService.log() signature to accept AuditAction + metadata Record so variable data (email, reason) is stored in a separate JSONB column instead of embedded in the action string - Update all callers in AuthService and AuditInterceptor to pass enum values and structured metadata objects - Add migration: widen action column to VARCHAR(255), add metadata JSONB column (NOT NULL DEFAULT '{}'), and CREATE INDEX on action for efficient filtering and aggregation Closes XStreamRollz#326
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #326
AuditService.log()previously accepted a free-formaction: string, which callers used to embed dynamic data (email addresses, reasons) directly into the action value. This made theactioncolumn impossible to index or aggregate meaningfully, and prevented querying for specific event types.Changes
api/src/audit/audit-action.enum.ts(new)Introduces an
AuditActionenum covering every action string used across the codebase:api/src/audit/audit.service.tsUpdated
log()signature:Variable data (email, reason, username) now goes into a separate
metadataJSONB column instead of being embedded in the action string.api/src/auth/auth.service.tsAll 6
auditService.log()calls updated to use enum values with structured metadata, e.g.:api/src/audit/audit.interceptor.tsSENSITIVE_ACTIONSmap typed asRecord<string, AuditAction>; interceptor passes{}as metadata (no body context available at interceptor level).Database migration
database/migrations/2026072801_add_audit_log_metadata_and_index.up.sql:actioncolumn toVARCHAR(255)metadata JSONB NOT NULL DEFAULT '{}'idx_audit_logs_actionviaCREATE INDEX CONCURRENTLYRollback:
2026072801_add_audit_log_metadata_and_index.down.sqlTesting