From 7e5f9f001d5de22c54748f935edc0c069028bb0e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 3 Aug 2018 10:26:47 +0200 Subject: Add audit logs for video import --- scripts/i18n/create-custom-files.ts | 11 ++++++++++- server/controllers/api/videos/import.ts | 11 ++++------- server/helpers/audit-logger.ts | 14 +++++++++++++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/scripts/i18n/create-custom-files.ts b/scripts/i18n/create-custom-files.ts index a297fa79c..c4f8411e1 100755 --- a/scripts/i18n/create-custom-files.ts +++ b/scripts/i18n/create-custom-files.ts @@ -1,7 +1,14 @@ import * as jsToXliff12 from 'xliff/jsToXliff12' import { writeFile } from 'fs' import { join } from 'path' -import { buildLanguages, VIDEO_CATEGORIES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../server/initializers/constants' +import { + buildLanguages, + VIDEO_CATEGORIES, + VIDEO_IMPORT_STATES, + VIDEO_LICENCES, + VIDEO_PRIVACIES, + VIDEO_STATES +} from '../../server/initializers/constants' import { values } from 'lodash' type TranslationType = { @@ -33,6 +40,8 @@ const serverKeys: any = {} values(VIDEO_CATEGORIES) .concat(values(VIDEO_LICENCES)) .concat(values(VIDEO_PRIVACIES)) + .concat(values(VIDEO_STATES)) + .concat(values(VIDEO_IMPORT_STATES)) .forEach(v => serverKeys[v] = v) // More keys diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index ca7a5f9ca..33ac83cb9 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -1,11 +1,6 @@ import * as express from 'express' -import { auditLoggerFactory } from '../../../helpers/audit-logger' -import { - asyncMiddleware, - asyncRetryTransactionMiddleware, - authenticate, - videoImportAddValidator -} from '../../../middlewares' +import { auditLoggerFactory, VideoImportAuditView } from '../../../helpers/audit-logger' +import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' import { CONFIG, IMAGE_MIMETYPE_EXT, PREVIEWS_SIZE, sequelizeTypescript, THUMBNAILS_SIZE } from '../../../initializers' import { getYoutubeDLInfo, YoutubeDLInfo } from '../../../helpers/youtube-dl' import { createReqFiles } from '../../../helpers/express-utils' @@ -136,5 +131,7 @@ async function addVideoImport (req: express.Request, res: express.Response) { } await JobQueue.Instance.createJob({ type: 'video-import', payload }) + auditLogger.create(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new VideoImportAuditView(videoImport.toFormattedJSON())) + return res.json(videoImport.toFormattedJSON()) } diff --git a/server/helpers/audit-logger.ts b/server/helpers/audit-logger.ts index f6eea7d90..031b1bfbd 100644 --- a/server/helpers/audit-logger.ts +++ b/server/helpers/audit-logger.ts @@ -5,7 +5,7 @@ import * as flatten from 'flat' import * as winston from 'winston' import { CONFIG } from '../initializers' import { jsonLoggerFormat, labelFormatter } from './logger' -import { VideoDetails, User, VideoChannel, VideoAbuse } from '../../shared' +import { VideoDetails, User, VideoChannel, VideoAbuse, VideoImport } from '../../shared' import { VideoComment } from '../../shared/models/videos/video-comment.model' import { CustomConfig } from '../../shared/models/server/custom-config.model' @@ -119,6 +119,17 @@ class VideoAuditView extends EntityAuditView { } } +const videoImportKeysToKeep = [ + 'id', + 'targetUrl', + 'video-name' +] +class VideoImportAuditView extends EntityAuditView { + constructor (private videoImport: VideoImport) { + super(videoImportKeysToKeep, 'video-import', videoImport) + } +} + const commentKeysToKeep = [ 'id', 'text', @@ -246,6 +257,7 @@ class CustomConfigAuditView extends EntityAuditView { export { auditLoggerFactory, + VideoImportAuditView, VideoChannelAuditView, CommentAuditView, UserAuditView, -- cgit v1.2.3