mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
refactor(core): Decouple event bus from internal hooks (no-changelog) (#9724)
This commit is contained in:
@@ -23,6 +23,7 @@ import { InternalHooks } from '@/InternalHooks';
|
||||
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
||||
import { UserRepository } from '@/databases/repositories/user.repository';
|
||||
import { isApiEnabled } from '@/PublicApi';
|
||||
import { EventRelay } from '@/eventbus/event-relay.service';
|
||||
|
||||
export const isApiEnabledMiddleware: RequestHandler = (_, res, next) => {
|
||||
if (isApiEnabled()) {
|
||||
@@ -42,6 +43,7 @@ export class MeController {
|
||||
private readonly userService: UserService,
|
||||
private readonly passwordUtility: PasswordUtility,
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly eventRelay: EventRelay,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -96,11 +98,9 @@ export class MeController {
|
||||
|
||||
this.authService.issueCookie(res, user, req.browserId);
|
||||
|
||||
const updatedKeys = Object.keys(payload);
|
||||
void this.internalHooks.onUserUpdate({
|
||||
user,
|
||||
fields_changed: updatedKeys,
|
||||
});
|
||||
const fieldsChanged = Object.keys(payload);
|
||||
void this.internalHooks.onUserUpdate({ user, fields_changed: fieldsChanged });
|
||||
this.eventRelay.emit('user-updated', { user, fieldsChanged });
|
||||
|
||||
const publicUser = await this.userService.toPublic(user);
|
||||
|
||||
@@ -149,10 +149,8 @@ export class MeController {
|
||||
|
||||
this.authService.issueCookie(res, updatedUser, req.browserId);
|
||||
|
||||
void this.internalHooks.onUserUpdate({
|
||||
user: updatedUser,
|
||||
fields_changed: ['password'],
|
||||
});
|
||||
void this.internalHooks.onUserUpdate({ user: updatedUser, fields_changed: ['password'] });
|
||||
this.eventRelay.emit('user-updated', { user: updatedUser, fieldsChanged: ['password'] });
|
||||
|
||||
await this.externalHooks.run('user.password.update', [updatedUser.email, updatedUser.password]);
|
||||
|
||||
@@ -200,10 +198,8 @@ export class MeController {
|
||||
|
||||
await this.userService.update(req.user.id, { apiKey });
|
||||
|
||||
void this.internalHooks.onApiKeyCreated({
|
||||
user: req.user,
|
||||
public_api: false,
|
||||
});
|
||||
void this.internalHooks.onApiKeyCreated({ user: req.user, public_api: false });
|
||||
this.eventRelay.emit('api-key-created', { user: req.user });
|
||||
|
||||
return { apiKey };
|
||||
}
|
||||
@@ -223,10 +219,8 @@ export class MeController {
|
||||
async deleteAPIKey(req: AuthenticatedRequest) {
|
||||
await this.userService.update(req.user.id, { apiKey: null });
|
||||
|
||||
void this.internalHooks.onApiKeyDeleted({
|
||||
user: req.user,
|
||||
public_api: false,
|
||||
});
|
||||
void this.internalHooks.onApiKeyDeleted({ user: req.user, public_api: false });
|
||||
this.eventRelay.emit('api-key-deleted', { user: req.user });
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user