From 810136a4a405855801c94de66ec8916979701c67 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 27 Mar 2024 14:03:53 +0100 Subject: [PATCH] feat: approval steps description --- backend/windmill-common/src/flows.rs | 2 + .../src/lib/components/DisplayResult.svelte | 15 +++-- .../FlowStatusWaitingForEvents.svelte | 6 ++ .../flows/content/FlowModuleSuspend.svelte | 7 +++ frontend/src/lib/script_helpers.ts | 56 ++++++++++++++++--- .../[job]/[resume]/[hmac]/+page.svelte | 26 ++++++--- openflow.openapi.yaml | 2 + 7 files changed, 93 insertions(+), 21 deletions(-) diff --git a/backend/windmill-common/src/flows.rs b/backend/windmill-common/src/flows.rs index c9b990d280..0c25a921ef 100644 --- a/backend/windmill-common/src/flows.rs +++ b/backend/windmill-common/src/flows.rs @@ -203,6 +203,8 @@ pub struct Suspend { pub user_groups_required: Option, #[serde(skip_serializing_if = "Option::is_none")] pub self_approval_disabled: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub hide_cancel: Option, } #[derive(Deserialize, Serialize, Debug, Clone)] diff --git a/frontend/src/lib/components/DisplayResult.svelte b/frontend/src/lib/components/DisplayResult.svelte index 34e9fdfe1f..0f35dcfbb2 100644 --- a/frontend/src/lib/components/DisplayResult.svelte +++ b/frontend/src/lib/components/DisplayResult.svelte @@ -34,6 +34,7 @@ export let jobId: string | undefined = undefined export let workspaceId: string | undefined = undefined export let hideAsJson: boolean = false + export let noControls: boolean = false let resultKind: | 'json' @@ -288,7 +289,7 @@
- {#if !disableExpand} + {#if !disableExpand && !noControls} @@ -542,11 +543,13 @@ {/if} {:else if typeof result == 'string' && result.length > 0}
{result}
-
- -
+ {#if !noControls} +
+ +
+ {/if} {:else}

Waiting to be resumed

+ {#if description != undefined} + + {/if}
{#if isOwner || resumeUrl}
diff --git a/frontend/src/lib/components/flows/content/FlowModuleSuspend.svelte b/frontend/src/lib/components/flows/content/FlowModuleSuspend.svelte index 391752c854..6cfe3c63fe 100644 --- a/frontend/src/lib/components/flows/content/FlowModuleSuspend.svelte +++ b/frontend/src/lib/components/flows/content/FlowModuleSuspend.svelte @@ -221,6 +221,13 @@
{/if} {#if flowModule.suspend?.resume_form} + {/if}
diff --git a/frontend/src/lib/script_helpers.ts b/frontend/src/lib/script_helpers.ts index 8b383875ab..2d0fe93b40 100644 --- a/frontend/src/lib/script_helpers.ts +++ b/frontend/src/lib/script_helpers.ts @@ -277,22 +277,62 @@ func main() (interface{}, error) { export const DENO_INIT_CODE_APPROVAL = `import * as wmill from "npm:windmill-client@^1.158.2" export async function main(approver?: string) { - return wmill.getResumeUrls(approver) + const urls = await wmill.getResumeUrls(approver) + // send the urls to their intended recipients + + + // if the resumeUrls are part of the response, they will be available to any persons having access + // to the run page and allowed to be approved from there, even from non owners of the flow + // self-approval is disablable in the suspend options + return { + ...urls, + default_args: {}, + enums: {}, + description: undefined + } +}` + +export const BUN_INIT_CODE_APPROVAL = `import * as wmill from "windmill-client@^1.158.2" + +export async function main(approver?: string) { + const urls = await wmill.getResumeUrls(approver) + // send the urls to their intended recipients + + + // if the resumeUrls are part of the response, they will be available to any persons having access + // to the run page and allowed to be approved from there, even from non owners of the flow + // self-approval is disablable in the suspend options + return { + ...urls, + default_args: {}, + enums: {}, + description: undefined + // supports all formats from rich display rendering such as simple strings, + // but also markdown, html, images, tables, maps, render_all, etc... + // https://www.windmill.dev/docs/core_concepts/rich_display_rendering + } }` export const PYTHON_INIT_CODE_APPROVAL = `import wmill def main(): urls = wmill.get_resume_urls() - return urls + # send the urls to their intended recipients + + # if the get_resume_urls are part of the response, they will be available to any persons having access + # to the run page and allowed to be approved from there, even from non owners of the flow + # self-approval is disablable in the suspend options + return { + **urls, + "default_args": {}, + "enums": {}, + "description": None, + # supports all formats from rich display rendering such as simple strings, + # but also markdown, html, images, tables, maps, render_all, etc... + # https://www.windmill.dev/docs/core_concepts/rich_display_rendering + } ` -export const BUN_INIT_CODE_APPROVAL = `import * as wmill from "windmill-client@^1.158.2" - -export async function main(approver?: string) { - return wmill.getResumeUrls(approver) -}` - export const DOCKER_INIT_CODE = `# shellcheck shell=bash # Bash script that calls docker as a client to the host daemon # See documentation: https://www.windmill.dev/docs/advanced/docker diff --git a/frontend/src/routes/approve/[workspace]/[job]/[resume]/[hmac]/+page.svelte b/frontend/src/routes/approve/[workspace]/[job]/[resume]/[hmac]/+page.svelte index 0949ec8edf..84eb382ab8 100644 --- a/frontend/src/routes/approve/[workspace]/[job]/[resume]/[hmac]/+page.svelte +++ b/frontend/src/routes/approve/[workspace]/[job]/[resume]/[hmac]/+page.svelte @@ -17,6 +17,7 @@ import { Alert } from '$lib/components/common' import { getUserExt } from '$lib/user' import { setLicense } from '$lib/enterpriseUtils' + import DisplayResult from '$lib/components/DisplayResult.svelte' $workspaceStore = $page.params.workspace let rd = $page.url.href.replace($page.url.origin, '') @@ -37,6 +38,7 @@ let error: string | undefined = undefined let default_payload: any = {} let enum_payload: object = {} + let description: any = undefined setLicense() @@ -80,6 +82,7 @@ workspace: job?.workspace_id ?? '', id: jobId }) + description = job_result?.description default_payload = job_result?.default_args ?? {} enum_payload = job_result?.enums ?? {} } @@ -203,6 +206,10 @@

You have already approved this flow to be resumed

{/if} + {#if description != undefined} + + {/if} + {#if schema} {#if emptyString($enterpriseLicense)} @@ -217,13 +224,18 @@ {/if}
- + {#if !job?.raw_flow?.modules?.[approvalStep]?.suspend?.hide_cancel} + + {:else} +
+ {/if} +