mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 12:19:09 +00:00
fix(core): Fix test webhook deregistration (#8247)
This commit is contained in:
@@ -24,6 +24,7 @@ import { WebhookNotFoundError } from '@/errors/response-errors/webhook-not-found
|
||||
import * as NodeExecuteFunctions from 'n8n-core';
|
||||
import { removeTrailingSlash } from './utils';
|
||||
import { TestWebhookRegistrationsService } from '@/services/test-webhook-registrations.service';
|
||||
import * as WorkflowExecuteAdditionalData from '@/WorkflowExecuteAdditionalData';
|
||||
|
||||
@Service()
|
||||
export class TestWebhooks implements IWebhookManager {
|
||||
@@ -185,6 +186,7 @@ export class TestWebhooks implements IWebhookManager {
|
||||
* For every webhook call to listen for, also activate the webhook.
|
||||
*/
|
||||
async needsWebhook(
|
||||
userId: string,
|
||||
workflowEntity: IWorkflowDb,
|
||||
additionalData: IWorkflowExecuteAdditionalData,
|
||||
sessionId?: string,
|
||||
@@ -219,21 +221,23 @@ export class TestWebhooks implements IWebhookManager {
|
||||
webhook.isTest = true;
|
||||
|
||||
/**
|
||||
* Remove additional data from webhook because:
|
||||
*
|
||||
* - It is not needed for the test webhook to be executed.
|
||||
* - It contains circular refs that cannot be cached.
|
||||
* Additional data cannot be cached because of circular refs.
|
||||
* Hence store the `userId` and recreate additional data when needed.
|
||||
*/
|
||||
const { workflowExecuteAdditionalData: _, ...rest } = webhook;
|
||||
const { workflowExecuteAdditionalData: _, ...cacheableWebhook } = webhook;
|
||||
|
||||
cacheableWebhook.userId = userId;
|
||||
|
||||
try {
|
||||
await workflow.createWebhookIfNotExists(webhook, NodeExecuteFunctions, 'manual', 'manual');
|
||||
|
||||
cacheableWebhook.staticData = workflow.staticData;
|
||||
|
||||
await this.registrations.register({
|
||||
sessionId,
|
||||
workflowEntity,
|
||||
destinationNode,
|
||||
webhook: rest as IWebhookData,
|
||||
webhook: cacheableWebhook as IWebhookData,
|
||||
});
|
||||
|
||||
this.timeouts[key] = timeout;
|
||||
@@ -341,6 +345,14 @@ export class TestWebhooks implements IWebhookManager {
|
||||
if (!webhooks) return; // nothing to deactivate
|
||||
|
||||
for (const webhook of webhooks) {
|
||||
const { userId, staticData } = webhook;
|
||||
|
||||
if (userId) {
|
||||
webhook.workflowExecuteAdditionalData = await WorkflowExecuteAdditionalData.getBase(userId);
|
||||
}
|
||||
|
||||
if (staticData) workflow.staticData = staticData;
|
||||
|
||||
await workflow.deleteWebhook(webhook, NodeExecuteFunctions, 'internal', 'update');
|
||||
|
||||
await this.registrations.deregister(webhook);
|
||||
@@ -350,7 +362,7 @@ export class TestWebhooks implements IWebhookManager {
|
||||
/**
|
||||
* Convert a `WorkflowEntity` from `typeorm` to a `Workflow` from `n8n-workflow`.
|
||||
*/
|
||||
private toWorkflow(workflowEntity: IWorkflowDb) {
|
||||
toWorkflow(workflowEntity: IWorkflowDb) {
|
||||
return new Workflow({
|
||||
id: workflowEntity.id,
|
||||
name: workflowEntity.name,
|
||||
@@ -358,7 +370,14 @@ export class TestWebhooks implements IWebhookManager {
|
||||
connections: workflowEntity.connections,
|
||||
active: false,
|
||||
nodeTypes: this.nodeTypes,
|
||||
|
||||
/**
|
||||
* `staticData` in the original workflow entity has production webhook IDs.
|
||||
* Since we are creating here a temporary workflow only for a test webhook,
|
||||
* `staticData` from the original workflow entity should not be transferred.
|
||||
*/
|
||||
staticData: undefined,
|
||||
|
||||
settings: workflowEntity.settings,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user