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

@@ -21,6 +21,7 @@ import { ForbiddenError } from '@/errors/response-errors/forbidden.error';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
import { UnprocessableRequestError } from '@/errors/response-errors/unprocessable.error';
import { UserRepository } from '@/databases/repositories/user.repository';
import { EventRelay } from '@/eventbus/event-relay.service';
@RestController()
export class PasswordResetController {
@@ -36,6 +37,7 @@ export class PasswordResetController {
private readonly license: License,
private readonly passwordUtility: PasswordUtility,
private readonly userRepository: UserRepository,
private readonly eventRelay: EventRelay,
) {}
/**
@@ -123,6 +125,7 @@ export class PasswordResetController {
message_type: 'Reset password',
public_api: false,
});
this.eventRelay.emit('email-failed', { user, messageType: 'Reset password' });
if (error instanceof Error) {
throw new InternalServerError(`Please contact your administrator: ${error.message}`);
}
@@ -136,6 +139,7 @@ export class PasswordResetController {
});
void this.internalHooks.onUserPasswordResetRequestClick({ user });
this.eventRelay.emit('user-password-reset-request-click', { user });
}
/**
@@ -168,6 +172,7 @@ export class PasswordResetController {
this.logger.info('Reset-password token resolved successfully', { userId: user.id });
void this.internalHooks.onUserPasswordResetEmailClick({ user });
this.eventRelay.emit('user-password-reset-email-click', { user });
}
/**
@@ -210,10 +215,8 @@ export class PasswordResetController {
this.authService.issueCookie(res, user, req.browserId);
void this.internalHooks.onUserUpdate({
user,
fields_changed: ['password'],
});
void this.internalHooks.onUserUpdate({ user, fields_changed: ['password'] });
this.eventRelay.emit('user-updated', { user, fieldsChanged: ['password'] });
// if this user used to be an LDAP users
const ldapIdentity = user?.authIdentities?.find((i) => i.providerType === 'ldap');
@@ -222,6 +225,7 @@ export class PasswordResetController {
user_type: 'email',
was_disabled_ldap_user: true,
});
this.eventRelay.emit('user-signed-up', { user });
}
await this.externalHooks.run('user.password.update', [user.email, passwordHash]);