From 2dbc170da35c9f88770653cd3114f4c59d482094 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 4 Jan 2021 09:54:48 +0100 Subject: [PATCH] Add missing audit log if the user deletes its account --- server/controllers/api/users/index.ts | 4 ++-- server/controllers/api/users/me.ts | 9 +++++++-- server/tests/api/users/users-verification.ts | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index d743a9912..c3190e731 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts @@ -305,10 +305,10 @@ async function listUsers (req: express.Request, res: express.Response) { async function removeUser (req: express.Request, res: express.Response) { const user = res.locals.user - await user.destroy() - auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) + await user.destroy() + Hooks.runAction('action:api.user.deleted', { user }) return res.sendStatus(HttpStatusCode.NO_CONTENT_204) diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index 3d2a325fe..b786d7f59 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts @@ -1,6 +1,8 @@ import 'multer' import * as express from 'express' +import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '@server/helpers/audit-logger' import { UserUpdateMe, UserVideoRate as FormattedUserVideoRate, VideoSortField } from '../../../../shared' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model' import { createReqFiles } from '../../../helpers/express-utils' import { getFormattedObjects } from '../../../helpers/utils' @@ -28,7 +30,8 @@ import { AccountVideoRateModel } from '../../../models/account/account-video-rat import { UserModel } from '../../../models/account/user' import { VideoModel } from '../../../models/video/video' import { VideoImportModel } from '../../../models/video/video-import' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' + +const auditLogger = auditLoggerFactory('users') const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) @@ -159,7 +162,9 @@ async function getUserVideoRating (req: express.Request, res: express.Response) } async function deleteMe (req: express.Request, res: express.Response) { - const user = res.locals.oauth.token.User + const user = await UserModel.loadByIdWithChannels(res.locals.oauth.token.User.id) + + auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) await user.destroy() diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index e05acdd72..1a9a519a0 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -104,6 +104,8 @@ describe('Test users account verification', function () { }) it('Should be able to change the user email', async function () { + this.timeout(10000) + let updateVerificationString: string { -- 2.41.0