diff --git a/src/lib/services/user-service.ts b/src/lib/services/user-service.ts index 60d83cca8bd4..1dc167d4b420 100644 --- a/src/lib/services/user-service.ts +++ b/src/lib/services/user-service.ts @@ -33,7 +33,7 @@ import { TokenUserSchema } from '../openapi/spec/token-user-schema'; import PasswordMismatch from '../error/password-mismatch'; import EventService from '../features/events/event-service'; -const systemUser = new User({ id: -1, username: 'system' }); +import { SYSTEM_USER } from '../types'; export interface ICreateUser { name?: string; @@ -244,7 +244,12 @@ class UserService { return userCreated; } - private getCreatedBy(updatedBy: IUser = systemUser) { + private getCreatedBy( + updatedBy: IUser = new User({ + id: SYSTEM_USER.id, + username: SYSTEM_USER.username, + }), + ): string { return updatedBy.username || updatedBy.email; } @@ -444,7 +449,10 @@ class UserService { async createResetPasswordEmail( receiverEmail: string, - user: IUser = systemUser, + user: IUser = new User({ + id: SYSTEM_USER.id, + username: SYSTEM_USER.username, + }), ): Promise { const receiver = await this.getByEmail(receiverEmail); if (!receiver) { diff --git a/src/migrations/20240123092918-EVENTS-SYSTEM-USER-OLD-TO-NEW.js b/src/migrations/20240123092918-EVENTS-SYSTEM-USER-OLD-TO-NEW.js new file mode 100644 index 000000000000..2fcf10fe888f --- /dev/null +++ b/src/migrations/20240123092918-EVENTS-SYSTEM-USER-OLD-TO-NEW.js @@ -0,0 +1,14 @@ +'use strict'; + +exports.up = function (db, callback) { + db.runSql( + ` + UPDATE TABLE events SET created_by_user_id = -1337 WHERE created_by_user_id = -1; + `, + callback, + ); +}; + +exports.down = function (db, callback) { + callback(); +};