fix: move token origins on workspace rename and keep links in the run's workspace

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-12-02 14:22:06 +01:00
co-authored by Claude Opus 5.5
parent fb1442b9ef
commit 79af4ec74b
3 changed files with 38 additions and 6 deletions
@@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "UPDATE job_token SET workspace_id = $1\n WHERE workspace_id = $2 AND job_id IN (SELECT id FROM v2_job WHERE workspace_id = $1)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": []
},
"hash": "e58e1182efcb756c465ae98a09828052085b812a22ec8057fb002aab429a0b3f"
}
@@ -791,6 +791,15 @@ pub(crate) async fn change_workspace_id(
.execute(&mut *tx)
.await?;
sqlx::query!(
"UPDATE job_token SET workspace_id = $1
WHERE workspace_id = $2 AND job_id IN (SELECT id FROM v2_job WHERE workspace_id = $1)",
&rw.new_id,
&old_id
)
.execute(&mut *tx)
.await?;
info!("Updating raw_app table");
sqlx::query!(
"UPDATE raw_app SET workspace_id = $1 WHERE workspace_id = $2",
@@ -161,13 +161,19 @@ export function getTriggerInfo(job: Job): { type: string; icon: any; detail?: st
}
/** The page of the trigger or app that started the job, when it has one. */
export function getTriggerHref(job: Job): string | null {
export function getTriggerHref(job: Job, workspaceId: string): string | null {
const path = job.trigger_path
const kind = job.trigger_kind
if (!path || !kind) return null
if (kind === 'app') return `/apps/get/${path}`
const workspace = `workspace=${encodeURIComponent(job.workspace_id || workspaceId)}`
if (kind === 'app') return `/apps/get/${path}?${workspace}`
if (kind in TRIGGER_PAGES) {
return pageItemPageHref({ kind: 'trigger', triggerKind: kind as TriggerKind, path })
const [page, hash] = pageItemPageHref({
kind: 'trigger',
triggerKind: kind as TriggerKind,
path
}).split('#')
return `${page}?${workspace}#${hash}`
}
return null
}
@@ -223,7 +229,7 @@ export const fieldConfigs: Record<JobField, FieldConfig> = {
const triggerInfo = getTriggerInfo(job)
return triggerInfo ? triggerInfo.type : null
},
getHref: (job) => getTriggerHref(job)
getHref: (job, workspaceId) => getTriggerHref(job, workspaceId)
},
token: {
@@ -234,8 +240,10 @@ export const fieldConfigs: Record<JobField, FieldConfig> = {
const label = job.token_label === 'session' ? 'Session' : job.token_label
return `${job.token_prefix}****${label ? ` (${label})` : ''}`
},
getHref: (job) =>
job.token_prefix ? `${AUDIT_LOGS_PATH}?token=${encodeURIComponent(job.token_prefix)}` : null
getHref: (job, workspaceId) =>
job.token_prefix
? `${AUDIT_LOGS_PATH}?token=${encodeURIComponent(job.token_prefix)}&workspace=${encodeURIComponent(job.workspace_id || workspaceId)}`
: null
},
parent_job: {