From 8a78ae17391632092a213dfb5b96d8b9dd801160 Mon Sep 17 00:00:00 2001 From: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Date: Fri, 5 Jan 2024 10:36:59 +0200 Subject: [PATCH] fix: Add template id to workflows created from templates (no-changelog) (#8226) In #8088 template ID was added to workflow metadata, but it was missing from workflows that were created using the template credential setup. This fixes that. --- cypress/e2e/34-template-credentials-setup.cy.ts | 16 ++++++++++++++++ .../src/utils/templates/templateActions.ts | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/34-template-credentials-setup.cy.ts b/cypress/e2e/34-template-credentials-setup.cy.ts index a65e3a55b2c9b..a55f45d24e58d 100644 --- a/cypress/e2e/34-template-credentials-setup.cy.ts +++ b/cypress/e2e/34-template-credentials-setup.cy.ts @@ -106,6 +106,22 @@ describe('Template credentials setup', () => { cy.wait('@createWorkflow'); workflowPage.getters.canvasNodes().should('have.length', 3); + + // Focus the canvas so the copy to clipboard works + workflowPage.getters.canvasNodes().eq(0).realClick(); + workflowPage.actions.selectAll(); + workflowPage.actions.hitCopy(); + + cy.grantBrowserPermissions('clipboardReadWrite', 'clipboardSanitizedWrite'); + // Check workflow JSON by copying it to clipboard + cy.readClipboard().then((workflowJSON) => { + const workflow = JSON.parse(workflowJSON); + + expect(workflow.meta).to.haveOwnProperty('templateId', testTemplate.id.toString()); + workflow.nodes.forEach((node: any) => { + expect(Object.keys(node.credentials ?? {})).to.have.lengthOf(1); + }); + }); }); it('should work with a template that has no credentials (ADO-1603)', () => { diff --git a/packages/editor-ui/src/utils/templates/templateActions.ts b/packages/editor-ui/src/utils/templates/templateActions.ts index ec81a94744fc4..1d380b6015084 100644 --- a/packages/editor-ui/src/utils/templates/templateActions.ts +++ b/packages/editor-ui/src/utils/templates/templateActions.ts @@ -37,7 +37,10 @@ export async function createWorkflowFromTemplate(opts: { nodes, connections, active: false, - // Ignored: pinData, settings, tags, versionId, meta + meta: { + templateId: template.id.toString(), + }, + // Ignored: pinData, settings, tags, versionId }; const createdWorkflow = await workflowsStore.createNewWorkflow(workflowToCreate);