From 718512ca04a1000a39623440338b9928a393cb64 Mon Sep 17 00:00:00 2001 From: Alexander Petric Date: Tue, 31 Dec 2024 17:54:59 +0100 Subject: [PATCH] cancel / close behavior --- backend/windmill-api/src/slack_approvals.rs | 23 +++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/windmill-api/src/slack_approvals.rs b/backend/windmill-api/src/slack_approvals.rs index 89894c51960ac..bba141dc29d56 100644 --- a/backend/windmill-api/src/slack_approvals.rs +++ b/backend/windmill-api/src/slack_approvals.rs @@ -180,6 +180,7 @@ struct PrivateMetadata { resume_url: String, resource_path: String, container: Container, + hide_cancel: Option, } pub async fn slack_app_callback_handler( @@ -354,6 +355,12 @@ async fn handle_submission( let resume_url = private_metadata.resume_url; let resource_path = private_metadata.resource_path; let container: Container = private_metadata.container; + let hide_cancel = private_metadata.hide_cancel; + + // If hide_cancel is true, we don't need to extract information from the private_metadata + if hide_cancel.unwrap_or(false) && action == "cancel" { + return Ok(()); + } // Use regex to extract information from private_metadata let re = Regex::new(r"/api/w/(?P[^/]+)/jobs_u/(?Presume|cancel)/(?P[^/]+)/(?P[^/]+)/(?P[a-fA-F0-9]+)(?:\?approver=(?P[^&]+))?").unwrap(); @@ -1026,13 +1033,21 @@ async fn get_modal_blocks( *Flow ID*: {parent_job_id_str}\n\n" ); - let message_str: &str = message.unwrap_or_else(|| fallback_message.as_str()); + let mut message_str: String = message.unwrap_or_else(|| fallback_message.as_str()).to_string(); tracing::debug!("Schema: {:#?}", schema); if let Some(resume_schema) = schema { let hide_cancel = resume_schema.hide_cancel.unwrap_or(false); + // if hide cancel is false add note to message + if !hide_cancel { + message_str.push_str("\n\n*NOTE*: closing this modal will cancel the workflow.\n\n"); + } + + // Convert message_str back to &str when needed + let message_str_ref: &str = &message_str; + if let Some(schema_obj) = resume_schema.resume_form { let inner_schema: ResumeSchema = serde_json::from_value(schema_obj.clone()).map_err(|e| { @@ -1044,7 +1059,7 @@ async fn get_modal_blocks( })?; let blocks = transform_schemas( - message_str, + message_str_ref, Some(&inner_schema.schema.properties), &urls, Some(&inner_schema.schema.order), @@ -1066,7 +1081,7 @@ async fn get_modal_blocks( } else { tracing::debug!("No suspend form found!"); let blocks = transform_schemas( - message_str, + message_str_ref, None, &urls, None, @@ -1112,7 +1127,7 @@ fn construct_payload( "type": "plain_text", "text": "Resume Workflow" }, - "private_metadata": serde_json::json!({ "resume_url": resume_url, "resource_path": resource_path, "container": container }).to_string(), + "private_metadata": serde_json::json!({ "resume_url": resume_url, "resource_path": resource_path, "container": container, "hide_cancel": hide_cancel }).to_string(), }); if !hide_cancel {