Filter orders before pagination and expose recorded decisions and result links

This commit is contained in:
2026-11-18 09:07:28 +01:00
parent 973e131c86
commit c0754f1d0d
6 changed files with 122 additions and 7 deletions
+10 -1
View File
@@ -240,7 +240,16 @@ pub async fn detail(
item["recent_jobs"] = if p.permits_scope("operations:read")
&& crate::permissions::allowed(&mut tx, &p.name, "operations:read").await?
{
sqlx::query_scalar::<_,Value>("SELECT jsonb_build_object('job_id',j.job_id,'operation_id',j.operation_id,'state',j.state,'created_at',r.created_at) FROM jobs j JOIN approval_requests r USING(tenant_id,operation_id) WHERE j.tenant_id=$1 AND j.asset_id=$2 AND j.agent_id=$3 ORDER BY r.created_at DESC,j.job_id LIMIT 20")
sqlx::query_scalar::<_, Value>(
"SELECT jsonb_build_object(
'job_id', j.job_id, 'operation_id', j.operation_id, 'state', j.state, 'created_at', r.created_at,
'title', coalesce(nullif(plan_view.payload#>>'{script_revision,name}', ''), nullif(btrim(plan_view.payload->>'reason'), '')),
'action', convert_from(j.payload, 'UTF8')::jsonb#>>'{action,action}')
FROM jobs j JOIN approval_requests r USING (tenant_id, operation_id)
JOIN operation_plans p USING (tenant_id, plan_id)
CROSS JOIN LATERAL (SELECT convert_from(p.payload, 'UTF8')::jsonb AS payload) AS plan_view
WHERE j.tenant_id=$1 AND j.asset_id=$2 AND j.agent_id=$3
ORDER BY r.created_at DESC, j.job_id LIMIT 20")
.bind(tenant).bind(asset).bind(row.get::<Uuid,_>("agent_id")).fetch_all(&mut *tx).await?.into()
} else {
Value::Null