fix(audit): filter count aliases outside the projection and clean identity detail

This commit is contained in:
sam committed 2026-10-25 23:00:44 +11:00
1 parent 79f3895923
commit 89bb4eb46b
2 files changed
+30 -20

No files matched your search

@@ -97,6 +97,7 @@ WITH sys_changes AS (
)
SELECT count(*)::bigint AS count
FROM (
SELECT category, action, kind, actor, target_kind, target_id, severity, outcome, search_text FROM (
SELECT
CASE t.table_name WHEN 'access_policies' THEN 'access' ELSE 'settings' END AS category,
CASE
@@ -154,15 +155,16 @@ FROM (
FROM sys_changes g
WHERE g.table_name IN ('resources', 'access_policies')
) t
WHERE (COALESCE(cardinality($1::text[]), 0) = 0 OR category = ANY($1::text[]))
AND (COALESCE(cardinality($2::text[]), 0) = 0 OR action = ANY($2::text[]))
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR kind = ANY($3::text[]))
AND ($4::text IS NULL OR actor = $4::text)
AND (COALESCE(cardinality($5::text[]), 0) = 0 OR target_kind = ANY($5::text[]))
AND (COALESCE(cardinality($6::text[]), 0) = 0 OR target_id = ANY($6::text[]))
AND (COALESCE(cardinality($7::text[]), 0) = 0 OR severity = ANY($7::text[]))
AND (COALESCE(cardinality($8::text[]), 0) = 0 OR outcome = ANY($8::text[]))
AND ($9::text IS NULL OR position(lower($9::text) IN lower(search_text)) > 0)
) s1
WHERE (COALESCE(cardinality($1::text[]), 0) = 0 OR s1.category = ANY($1::text[]))
AND (COALESCE(cardinality($2::text[]), 0) = 0 OR s1.action = ANY($2::text[]))
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR s1.kind = ANY($3::text[]))
AND ($4::text IS NULL OR s1.actor = $4::text)
AND (COALESCE(cardinality($5::text[]), 0) = 0 OR s1.target_kind = ANY($5::text[]))
AND (COALESCE(cardinality($6::text[]), 0) = 0 OR s1.target_id = ANY($6::text[]))
AND (COALESCE(cardinality($7::text[]), 0) = 0 OR s1.severity = ANY($7::text[]))
AND (COALESCE(cardinality($8::text[]), 0) = 0 OR s1.outcome = ANY($8::text[]))
AND ($9::text IS NULL OR position(lower($9::text) IN lower(s1.search_text)) > 0)
UNION ALL
SELECT
'identity'::text AS category,
@@ -591,7 +593,10 @@ SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principa
ie.event_type AS action,
CASE WHEN ie.event_type IN ('suspend', 'retire') THEN 'warning' ELSE 'info' END AS severity,
'success'::text AS outcome,
ie.from_lifecycle || ' → ' || ie.to_lifecycle AS detail,
CASE
WHEN ie.from_lifecycle = '' THEN ie.to_lifecycle
ELSE ie.from_lifecycle || ' → ' || ie.to_lifecycle
END AS detail,
concat_ws(' ', ie.identity_id, ie.event_type, ie.display_name, ie.actor_id, ie.source) AS search_text,
''::text AS workspace_id,
0::bigint AS task_id,