refactor(core): Decouple event bus from internal hooks (no-changelog) (#9724)

This commit is contained in:
Iván Ovejero
2024-06-20 12:32:22 +02:00
committed by GitHub
parent e4463c62b4
commit 199dff4fb3
29 changed files with 1028 additions and 664 deletions

View File

@@ -29,6 +29,7 @@ import { In } from '@n8n/typeorm';
import { SharedCredentials } from '@/databases/entities/SharedCredentials';
import { ProjectRelationRepository } from '@/databases/repositories/projectRelation.repository';
import { z } from 'zod';
import { EventRelay } from '@/eventbus/event-relay.service';
@RestController('/credentials')
export class CredentialsController {
@@ -42,6 +43,7 @@ export class CredentialsController {
private readonly userManagementMailer: UserManagementMailer,
private readonly sharedCredentialsRepository: SharedCredentialsRepository,
private readonly projectRelationRepository: ProjectRelationRepository,
private readonly eventRelay: EventRelay,
) {}
@Get('/', { middlewares: listQueryMiddleware })
@@ -164,6 +166,12 @@ export class CredentialsController {
credential_id: credential.id,
public_api: false,
});
this.eventRelay.emit('credentials-created', {
user: req.user,
credentialName: newCredential.name,
credentialType: credential.type,
credentialId: credential.id,
});
const scopes = await this.credentialsService.getCredentialScopes(req.user, credential.id);
@@ -218,6 +226,12 @@ export class CredentialsController {
credential_type: credential.type,
credential_id: credential.id,
});
this.eventRelay.emit('credentials-updated', {
user: req.user,
credentialName: credential.name,
credentialType: credential.type,
credentialId: credential.id,
});
const scopes = await this.credentialsService.getCredentialScopes(req.user, credential.id);
@@ -253,6 +267,12 @@ export class CredentialsController {
credential_type: credential.type,
credential_id: credential.id,
});
this.eventRelay.emit('credentials-deleted', {
user: req.user,
credentialName: credential.name,
credentialType: credential.type,
credentialId: credential.id,
});
return true;
}
@@ -321,6 +341,15 @@ export class CredentialsController {
user_ids_sharees_added: newShareeIds,
sharees_removed: amountRemoved,
});
this.eventRelay.emit('credentials-shared', {
user: req.user,
credentialName: credential.name,
credentialType: credential.type,
credentialId: credential.id,
userIdSharer: req.user.id,
userIdsShareesRemoved: newShareeIds,
shareesRemoved: amountRemoved,
});
const projectsRelations = await this.projectRelationRepository.findBy({
projectId: In(newShareeIds),