From 09e38981edd8750df8bbf65bb6a37d3fd74e499a Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 15 Dec 2022 16:00:59 +0100 Subject: [PATCH] add visible_to_owner --- ...20221215101605_share_job_to_owner.down.sql | 3 ++ .../20221215101605_share_job_to_owner.up.sql | 3 ++ backend/tests/worker.rs | 1 + backend/windmill-api/openapi.yaml | 31 +++++++++++++++++-- backend/windmill-api/src/apps.rs | 1 + backend/windmill-api/src/flows.rs | 2 ++ backend/windmill-api/src/jobs.rs | 15 +++++++++ backend/windmill-api/src/oauth2.rs | 1 + backend/windmill-api/src/scripts.rs | 1 + backend/windmill-queue/src/jobs.rs | 9 ++++-- backend/windmill-queue/src/schedule.rs | 1 + backend/windmill-worker/src/jobs.rs | 9 ++++-- backend/windmill-worker/src/worker.rs | 2 +- backend/windmill-worker/src/worker_flow.rs | 1 + .../pickers/WorkspaceScriptPicker.svelte | 3 ++ .../src/lib/components/home/ItemsList.svelte | 4 +++ frontend/src/routes/resources.svelte | 5 +++ frontend/src/routes/variables.svelte | 4 +++ 18 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 backend/migrations/20221215101605_share_job_to_owner.down.sql create mode 100644 backend/migrations/20221215101605_share_job_to_owner.up.sql diff --git a/backend/migrations/20221215101605_share_job_to_owner.down.sql b/backend/migrations/20221215101605_share_job_to_owner.down.sql new file mode 100644 index 0000000000..a23ec345aa --- /dev/null +++ b/backend/migrations/20221215101605_share_job_to_owner.down.sql @@ -0,0 +1,3 @@ +-- Add down migration script here +ALTER TABLE queue DROP COLUMN visible_to_owner; +ALTER TABLE completed_job DROP COLUMN visible_to_owner; \ No newline at end of file diff --git a/backend/migrations/20221215101605_share_job_to_owner.up.sql b/backend/migrations/20221215101605_share_job_to_owner.up.sql new file mode 100644 index 0000000000..a06405122b --- /dev/null +++ b/backend/migrations/20221215101605_share_job_to_owner.up.sql @@ -0,0 +1,3 @@ +-- Add up migration script here +ALTER TABLE queue ADD COLUMN visible_to_owner BOOLEAN DEFAULT true; +ALTER TABLE completed_job ADD COLUMN visible_to_owner BOOLEAN DEFAULT true; diff --git a/backend/tests/worker.rs b/backend/tests/worker.rs index c92f0edeb5..e841d0cb04 100644 --- a/backend/tests/worker.rs +++ b/backend/tests/worker.rs @@ -831,6 +831,7 @@ impl RunJob { /* is_flow_step */ false, /* running */ false, None, + true, ) .await .expect("push has to succeed"); diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 61e79e56c8..660fdcecd2 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -2175,7 +2175,11 @@ paths: schema: type: integer - $ref: "#/components/parameters/ParentJob" - + - name: invisible_to_owner + description: make the run invisible to the the script owner (default false) + in: query + schema: + type: boolean requestBody: description: script args required: true @@ -2653,6 +2657,11 @@ paths: type: integer - $ref: "#/components/parameters/ParentJob" - $ref: "#/components/parameters/IncludeHeader" + - name: invisible_to_owner + description: make the run invisible to the the flow owner (default false) + in: query + schema: + type: boolean requestBody: description: flow args @@ -2693,7 +2702,11 @@ paths: type: integer - $ref: "#/components/parameters/ParentJob" - $ref: "#/components/parameters/IncludeHeader" - + - name: invisible_to_owner + description: make the run invisible to the the script owner (default false) + in: query + schema: + type: boolean requestBody: description: Partially filled args required: true @@ -2720,7 +2733,11 @@ paths: parameters: - $ref: "#/components/parameters/WorkspaceId" - $ref: "#/components/parameters/IncludeHeader" - + - name: invisible_to_owner + description: make the run invisible to the the script owner (default false) + in: query + schema: + type: boolean requestBody: description: preview required: true @@ -2747,6 +2764,11 @@ paths: parameters: - $ref: "#/components/parameters/WorkspaceId" - $ref: "#/components/parameters/IncludeHeader" + - name: invisible_to_owner + description: make the run invisible to the the script owner (default false) + in: query + schema: + type: boolean requestBody: description: preview @@ -4215,6 +4237,8 @@ components: type: boolean email: type: string + visible_to_owner: + type: boolean required: - id - created_by @@ -4228,6 +4252,7 @@ components: - is_flow_step - is_skipped - email + - visible_to_owner Job: allOf: diff --git a/backend/windmill-api/src/apps.rs b/backend/windmill-api/src/apps.rs index 50321f730f..724b8f3d12 100644 --- a/backend/windmill-api/src/apps.rs +++ b/backend/windmill-api/src/apps.rs @@ -535,6 +535,7 @@ async fn execute_component( false, false, None, + true, ) .await?; diff --git a/backend/windmill-api/src/flows.rs b/backend/windmill-api/src/flows.rs index a485f5d2fe..a02e93b731 100644 --- a/backend/windmill-api/src/flows.rs +++ b/backend/windmill-api/src/flows.rs @@ -196,6 +196,7 @@ async fn create_flow( false, false, None, + true, ) .await?; sqlx::query!( @@ -302,6 +303,7 @@ async fn update_flow( false, false, None, + true, ) .await?; sqlx::query!( diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index 3827bc9e34..7fdb629e05 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -239,6 +239,7 @@ pub struct CompletedJob { pub language: Option, pub is_skipped: bool, pub email: String, + pub visible_to_owner: bool, } #[derive(Deserialize, Clone)] @@ -247,6 +248,7 @@ pub struct RunJobQuery { scheduled_in_secs: Option, parent_job: Option, include_header: Option, + invisible_to_owner: Option, } impl RunJobQuery { @@ -402,6 +404,7 @@ async fn list_jobs( "language", "false as is_skipped", "email", + "visible_to_owner", ], ); let sqlc = list_completed_jobs_query( @@ -435,6 +438,7 @@ async fn list_jobs( "language", "is_skipped", "email", + "visible_to_owner", ], ); let sql = format!( @@ -811,6 +815,7 @@ struct UnifiedJob { language: Option, is_skipped: bool, email: String, + visible_to_owner: bool, } impl From for Job { @@ -844,6 +849,7 @@ impl From for Job { language: uj.language, is_skipped: uj.is_skipped, email: uj.email, + visible_to_owner: uj.visible_to_owner, }), "QueuedJob" => Job::QueuedJob(QueuedJob { workspace_id: uj.workspace_id, @@ -874,6 +880,7 @@ impl From for Job { same_worker: false, pre_run_error: None, email: uj.email, + visible_to_owner: uj.visible_to_owner, }), t => panic!("job type {} not valid", t), } @@ -971,6 +978,7 @@ pub async fn run_flow_by_path( false, false, None, + !run_query.invisible_to_owner.unwrap_or(false), ) .await?; tx.commit().await?; @@ -1005,6 +1013,7 @@ pub async fn run_job_by_path( false, false, None, + !run_query.invisible_to_owner.unwrap_or(false), ) .await?; tx.commit().await?; @@ -1072,6 +1081,7 @@ pub async fn run_wait_result_job_by_path( false, false, None, + !run_query.invisible_to_owner.unwrap_or(false), ) .await?; tx.commit().await?; @@ -1107,6 +1117,7 @@ pub async fn run_wait_result_job_by_hash( false, false, None, + !run_query.invisible_to_owner.unwrap_or(false), ) .await?; tx.commit().await?; @@ -1160,6 +1171,7 @@ async fn run_preview_job( false, false, None, + true, ) .await?; tx.commit().await?; @@ -1192,6 +1204,7 @@ async fn run_preview_flow_job( false, false, None, + true, ) .await?; tx.commit().await?; @@ -1226,6 +1239,7 @@ pub async fn run_job_by_hash( false, false, None, + !run_query.invisible_to_owner.unwrap_or(false), ) .await?; tx.commit().await?; @@ -1398,6 +1412,7 @@ async fn list_completed_jobs( "language", "is_skipped", "email", + "visible_to_owner", ], ) .sql()?; diff --git a/backend/windmill-api/src/oauth2.rs b/backend/windmill-api/src/oauth2.rs index f5fa847b3b..5ac7aa5107 100644 --- a/backend/windmill-api/src/oauth2.rs +++ b/backend/windmill-api/src/oauth2.rs @@ -806,6 +806,7 @@ async fn slack_command( false, false, None, + true, ) .await?; tx.commit().await?; diff --git a/backend/windmill-api/src/scripts.rs b/backend/windmill-api/src/scripts.rs index c8a9572bf8..2a9f453928 100644 --- a/backend/windmill-api/src/scripts.rs +++ b/backend/windmill-api/src/scripts.rs @@ -343,6 +343,7 @@ async fn create_script( false, false, None, + true, ) .await?; tx diff --git a/backend/windmill-queue/src/jobs.rs b/backend/windmill-queue/src/jobs.rs index c39f6bd32f..181035ec13 100644 --- a/backend/windmill-queue/src/jobs.rs +++ b/backend/windmill-queue/src/jobs.rs @@ -254,6 +254,7 @@ pub async fn push<'c>( is_flow_step: bool, mut same_worker: bool, pre_run_error: Option<&windmill_common::error::Error>, + visible_to_owner: bool, ) -> Result<(Uuid, Transaction<'c, Postgres>), Error> { let scheduled_for = scheduled_for_o.unwrap_or_else(chrono::Utc::now); let args_json = serde_json::Value::Object(args); @@ -476,8 +477,8 @@ pub async fn push<'c>( "INSERT INTO queue (workspace_id, id, running, parent_job, created_by, permissioned_as, scheduled_for, script_hash, script_path, raw_code, raw_lock, args, job_kind, schedule_path, raw_flow, \ - flow_status, is_flow_step, language, started_at, same_worker, pre_run_error, email) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, CASE WHEN $3 THEN now() END, $19, $20, $21) \ + flow_status, is_flow_step, language, started_at, same_worker, pre_run_error, email, visible_to_owner) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, CASE WHEN $3 THEN now() END, $19, $20, $21, $22) \ RETURNING id", workspace_id, job_id, @@ -499,7 +500,8 @@ pub async fn push<'c>( language: ScriptLang, same_worker, pre_run_error.map(|e| e.to_string()), - email + email, + visible_to_owner ) .fetch_one(&mut tx) .await @@ -595,6 +597,7 @@ pub struct QueuedJob { pub same_worker: bool, pub pre_run_error: Option, pub email: String, + pub visible_to_owner: bool, } impl QueuedJob { diff --git a/backend/windmill-queue/src/schedule.rs b/backend/windmill-queue/src/schedule.rs index 86189e9542..3ed9205f37 100644 --- a/backend/windmill-queue/src/schedule.rs +++ b/backend/windmill-queue/src/schedule.rs @@ -116,6 +116,7 @@ pub async fn push_scheduled_job<'c>( false, false, None, + true, ) .await?; sqlx::query!( diff --git a/backend/windmill-worker/src/jobs.rs b/backend/windmill-worker/src/jobs.rs index 00f8afafe8..34b28001ca 100644 --- a/backend/windmill-worker/src/jobs.rs +++ b/backend/windmill-worker/src/jobs.rs @@ -127,9 +127,11 @@ pub async fn add_completed_job( , is_flow_step , is_skipped , language - , email ) + , email + , visible_to_owner + ) VALUES ($1, $2, $3, $4, $5, $6, COALESCE($26, EXTRACT(milliseconds FROM (now() - $6))), $7, $8, $9,\ - $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $27) + $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $27, $28) ON CONFLICT (id) DO UPDATE SET success = $7, result = $11, logs = concat(cj.logs, $12)", queued_job.workspace_id, queued_job.id, @@ -157,7 +159,8 @@ pub async fn add_completed_job( skipped, queued_job.language: ScriptLang, duration: Option, - queued_job.email + queued_job.email, + queued_job.visible_to_owner ) .execute(&mut tx) .await diff --git a/backend/windmill-worker/src/worker.rs b/backend/windmill-worker/src/worker.rs index bf1e5338ac..0bc6b5576c 100644 --- a/backend/windmill-worker/src/worker.rs +++ b/backend/windmill-worker/src/worker.rs @@ -2215,7 +2215,7 @@ async fn handle_child( r#" UPDATE queue SET canceled = true - , canceled_by = 'timeout', + , canceled_by = 'timeout' , canceled_reason = $1 WHERE id = $2 r"#, diff --git a/backend/windmill-worker/src/worker_flow.rs b/backend/windmill-worker/src/worker_flow.rs index 0254cc9e9a..4d6fa1589c 100644 --- a/backend/windmill-worker/src/worker_flow.rs +++ b/backend/windmill-worker/src/worker_flow.rs @@ -1241,6 +1241,7 @@ async fn push_next_flow_job( true, continue_on_same_worker, err, + flow_job.visible_to_owner, ) .await?; tx = inner_tx; diff --git a/frontend/src/lib/components/flows/pickers/WorkspaceScriptPicker.svelte b/frontend/src/lib/components/flows/pickers/WorkspaceScriptPicker.svelte index 797012f114..a167b538cc 100644 --- a/frontend/src/lib/components/flows/pickers/WorkspaceScriptPicker.svelte +++ b/frontend/src/lib/components/flows/pickers/WorkspaceScriptPicker.svelte @@ -33,6 +33,9 @@ } let ownerFilter: string | undefined = undefined + $: if ($workspaceStore) { + ownerFilter = undefined + } $: prefilteredItems = ownerFilter ? items?.filter((x) => x.path.startsWith(ownerFilter!)) : items $: owners = Array.from( diff --git a/frontend/src/lib/components/home/ItemsList.svelte b/frontend/src/lib/components/home/ItemsList.svelte index 8a28c6c058..bdacf5f056 100644 --- a/frontend/src/lib/components/home/ItemsList.svelte +++ b/frontend/src/lib/components/home/ItemsList.svelte @@ -129,6 +129,10 @@ let ownerFilter: string | undefined = undefined + $: if ($workspaceStore) { + ownerFilter = undefined + } + $: { if (($userStore || $superadmin) && $workspaceStore) { loadScripts() diff --git a/frontend/src/routes/resources.svelte b/frontend/src/routes/resources.svelte index 2345b60a6f..ed35c3c93a 100644 --- a/frontend/src/routes/resources.svelte +++ b/frontend/src/routes/resources.svelte @@ -89,6 +89,11 @@ let filter = '' let ownerFilter: string | undefined = undefined + + $: if ($workspaceStore) { + ownerFilter = undefined + } + let typeFilter: string | undefined = undefined $: preFilteredItemsOwners = diff --git a/frontend/src/routes/variables.svelte b/frontend/src/routes/variables.svelte index e7ef060d2c..5ac9dc0752 100644 --- a/frontend/src/routes/variables.svelte +++ b/frontend/src/routes/variables.svelte @@ -60,6 +60,10 @@ let ownerFilter: string | undefined = undefined + $: if ($workspaceStore) { + ownerFilter = undefined + } + $: preFilteredItems = ownerFilter == undefined ? variables