mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(n8n Form Node): Redirection update (no-changelog) (#13104)
Co-authored-by: Dana <152518854+dana-gill@users.noreply.github.com>
This commit is contained in:
@@ -243,7 +243,7 @@ export class Form extends Node {
|
||||
{
|
||||
name: 'default',
|
||||
httpMethod: 'POST',
|
||||
responseMode: 'onReceived',
|
||||
responseMode: 'responseNode',
|
||||
path: '',
|
||||
restartWebhook: true,
|
||||
isFullPath: true,
|
||||
@@ -384,6 +384,13 @@ export class Form extends Node {
|
||||
const waitTill = configureWaitTillDate(context, 'root');
|
||||
await context.putExecutionToWait(waitTill);
|
||||
|
||||
context.sendResponse({
|
||||
headers: {
|
||||
location: context.evaluateExpression('{{ $execution.resumeFormUrl }}', 0),
|
||||
},
|
||||
statusCode: 307,
|
||||
});
|
||||
|
||||
return [context.getInputData()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,6 @@ export const renderFormCompletion = async (
|
||||
const options = context.getNodeParameter('options', {}) as { formTitle: string };
|
||||
const responseText = context.getNodeParameter('responseText', '') as string;
|
||||
|
||||
if (redirectUrl) {
|
||||
res.send(
|
||||
`<html><head><meta http-equiv="refresh" content="0; url=${redirectUrl}"></head></html>`,
|
||||
);
|
||||
return { noWebhookResponse: true };
|
||||
}
|
||||
|
||||
let title = options.formTitle;
|
||||
if (!title) {
|
||||
title = context.evaluateExpression(`{{ $('${trigger?.name}').params.formTitle }}`) as string;
|
||||
@@ -39,6 +32,7 @@ export const renderFormCompletion = async (
|
||||
formTitle: title,
|
||||
appendAttribution,
|
||||
responseText: sanitizeHtml(responseText),
|
||||
redirectUrl,
|
||||
});
|
||||
|
||||
return { noWebhookResponse: true };
|
||||
|
||||
@@ -2,8 +2,6 @@ import { type Response } from 'express';
|
||||
import {
|
||||
type NodeTypeAndVersion,
|
||||
type IWebhookFunctions,
|
||||
FORM_NODE_TYPE,
|
||||
WAIT_NODE_TYPE,
|
||||
type FormFieldsParameter,
|
||||
type IWebhookResponseData,
|
||||
} from 'n8n-workflow';
|
||||
@@ -43,20 +41,6 @@ export const renderFormNode = async (
|
||||
) as string) || 'Submit';
|
||||
}
|
||||
|
||||
const responseMode = 'onReceived';
|
||||
|
||||
let redirectUrl;
|
||||
|
||||
const connectedNodes = context.getChildNodes(context.getNode().name);
|
||||
|
||||
const hasNextPage = connectedNodes.some(
|
||||
(node) => !node.disabled && (node.type === FORM_NODE_TYPE || node.type === WAIT_NODE_TYPE),
|
||||
);
|
||||
|
||||
if (hasNextPage) {
|
||||
redirectUrl = context.evaluateExpression('{{ $execution.resumeFormUrl }}') as string;
|
||||
}
|
||||
|
||||
const appendAttribution = context.evaluateExpression(
|
||||
`{{ $('${trigger?.name}').params.options?.appendAttribution === false ? false : true }}`,
|
||||
) as boolean;
|
||||
@@ -67,9 +51,9 @@ export const renderFormNode = async (
|
||||
formTitle: title,
|
||||
formDescription: description,
|
||||
formFields: fields,
|
||||
responseMode,
|
||||
responseMode: 'responseNode',
|
||||
mode,
|
||||
redirectUrl,
|
||||
redirectUrl: undefined,
|
||||
appendAttribution,
|
||||
buttonLabel,
|
||||
});
|
||||
|
||||
@@ -166,7 +166,7 @@ describe('Form Node', () => {
|
||||
formTitle: 'Form Title',
|
||||
n8nWebsiteLink: 'https://n8n.io/?utm_source=n8n-internal&utm_medium=form-trigger',
|
||||
testRun: true,
|
||||
useResponseData: false,
|
||||
useResponseData: true,
|
||||
validForm: true,
|
||||
formSubmittedHeader: undefined,
|
||||
});
|
||||
@@ -230,6 +230,7 @@ describe('Form Node', () => {
|
||||
appendAttribution: 'test',
|
||||
formTitle: 'test',
|
||||
message: 'Test Message',
|
||||
redirectUrl: '',
|
||||
title: 'Test Title',
|
||||
responseText: '',
|
||||
},
|
||||
@@ -242,6 +243,7 @@ describe('Form Node', () => {
|
||||
appendAttribution: 'test',
|
||||
formTitle: 'test',
|
||||
message: 'Test Message',
|
||||
redirectUrl: '',
|
||||
title: 'Test Title',
|
||||
responseText: '<div>hey</div>',
|
||||
},
|
||||
@@ -254,6 +256,7 @@ describe('Form Node', () => {
|
||||
appendAttribution: 'test',
|
||||
formTitle: 'test',
|
||||
message: 'Test Message',
|
||||
redirectUrl: '',
|
||||
title: 'Test Title',
|
||||
responseText: 'my text over here',
|
||||
},
|
||||
@@ -340,9 +343,14 @@ describe('Form Node', () => {
|
||||
const result = await form.webhook(mockWebhookFunctions);
|
||||
|
||||
expect(result).toEqual({ noWebhookResponse: true });
|
||||
expect(mockResponseObject.send).toHaveBeenCalledWith(
|
||||
'<html><head><meta http-equiv="refresh" content="0; url=https://n8n.io"></head></html>',
|
||||
);
|
||||
expect(mockResponseObject.render).toHaveBeenCalledWith('form-trigger-completion', {
|
||||
appendAttribution: 'test',
|
||||
formTitle: 'test',
|
||||
message: 'Test Message',
|
||||
redirectUrl: 'https://n8n.io',
|
||||
responseText: '',
|
||||
title: 'Test Title',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -476,7 +476,7 @@ export async function formWebhook(
|
||||
if (method === 'GET') {
|
||||
const formTitle = context.getNodeParameter('formTitle', '') as string;
|
||||
const formDescription = sanitizeHtml(context.getNodeParameter('formDescription', '') as string);
|
||||
const responseMode = context.getNodeParameter('responseMode', '') as string;
|
||||
let responseMode = context.getNodeParameter('responseMode', '') as string;
|
||||
|
||||
let formSubmittedText;
|
||||
let redirectUrl;
|
||||
@@ -504,15 +504,14 @@ export async function formWebhook(
|
||||
buttonLabel = options.buttonLabel;
|
||||
}
|
||||
|
||||
if (!redirectUrl && node.type !== FORM_TRIGGER_NODE_TYPE) {
|
||||
const connectedNodes = context.getChildNodes(context.getNode().name, {
|
||||
includeNodeParameters: true,
|
||||
});
|
||||
const hasNextPage = isFormConnected(connectedNodes);
|
||||
const connectedNodes = context.getChildNodes(context.getNode().name, {
|
||||
includeNodeParameters: true,
|
||||
});
|
||||
const hasNextPage = isFormConnected(connectedNodes);
|
||||
|
||||
if (hasNextPage) {
|
||||
redirectUrl = context.evaluateExpression('{{ $execution.resumeFormUrl }}') as string;
|
||||
}
|
||||
if (hasNextPage) {
|
||||
redirectUrl = undefined;
|
||||
responseMode = 'responseNode';
|
||||
}
|
||||
|
||||
renderForm({
|
||||
|
||||
Reference in New Issue
Block a user