Skip to content

Commit

Permalink
cancel / close behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
alpetric committed Dec 31, 2024
1 parent 5b00fa2 commit 718512c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions backend/windmill-api/src/slack_approvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ struct PrivateMetadata {
resume_url: String,
resource_path: String,
container: Container,
hide_cancel: Option<bool>,
}

pub async fn slack_app_callback_handler(
Expand Down Expand Up @@ -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<w_id>[^/]+)/jobs_u/(?P<action>resume|cancel)/(?P<job_id>[^/]+)/(?P<resume_id>[^/]+)/(?P<secret>[a-fA-F0-9]+)(?:\?approver=(?P<approver>[^&]+))?").unwrap();
Expand Down Expand Up @@ -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| {
Expand All @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 718512c

Please sign in to comment.