refactor(core): Decouple event bus from internal hooks (no-changelog) (#9724)
This commit is contained in:
@@ -32,6 +32,7 @@ import type { Scope } from '@n8n/permissions';
|
||||
import type { EntityManager } from '@n8n/typeorm';
|
||||
import { In } from '@n8n/typeorm';
|
||||
import { SharedWorkflow } from '@/databases/entities/SharedWorkflow';
|
||||
import { EventRelay } from '@/eventbus/event-relay.service';
|
||||
|
||||
@Service()
|
||||
export class WorkflowService {
|
||||
@@ -51,6 +52,7 @@ export class WorkflowService {
|
||||
private readonly workflowSharingService: WorkflowSharingService,
|
||||
private readonly projectService: ProjectService,
|
||||
private readonly executionRepository: ExecutionRepository,
|
||||
private readonly eventRelay: EventRelay,
|
||||
) {}
|
||||
|
||||
async getMany(user: User, options?: ListQuery.Options, includeScopes?: boolean) {
|
||||
@@ -216,6 +218,11 @@ export class WorkflowService {
|
||||
|
||||
await this.externalHooks.run('workflow.afterUpdate', [updatedWorkflow]);
|
||||
void Container.get(InternalHooks).onWorkflowSaved(user, updatedWorkflow, false);
|
||||
this.eventRelay.emit('workflow-saved', {
|
||||
user,
|
||||
workflowId: updatedWorkflow.id,
|
||||
workflowName: updatedWorkflow.name,
|
||||
});
|
||||
|
||||
if (updatedWorkflow.active) {
|
||||
// When the workflow is supposed to be active add it again
|
||||
@@ -274,6 +281,7 @@ export class WorkflowService {
|
||||
await this.binaryDataService.deleteMany(idsForDeletion);
|
||||
|
||||
void Container.get(InternalHooks).onWorkflowDeleted(user, workflowId, false);
|
||||
this.eventRelay.emit('workflow-deleted', { user, workflowId });
|
||||
await this.externalHooks.run('workflow.afterDelete', [workflowId]);
|
||||
|
||||
return workflow;
|
||||
|
||||
@@ -41,6 +41,7 @@ import { In, type FindOptionsRelations } from '@n8n/typeorm';
|
||||
import type { Project } from '@/databases/entities/Project';
|
||||
import { ProjectRelationRepository } from '@/databases/repositories/projectRelation.repository';
|
||||
import { z } from 'zod';
|
||||
import { EventRelay } from '@/eventbus/event-relay.service';
|
||||
|
||||
@RestController('/workflows')
|
||||
export class WorkflowsController {
|
||||
@@ -64,6 +65,7 @@ export class WorkflowsController {
|
||||
private readonly projectRepository: ProjectRepository,
|
||||
private readonly projectService: ProjectService,
|
||||
private readonly projectRelationRepository: ProjectRelationRepository,
|
||||
private readonly eventRelay: EventRelay,
|
||||
) {}
|
||||
|
||||
@Post('/')
|
||||
@@ -175,6 +177,7 @@ export class WorkflowsController {
|
||||
|
||||
await this.externalHooks.run('workflow.afterCreate', [savedWorkflow]);
|
||||
void this.internalHooks.onWorkflowCreated(req.user, newWorkflow, project!, false);
|
||||
this.eventRelay.emit('workflow-created', { user: req.user, workflow: newWorkflow });
|
||||
|
||||
const scopes = await this.workflowService.getWorkflowScopes(req.user, savedWorkflow.id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user