]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add audit logs for video import
authorChocobozzz <me@florianbigard.com>
Fri, 3 Aug 2018 08:26:47 +0000 (10:26 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 6 Aug 2018 09:19:16 +0000 (11:19 +0200)
scripts/i18n/create-custom-files.ts
server/controllers/api/videos/import.ts
server/helpers/audit-logger.ts

index a297fa79cf45967017b56de1359d597cf64a70c3..c4f8411e133b078e3fdbda97f81c577072d9bc04 100755 (executable)
@@ -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
index ca7a5f9cac8edabd4365d8215d68f694868b2de9..33ac83cb937b24fad9b72e4a43148978275b0501 100644 (file)
@@ -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())
 }
index f6eea7d9046707b159e4b0396ac31bf46789a34d..031b1bfbd08650301eedfb7a6b6843944d455a9a 100644 (file)
@@ -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,