diff options
author | Aurélien Bertron <aurelienbertron@gmail.com> | 2018-07-31 14:04:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-31 15:40:29 +0200 |
commit | 80e36cd9facb56b330be3e4f1c5ba253cc78c308 (patch) | |
tree | 807d8a642ae99ec3f05597e19ebe1ca5dc849582 /server/controllers/api/video-channel.ts | |
parent | 59390818384baa0ffc0cb71af2e67350c6b39172 (diff) | |
download | PeerTube-80e36cd9facb56b330be3e4f1c5ba253cc78c308.tar.gz PeerTube-80e36cd9facb56b330be3e4f1c5ba253cc78c308.tar.zst PeerTube-80e36cd9facb56b330be3e4f1c5ba253cc78c308.zip |
Add audit logs in various modules
- Videos
- Videos comments
- Users
- Videos channels
- Videos abuses
- Custom config
Diffstat (limited to 'server/controllers/api/video-channel.ts')
-rw-r--r-- | server/controllers/api/video-channel.ts | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index 0488ba8f5..3a444547b 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts | |||
@@ -27,7 +27,9 @@ import { logger } from '../../helpers/logger' | |||
27 | import { VideoModel } from '../../models/video/video' | 27 | import { VideoModel } from '../../models/video/video' |
28 | import { updateAvatarValidator } from '../../middlewares/validators/avatar' | 28 | import { updateAvatarValidator } from '../../middlewares/validators/avatar' |
29 | import { updateActorAvatarFile } from '../../lib/avatar' | 29 | import { updateActorAvatarFile } from '../../lib/avatar' |
30 | import { auditLoggerFactory, VideoChannelAuditView } from '../../helpers/audit-logger' | ||
30 | 31 | ||
32 | const auditLogger = auditLoggerFactory('channels') | ||
31 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) | 33 | const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR }) |
32 | 34 | ||
33 | const videoChannelRouter = express.Router() | 35 | const videoChannelRouter = express.Router() |
@@ -99,10 +101,17 @@ async function listVideoChannels (req: express.Request, res: express.Response, n | |||
99 | 101 | ||
100 | async function updateVideoChannelAvatar (req: express.Request, res: express.Response, next: express.NextFunction) { | 102 | async function updateVideoChannelAvatar (req: express.Request, res: express.Response, next: express.NextFunction) { |
101 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] | 103 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] |
102 | const videoChannel = res.locals.videoChannel | 104 | const videoChannel = res.locals.videoChannel as VideoChannelModel |
105 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON()) | ||
103 | 106 | ||
104 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel.Actor, videoChannel) | 107 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel.Actor, videoChannel) |
105 | 108 | ||
109 | auditLogger.update( | ||
110 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | ||
111 | new VideoChannelAuditView(videoChannel.toFormattedJSON()), | ||
112 | oldVideoChannelAuditKeys | ||
113 | ) | ||
114 | |||
106 | return res | 115 | return res |
107 | .json({ | 116 | .json({ |
108 | avatar: avatar.toFormattedJSON() | 117 | avatar: avatar.toFormattedJSON() |
@@ -121,6 +130,10 @@ async function addVideoChannel (req: express.Request, res: express.Response) { | |||
121 | setAsyncActorKeys(videoChannelCreated.Actor) | 130 | setAsyncActorKeys(videoChannelCreated.Actor) |
122 | .catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, { err })) | 131 | .catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, { err })) |
123 | 132 | ||
133 | auditLogger.create( | ||
134 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | ||
135 | new VideoChannelAuditView(videoChannelCreated.toFormattedJSON()) | ||
136 | ) | ||
124 | logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid) | 137 | logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid) |
125 | 138 | ||
126 | return res.json({ | 139 | return res.json({ |
@@ -134,6 +147,7 @@ async function addVideoChannel (req: express.Request, res: express.Response) { | |||
134 | async function updateVideoChannel (req: express.Request, res: express.Response) { | 147 | async function updateVideoChannel (req: express.Request, res: express.Response) { |
135 | const videoChannelInstance = res.locals.videoChannel as VideoChannelModel | 148 | const videoChannelInstance = res.locals.videoChannel as VideoChannelModel |
136 | const videoChannelFieldsSave = videoChannelInstance.toJSON() | 149 | const videoChannelFieldsSave = videoChannelInstance.toJSON() |
150 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()) | ||
137 | const videoChannelInfoToUpdate = req.body as VideoChannelUpdate | 151 | const videoChannelInfoToUpdate = req.body as VideoChannelUpdate |
138 | 152 | ||
139 | try { | 153 | try { |
@@ -148,9 +162,14 @@ async function updateVideoChannel (req: express.Request, res: express.Response) | |||
148 | 162 | ||
149 | const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions) | 163 | const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions) |
150 | await sendUpdateActor(videoChannelInstanceUpdated, t) | 164 | await sendUpdateActor(videoChannelInstanceUpdated, t) |
151 | }) | ||
152 | 165 | ||
153 | logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) | 166 | auditLogger.update( |
167 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | ||
168 | new VideoChannelAuditView(videoChannelInstanceUpdated.toFormattedJSON()), | ||
169 | oldVideoChannelAuditKeys | ||
170 | ) | ||
171 | logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) | ||
172 | }) | ||
154 | } catch (err) { | 173 | } catch (err) { |
155 | logger.debug('Cannot update the video channel.', { err }) | 174 | logger.debug('Cannot update the video channel.', { err }) |
156 | 175 | ||
@@ -171,6 +190,10 @@ async function removeVideoChannel (req: express.Request, res: express.Response) | |||
171 | await sequelizeTypescript.transaction(async t => { | 190 | await sequelizeTypescript.transaction(async t => { |
172 | await videoChannelInstance.destroy({ transaction: t }) | 191 | await videoChannelInstance.destroy({ transaction: t }) |
173 | 192 | ||
193 | auditLogger.delete( | ||
194 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | ||
195 | new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()) | ||
196 | ) | ||
174 | logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) | 197 | logger.info('Video channel with name %s and uuid %s deleted.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) |
175 | }) | 198 | }) |
176 | 199 | ||