allow resuming as owner suspended job only for path owners

This commit is contained in:
Ruben Fiszel
2022-12-23 13:44:41 +01:00
parent 2d55abfc44
commit 12979223b5
2 changed files with 51 additions and 50 deletions

View File

@@ -2557,38 +2557,6 @@
},
"query": "UPDATE resource SET path = $1 WHERE path = $2 AND workspace_id = $3"
},
"853788436dbe987853433e8dc83665f68bd127de31d4c807abafeead896f6ac4": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "flow_status",
"ordinal": 1,
"type_info": "Jsonb"
},
{
"name": "suspend",
"ordinal": 2,
"type_info": "Int4"
}
],
"nullable": [
false,
true,
false
],
"parameters": {
"Left": [
"Uuid"
]
}
},
"query": "\n SELECT id, flow_status, suspend\n FROM queue\n WHERE id = ( SELECT parent_job FROM queue WHERE id = $1 UNION ALL SELECT parent_job FROM completed_job WHERE id = $1)\n FOR UPDATE\n "
},
"8543f029d9784234e4c6a6dcd7b03e62d544b98be261334ee210594e0bb839f2": {
"describe": {
"columns": [
@@ -4431,6 +4399,44 @@
},
"query": "UPDATE queue SET canceled = true WHERE id = $1"
},
"c75761c9aa900391251596771782039809bc01e4a0aa05701d6607b06769caa5": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "flow_status",
"ordinal": 1,
"type_info": "Jsonb"
},
{
"name": "suspend",
"ordinal": 2,
"type_info": "Int4"
},
{
"name": "script_path",
"ordinal": 3,
"type_info": "Varchar"
}
],
"nullable": [
false,
true,
false,
true
],
"parameters": {
"Left": [
"Uuid"
]
}
},
"query": "\n SELECT id, flow_status, suspend, script_path\n FROM queue\n WHERE id = ( SELECT parent_job FROM queue WHERE id = $1 UNION ALL SELECT parent_job FROM completed_job WHERE id = $1)\n FOR UPDATE\n "
},
"cac594031a21b4806de9c4616317d3541522ef9712a83ecff7bd8b5f6e870748": {
"describe": {
"columns": [],

View File

@@ -35,7 +35,7 @@ use windmill_queue::{get_queued_job, push, JobKind, JobPayload, QueuedJob, RawCo
use crate::{
db::{UserDB, DB},
users::Authed,
users::{require_owner_of_path, Authed},
variables::get_workspace_key,
BaseUrl,
};
@@ -466,6 +466,16 @@ pub async fn resume_suspended_job_as_owner(
let flow = get_suspended_flow_info(job_id, &mut tx).await?;
if !authed.is_admin {
require_owner_of_path(
&w_id,
&authed.username,
&authed.groups,
&flow.script_path.clone().unwrap_or_else(|| String::new()),
&db,
)
.await?;
}
insert_resume_job(0, job_id, &flow, value, Some(authed.username), &mut tx).await?;
resume_immediately_if_relevant(flow, job_id, &mut tx).await?;
@@ -580,6 +590,7 @@ struct FlowInfo {
id: Uuid,
flow_status: Option<serde_json::Value>,
suspend: i32,
script_path: Option<String>,
}
async fn get_suspended_flow_info<'c>(
@@ -589,7 +600,7 @@ async fn get_suspended_flow_info<'c>(
let flow = sqlx::query_as!(
FlowInfo,
r#"
SELECT id, flow_status, suspend
SELECT id, flow_status, suspend, script_path
FROM queue
WHERE id = ( SELECT parent_job FROM queue WHERE id = $1 UNION ALL SELECT parent_job FROM completed_job WHERE id = $1)
FOR UPDATE
@@ -1497,22 +1508,6 @@ async fn get_completed_job(
Ok(Json(job))
}
async fn get_flow_current_step_state(
Extension(db): Extension<DB>,
Path((w_id, id)): Path<(String, Uuid)>,
) -> error::JsonResult<String> {
let x = sqlx::query!(
"
SELECT (flow_status->'step')::integer as step, jsonb_array_length(flow_status->'modules') as len
FROM queue WHERE id = $1 AND workspace_id = $2",
id,
w_id
)
.fetch_optional(&db)
.await?;
Ok(Json(String::new()))
}
async fn get_completed_job_result(
Extension(db): Extension<DB>,
Path((w_id, id)): Path<(String, Uuid)>,