diff --git a/backend/.sqlx/query-495377c3f9388f8967407dffda71cc5d3fbf38ac14ec5d4a4d61c6df8a5e8884.json b/backend/.sqlx/query-495377c3f9388f8967407dffda71cc5d3fbf38ac14ec5d4a4d61c6df8a5e8884.json deleted file mode 100644 index 18caed0fa8..0000000000 --- a/backend/.sqlx/query-495377c3f9388f8967407dffda71cc5d3fbf38ac14ec5d4a4d61c6df8a5e8884.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT jt.token_prefix, (SELECT label FROM token WHERE token_prefix = jt.token_prefix LIMIT 1) AS label\n FROM job_token jt WHERE jt.job_id = $1", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "token_prefix", - "type_info": "Varchar" - }, - { - "ordinal": 1, - "name": "label", - "type_info": "Varchar" - } - ], - "parameters": { - "Left": [ - "Uuid" - ] - }, - "nullable": [ - false, - null - ] - }, - "hash": "495377c3f9388f8967407dffda71cc5d3fbf38ac14ec5d4a4d61c6df8a5e8884" -} diff --git a/backend/.sqlx/query-52849bedd8963374d05a5557607913be1d331af1fc2b1cb4995a09e3b3b962bb.json b/backend/.sqlx/query-52849bedd8963374d05a5557607913be1d331af1fc2b1cb4995a09e3b3b962bb.json new file mode 100644 index 0000000000..0f1649ae2d --- /dev/null +++ b/backend/.sqlx/query-52849bedd8963374d05a5557607913be1d331af1fc2b1cb4995a09e3b3b962bb.json @@ -0,0 +1,34 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT jt.token_prefix, t.label, u.username AS \"owner?\"\n FROM job_token jt\n LEFT JOIN token t ON t.token_prefix = jt.token_prefix\n LEFT JOIN usr u ON u.workspace_id = jt.workspace_id AND u.email = t.email\n WHERE jt.job_id = $1\n LIMIT 1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "token_prefix", + "type_info": "Varchar" + }, + { + "ordinal": 1, + "name": "label", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "owner?", + "type_info": "Varchar" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false, + true, + false + ] + }, + "hash": "52849bedd8963374d05a5557607913be1d331af1fc2b1cb4995a09e3b3b962bb" +} diff --git a/backend/windmill-api-sse/src/lib.rs b/backend/windmill-api-sse/src/lib.rs index bd93382e63..6009a590e9 100644 --- a/backend/windmill-api-sse/src/lib.rs +++ b/backend/windmill-api-sse/src/lib.rs @@ -54,6 +54,9 @@ pub struct JobExtended { #[sqlx(skip)] #[serde(skip_serializing_if = "Option::is_none")] pub token_label: Option, + #[sqlx(skip)] + #[serde(skip_serializing_if = "Option::is_none")] + pub token_owner: Option, } pub trait JobCommon { @@ -88,6 +91,7 @@ impl JobExtended { aggregate_wait_time_ms, token_prefix: None, token_label: None, + token_owner: None, } } } @@ -272,18 +276,26 @@ impl Job { db: &sqlx::Pool, ) -> Result<(), sqlx::Error> { let r = sqlx::query!( - "SELECT jt.token_prefix, (SELECT label FROM token WHERE token_prefix = jt.token_prefix LIMIT 1) AS label - FROM job_token jt WHERE jt.job_id = $1", + "SELECT jt.token_prefix, t.label, u.username AS \"owner?\" + FROM job_token jt + LEFT JOIN token t ON t.token_prefix = jt.token_prefix + LEFT JOIN usr u ON u.workspace_id = jt.workspace_id AND u.email = t.email + WHERE jt.job_id = $1 + LIMIT 1", self.id() ) .fetch_optional(db) .await?; - let (prefix, label) = r - .map(|x| (Some(x.token_prefix), x.label)) + let (prefix, label, owner) = r + .map(|x| (Some(x.token_prefix), x.label, x.owner)) .unwrap_or_default(); match self { - Job::QueuedJob(job) => (job.token_prefix, job.token_label) = (prefix, label), - Job::CompletedJob(job) => (job.token_prefix, job.token_label) = (prefix, label), + Job::QueuedJob(job) => { + (job.token_prefix, job.token_label, job.token_owner) = (prefix, label, owner) + } + Job::CompletedJob(job) => { + (job.token_prefix, job.token_label, job.token_owner) = (prefix, label, owner) + } } Ok(()) } diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 631e2627d0..18107b0905 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -33967,6 +33967,9 @@ components: token_label: type: string description: Label of that token, while it still exists + token_owner: + type: string + description: Workspace username of that token's owner, while the token and the user still exist worker: type: string required: @@ -34124,6 +34127,9 @@ components: token_label: type: string description: Label of that token, while it still exists + token_owner: + type: string + description: Workspace username of that token's owner, while the token and the user still exist worker: type: string required: diff --git a/frontend/src/lib/components/JobLoader.svelte b/frontend/src/lib/components/JobLoader.svelte index 7fe1273454..1fd1acd430 100644 --- a/frontend/src/lib/components/JobLoader.svelte +++ b/frontend/src/lib/components/JobLoader.svelte @@ -459,6 +459,7 @@ njob.raw_flow = job?.raw_flow ?? njob.raw_flow njob.token_prefix ??= job?.token_prefix njob.token_label ??= job?.token_label + njob.token_owner ??= job?.token_owner job = njob await onJobCompleted(testId, job, callbacks) } @@ -896,6 +897,7 @@ // Only the single-job GET carries the token that started the run. njob.token_prefix ??= job?.token_prefix njob.token_label ??= job?.token_label + njob.token_owner ??= job?.token_owner job = njob onJobCompleted(id, job, callbacks) } diff --git a/frontend/src/lib/components/runs/JobDetailFieldConfig.ts b/frontend/src/lib/components/runs/JobDetailFieldConfig.ts index 21c17afad9..4ab1398355 100644 --- a/frontend/src/lib/components/runs/JobDetailFieldConfig.ts +++ b/frontend/src/lib/components/runs/JobDetailFieldConfig.ts @@ -243,7 +243,8 @@ export const fieldConfigs: Record = { getValue: (job) => { if (!job.token_prefix) return null const label = job.token_label === 'session' ? 'Session' : job.token_label - return `${job.token_prefix}****${label ? ` (${label})` : ''}` + const owner = job.token_owner ? `, owned by ${job.token_owner}` : '' + return `${job.token_prefix}****${label ? ` (${label})` : ''}${owner}` }, getHref: (job, workspaceId) => job.token_prefix