Refractor audit user identifier

pull/1093/head
Chocobozzz 2018-09-19 17:02:16 +02:00
parent 606c946e74
commit 993cef4b6e
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
9 changed files with 58 additions and 48 deletions

View File

@ -8,7 +8,7 @@ import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers'
import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
import { customConfigUpdateValidator } from '../../middlewares/validators/config'
import { ClientHtml } from '../../lib/client-html'
import { auditLoggerFactory, CustomConfigAuditView } from '../../helpers/audit-logger'
import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger'
import { remove, writeJSON } from 'fs-extra'
const packageJSON = require('../../../../package.json')
@ -134,10 +134,7 @@ async function getCustomConfig (req: express.Request, res: express.Response, nex
async function deleteCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) {
await remove(CONFIG.CUSTOM_FILE)
auditLogger.delete(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
new CustomConfigAuditView(customConfig())
)
auditLogger.delete(getAuditIdFromRes(res), new CustomConfigAuditView(customConfig()))
reloadConfig()
ClientHtml.invalidCache()
@ -183,7 +180,7 @@ async function updateCustomConfig (req: express.Request, res: express.Response,
const data = customConfig()
auditLogger.update(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
getAuditIdFromRes(res),
new CustomConfigAuditView(data),
oldCustomConfigAuditKeys
)

View File

@ -27,12 +27,15 @@ import {
usersUpdateValidator
} from '../../../middlewares'
import {
usersAskResetPasswordValidator, usersBlockingValidator, usersResetPasswordValidator,
usersAskSendVerifyEmailValidator, usersVerifyEmailValidator
usersAskResetPasswordValidator,
usersAskSendVerifyEmailValidator,
usersBlockingValidator,
usersResetPasswordValidator,
usersVerifyEmailValidator
} from '../../../middlewares/validators'
import { UserModel } from '../../../models/account/user'
import { OAuthTokenModel } from '../../../models/oauth/oauth-token'
import { auditLoggerFactory, UserAuditView } from '../../../helpers/audit-logger'
import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger'
import { meRouter } from './me'
const auditLogger = auditLoggerFactory('users')
@ -166,7 +169,7 @@ async function createUser (req: express.Request, res: express.Response) {
const { user, account } = await createUserAccountAndChannel(userToCreate)
auditLogger.create(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new UserAuditView(user.toFormattedJSON()))
auditLogger.create(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
logger.info('User %s with its channel and account created.', body.username)
return res.json({
@ -245,7 +248,7 @@ async function removeUser (req: express.Request, res: express.Response, next: ex
await user.destroy()
auditLogger.delete(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new UserAuditView(user.toFormattedJSON()))
auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
return res.sendStatus(204)
}
@ -269,7 +272,7 @@ async function updateUser (req: express.Request, res: express.Response, next: ex
}
auditLogger.update(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
getAuditIdFromRes(res),
new UserAuditView(user.toFormattedJSON()),
oldUserAuditView
)
@ -341,7 +344,7 @@ async function changeUserBlock (res: express.Response, user: UserModel, block: b
await Emailer.Instance.addUserBlockJob(user, block, reason)
auditLogger.update(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
getAuditIdFromRes(res),
new UserAuditView(user.toFormattedJSON()),
oldUserAuditView
)

View File

@ -5,7 +5,8 @@ import { getFormattedObjects } from '../../../helpers/utils'
import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../../initializers'
import { sendUpdateActor } from '../../../lib/activitypub/send'
import {
asyncMiddleware, asyncRetryTransactionMiddleware,
asyncMiddleware,
asyncRetryTransactionMiddleware,
authenticate,
commonVideosFiltersValidator,
paginationValidator,
@ -17,11 +18,11 @@ import {
usersVideoRatingValidator
} from '../../../middlewares'
import {
areSubscriptionsExistValidator,
deleteMeValidator,
userSubscriptionsSortValidator,
videoImportsSortValidator,
videosSortValidator,
areSubscriptionsExistValidator
videosSortValidator
} from '../../../middlewares/validators'
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
import { UserModel } from '../../../models/account/user'
@ -31,7 +32,7 @@ import { buildNSFWFilter, createReqFiles } from '../../../helpers/express-utils'
import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model'
import { updateAvatarValidator } from '../../../middlewares/validators/avatar'
import { updateActorAvatarFile } from '../../../lib/avatar'
import { auditLoggerFactory, UserAuditView } from '../../../helpers/audit-logger'
import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger'
import { VideoImportModel } from '../../../models/video/video-import'
import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
@ -311,7 +312,7 @@ async function deleteMe (req: express.Request, res: express.Response) {
await user.destroy()
auditLogger.delete(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new UserAuditView(user.toFormattedJSON()))
auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
return res.sendStatus(204)
}
@ -337,7 +338,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr
await sendUpdateActor(user.Account, t)
auditLogger.update(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
getAuditIdFromRes(res),
new UserAuditView(user.toFormattedJSON()),
oldUserAuditView
)
@ -355,7 +356,7 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next
const avatar = await updateActorAvatarFile(avatarPhysicalFile, account.Actor, account)
auditLogger.update(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
getAuditIdFromRes(res),
new UserAuditView(user.toFormattedJSON()),
oldUserAuditView
)

View File

@ -27,7 +27,7 @@ import { logger } from '../../helpers/logger'
import { VideoModel } from '../../models/video/video'
import { updateAvatarValidator } from '../../middlewares/validators/avatar'
import { updateActorAvatarFile } from '../../lib/avatar'
import { auditLoggerFactory, VideoChannelAuditView } from '../../helpers/audit-logger'
import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger'
import { resetSequelizeInstance } from '../../helpers/database-utils'
const auditLogger = auditLoggerFactory('channels')
@ -109,7 +109,7 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp
const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel.Actor, videoChannel)
auditLogger.update(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
getAuditIdFromRes(res),
new VideoChannelAuditView(videoChannel.toFormattedJSON()),
oldVideoChannelAuditKeys
)
@ -133,7 +133,7 @@ async function addVideoChannel (req: express.Request, res: express.Response) {
.catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, { err }))
auditLogger.create(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
getAuditIdFromRes(res),
new VideoChannelAuditView(videoChannelCreated.toFormattedJSON())
)
logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid)
@ -166,7 +166,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response)
await sendUpdateActor(videoChannelInstanceUpdated, t)
auditLogger.update(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
getAuditIdFromRes(res),
new VideoChannelAuditView(videoChannelInstanceUpdated.toFormattedJSON()),
oldVideoChannelAuditKeys
)
@ -192,10 +192,7 @@ async function removeVideoChannel (req: express.Request, res: express.Response)
await sequelizeTypescript.transaction(async t => {
await videoChannelInstance.destroy({ transaction: t })
auditLogger.delete(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
new VideoChannelAuditView(videoChannelInstance.toFormattedJSON())
)
auditLogger.delete(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()))
logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.Actor.uuid)
})

View File

@ -23,7 +23,7 @@ import {
} from '../../../middlewares/validators/video-comments'
import { VideoModel } from '../../../models/video/video'
import { VideoCommentModel } from '../../../models/video/video-comment'
import { auditLoggerFactory, CommentAuditView } from '../../../helpers/audit-logger'
import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
const auditLogger = auditLoggerFactory('comments')
const videoCommentRouter = express.Router()
@ -109,7 +109,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons
}, t)
})
auditLogger.create(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new CommentAuditView(comment.toFormattedJSON()))
auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
return res.json({
comment: comment.toFormattedJSON()
@ -128,7 +128,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Response
}, t)
})
auditLogger.create(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new CommentAuditView(comment.toFormattedJSON()))
auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
return res.json({
comment: comment.toFormattedJSON()
@ -143,7 +143,7 @@ async function removeVideoComment (req: express.Request, res: express.Response)
})
auditLogger.delete(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
getAuditIdFromRes(res),
new CommentAuditView(videoCommentInstance.toFormattedJSON())
)
logger.info('Video comment %d deleted.', videoCommentInstance.id)

View File

@ -1,7 +1,7 @@
import * as express from 'express'
import * as magnetUtil from 'magnet-uri'
import 'multer'
import { auditLoggerFactory, VideoImportAuditView } from '../../../helpers/audit-logger'
import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares'
import {
CONFIG,
@ -114,7 +114,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
}
await JobQueue.Instance.createJob({ type: 'video-import', payload })
auditLogger.create(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new VideoImportAuditView(videoImport.toFormattedJSON()))
auditLogger.create(getAuditIdFromRes(res), new VideoImportAuditView(videoImport.toFormattedJSON()))
return res.json(videoImport.toFormattedJSON()).end()
}
@ -158,7 +158,7 @@ async function addYoutubeDLImport (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()))
auditLogger.create(getAuditIdFromRes(res), new VideoImportAuditView(videoImport.toFormattedJSON()))
return res.json(videoImport.toFormattedJSON()).end()
}

View File

@ -4,7 +4,7 @@ import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../
import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
import { processImage } from '../../../helpers/image-utils'
import { logger } from '../../../helpers/logger'
import { auditLoggerFactory, VideoAuditView } from '../../../helpers/audit-logger'
import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
import {
CONFIG,
@ -253,7 +253,7 @@ async function addVideo (req: express.Request, res: express.Response) {
await federateVideoIfNeeded(video, true, t)
auditLogger.create(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new VideoAuditView(videoCreated.toFormattedDetailsJSON()))
auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON()))
logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid)
return videoCreated
@ -354,7 +354,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
auditLogger.update(
res.locals.oauth.token.User.Account.Actor.getIdentifier(),
getAuditIdFromRes(res),
new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()),
oldVideoAuditView
)
@ -439,7 +439,7 @@ async function removeVideo (req: express.Request, res: express.Response) {
await videoInstance.destroy({ transaction: t })
})
auditLogger.delete(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new VideoAuditView(videoInstance.toFormattedDetailsJSON()))
auditLogger.delete(getAuditIdFromRes(res), new VideoAuditView(videoInstance.toFormattedDetailsJSON()))
logger.info('Video with name %s and uuid %s deleted.', videoInstance.name, videoInstance.uuid)
return res.type('json').status(204).end()

View File

@ -1,4 +1,5 @@
import * as path from 'path'
import * as express from 'express'
import { diff } from 'deep-object-diff'
import { chain } from 'lodash'
import * as flatten from 'flat'
@ -8,6 +9,11 @@ import { jsonLoggerFormat, labelFormatter } from './logger'
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'
import { UserModel } from '../models/account/user'
function getAuditIdFromRes (res: express.Response) {
return (res.locals.oauth.token.User as UserModel).username
}
enum AUDIT_TYPE {
CREATE = 'create',
@ -255,6 +261,8 @@ class CustomConfigAuditView extends EntityAuditView {
}
export {
getAuditIdFromRes,
auditLoggerFactory,
VideoImportAuditView,
VideoChannelAuditView,

View File

@ -6,15 +6,16 @@ import { VideoDetails } from '../../../../shared/models/videos'
import {
doubleFollow,
flushAndRunMultipleServers,
flushTests,
getFollowingListPaginationAndSort,
getVideo,
immutableAssign,
killallServers,
root,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
wait,
root, viewVideo, immutableAssign
viewVideo,
wait
} from '../../utils'
import { waitJobs } from '../../utils/server/jobs'
import * as magnetUtil from 'magnet-uri'
@ -44,12 +45,15 @@ function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: numbe
async function runServers (strategy: VideoRedundancyStrategy, additionalParams: any = {}) {
const config = {
redundancy: {
videos: [
immutableAssign({
strategy: strategy,
size: '100KB'
}, additionalParams)
]
videos: {
check_interval: '5 seconds',
strategies: [
immutableAssign({
strategy: strategy,
size: '100KB'
}, additionalParams)
]
}
}
}
servers = await flushAndRunMultipleServers(3, config)