refactor(core): Decouple workflow created, saved, deleted events from internal hooks (no-changelog) (#10264)

This commit is contained in:
Iván Ovejero
2024-08-01 13:44:23 +02:00
committed by GitHub
parent efb71dd9ad
commit d8688bd463
8 changed files with 125 additions and 103 deletions

View File

@@ -1,4 +1,4 @@
import Container, { Service } from 'typedi';
import { Service } from 'typedi';
import { NodeApiError } from 'n8n-workflow';
import pick from 'lodash/pick';
import omit from 'lodash/omit';
@@ -17,7 +17,6 @@ import { validateEntity } from '@/GenericHelpers';
import { ExternalHooks } from '@/ExternalHooks';
import { hasSharing, type ListQuery } from '@/requests';
import { TagService } from '@/services/tag.service';
import { InternalHooks } from '@/InternalHooks';
import { OwnershipService } from '@/services/ownership.service';
import { WorkflowHistoryService } from './workflowHistory/workflowHistory.service.ee';
import { Logger } from '@/Logger';
@@ -219,11 +218,10 @@ export class WorkflowService {
}
await this.externalHooks.run('workflow.afterUpdate', [updatedWorkflow]);
void Container.get(InternalHooks).onWorkflowSaved(user, updatedWorkflow, false);
this.eventService.emit('workflow-saved', {
user,
workflowId: updatedWorkflow.id,
workflowName: updatedWorkflow.name,
workflow: updatedWorkflow,
publicApi: false,
});
if (updatedWorkflow.active) {
@@ -282,8 +280,7 @@ export class WorkflowService {
await this.workflowRepository.delete(workflowId);
await this.binaryDataService.deleteMany(idsForDeletion);
Container.get(InternalHooks).onWorkflowDeleted(user, workflowId, false);
this.eventService.emit('workflow-deleted', { user, workflowId });
this.eventService.emit('workflow-deleted', { user, workflowId, publicApi: false });
await this.externalHooks.run('workflow.afterDelete', [workflowId]);
return workflow;

View File

@@ -179,8 +179,13 @@ export class WorkflowsController {
delete savedWorkflowWithMetaData.shared;
await this.externalHooks.run('workflow.afterCreate', [savedWorkflow]);
this.internalHooks.onWorkflowCreated(req.user, newWorkflow, project!, false);
this.eventService.emit('workflow-created', { user: req.user, workflow: newWorkflow });
this.eventService.emit('workflow-created', {
user: req.user,
workflow: newWorkflow,
publicApi: false,
projectId: project!.id,
projectType: project!.type,
});
const scopes = await this.workflowService.getWorkflowScopes(req.user, savedWorkflow.id);