refactor(core): Decouple user events from internal hooks (no-changelog) (#10292)

This commit is contained in:
Iván Ovejero
2024-08-05 12:07:42 +02:00
committed by GitHub
parent 88086a41ff
commit c0f3693e8a
15 changed files with 260 additions and 181 deletions

View File

@@ -19,7 +19,6 @@ import { isSamlLicensedAndEnabled } from '@/sso/saml/samlHelpers';
import { UserService } from '@/services/user.service';
import { Logger } from '@/Logger';
import { ExternalHooks } from '@/ExternalHooks';
import { InternalHooks } from '@/InternalHooks';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { UserRepository } from '@/databases/repositories/user.repository';
import { isApiEnabled } from '@/PublicApi';
@@ -40,7 +39,6 @@ export class MeController {
constructor(
private readonly logger: Logger,
private readonly externalHooks: ExternalHooks,
private readonly internalHooks: InternalHooks,
private readonly authService: AuthService,
private readonly userService: UserService,
private readonly passwordUtility: PasswordUtility,
@@ -101,7 +99,6 @@ export class MeController {
this.authService.issueCookie(res, user, req.browserId);
const fieldsChanged = Object.keys(payload);
this.internalHooks.onUserUpdate({ user, fields_changed: fieldsChanged });
this.eventService.emit('user-updated', { user, fieldsChanged });
const publicUser = await this.userService.toPublic(user);
@@ -151,7 +148,6 @@ export class MeController {
this.authService.issueCookie(res, updatedUser, req.browserId);
this.internalHooks.onUserUpdate({ user: updatedUser, fields_changed: ['password'] });
this.eventService.emit('user-updated', { user: updatedUser, fieldsChanged: ['password'] });
await this.externalHooks.run('user.password.update', [updatedUser.email, updatedUser.password]);
@@ -186,7 +182,10 @@ export class MeController {
this.logger.info('User survey updated successfully', { userId: req.user.id });
this.internalHooks.onPersonalizationSurveySubmitted(req.user.id, personalizationAnswers);
this.eventService.emit('user-submitted-personalization-survey', {
userId: req.user.id,
answers: personalizationAnswers,
});
return { success: true };
}