feat: make database.Chat auditable (#24485)

Wire database.Chat into the audit system so chat lifecycle events
(creation, patches, etc.) produce audit log entries.

Part of CODAGT-200.

> 🤖
This commit is contained in:
Cian Johnston
2026-04-21 11:11:56 +01:00
committed by GitHub
parent 5f3effd839
commit c968a1f3a3
18 changed files with 271 additions and 28 deletions
+14
View File
@@ -435,6 +435,16 @@ func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.Get
api.Logger.Error(ctx, "unable to fetch task", slog.Error(err))
}
return task.DeletedAt.Valid && task.DeletedAt.Time.Before(time.Now())
case database.ResourceTypeChat:
// Chats are hard-deleted, so a 404 means deleted.
_, err := api.Database.GetChatByID(ctx, alog.AuditLog.ResourceID)
if xerrors.Is(err, sql.ErrNoRows) {
return true
}
if err != nil {
api.Logger.Error(ctx, "unable to fetch chat", slog.Error(err))
}
return false
default:
return false
}
@@ -522,6 +532,10 @@ func (api *API) auditLogResourceLink(ctx context.Context, alog database.GetAudit
}
return fmt.Sprintf("/tasks/%s/%s", user.Username, task.ID)
case database.ResourceTypeChat:
// Chats are surfaced at /agents/{id}. They are owner-scoped but
// not username-scoped in the URL like workspaces or tasks.
return fmt.Sprintf("/agents/%s", alog.AuditLog.ResourceID)
default:
return ""
}