diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-19 17:02:16 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-19 17:02:27 +0200 |
commit | 993cef4b6e000ee425087e5195dfe40cd0840243 (patch) | |
tree | 9bddf4a2f4fad0ac8cbb9d79445c1c1ec36bd305 /server/controllers/api/users | |
parent | 606c946e74211c4123b16087288902226306198d (diff) | |
download | PeerTube-993cef4b6e000ee425087e5195dfe40cd0840243.tar.gz PeerTube-993cef4b6e000ee425087e5195dfe40cd0840243.tar.zst PeerTube-993cef4b6e000ee425087e5195dfe40cd0840243.zip |
Refractor audit user identifier
Diffstat (limited to 'server/controllers/api/users')
-rw-r--r-- | server/controllers/api/users/index.ts | 17 | ||||
-rw-r--r-- | server/controllers/api/users/me.ts | 15 |
2 files changed, 18 insertions, 14 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index 07edf3727..a299167e8 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -27,12 +27,15 @@ import { | |||
27 | usersUpdateValidator | 27 | usersUpdateValidator |
28 | } from '../../../middlewares' | 28 | } from '../../../middlewares' |
29 | import { | 29 | import { |
30 | usersAskResetPasswordValidator, usersBlockingValidator, usersResetPasswordValidator, | 30 | usersAskResetPasswordValidator, |
31 | usersAskSendVerifyEmailValidator, usersVerifyEmailValidator | 31 | usersAskSendVerifyEmailValidator, |
32 | usersBlockingValidator, | ||
33 | usersResetPasswordValidator, | ||
34 | usersVerifyEmailValidator | ||
32 | } from '../../../middlewares/validators' | 35 | } from '../../../middlewares/validators' |
33 | import { UserModel } from '../../../models/account/user' | 36 | import { UserModel } from '../../../models/account/user' |
34 | import { OAuthTokenModel } from '../../../models/oauth/oauth-token' | 37 | import { OAuthTokenModel } from '../../../models/oauth/oauth-token' |
35 | import { auditLoggerFactory, UserAuditView } from '../../../helpers/audit-logger' | 38 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' |
36 | import { meRouter } from './me' | 39 | import { meRouter } from './me' |
37 | 40 | ||
38 | const auditLogger = auditLoggerFactory('users') | 41 | const auditLogger = auditLoggerFactory('users') |
@@ -166,7 +169,7 @@ async function createUser (req: express.Request, res: express.Response) { | |||
166 | 169 | ||
167 | const { user, account } = await createUserAccountAndChannel(userToCreate) | 170 | const { user, account } = await createUserAccountAndChannel(userToCreate) |
168 | 171 | ||
169 | auditLogger.create(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new UserAuditView(user.toFormattedJSON())) | 172 | auditLogger.create(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) |
170 | logger.info('User %s with its channel and account created.', body.username) | 173 | logger.info('User %s with its channel and account created.', body.username) |
171 | 174 | ||
172 | return res.json({ | 175 | return res.json({ |
@@ -245,7 +248,7 @@ async function removeUser (req: express.Request, res: express.Response, next: ex | |||
245 | 248 | ||
246 | await user.destroy() | 249 | await user.destroy() |
247 | 250 | ||
248 | auditLogger.delete(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new UserAuditView(user.toFormattedJSON())) | 251 | auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) |
249 | 252 | ||
250 | return res.sendStatus(204) | 253 | return res.sendStatus(204) |
251 | } | 254 | } |
@@ -269,7 +272,7 @@ async function updateUser (req: express.Request, res: express.Response, next: ex | |||
269 | } | 272 | } |
270 | 273 | ||
271 | auditLogger.update( | 274 | auditLogger.update( |
272 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | 275 | getAuditIdFromRes(res), |
273 | new UserAuditView(user.toFormattedJSON()), | 276 | new UserAuditView(user.toFormattedJSON()), |
274 | oldUserAuditView | 277 | oldUserAuditView |
275 | ) | 278 | ) |
@@ -341,7 +344,7 @@ async function changeUserBlock (res: express.Response, user: UserModel, block: b | |||
341 | await Emailer.Instance.addUserBlockJob(user, block, reason) | 344 | await Emailer.Instance.addUserBlockJob(user, block, reason) |
342 | 345 | ||
343 | auditLogger.update( | 346 | auditLogger.update( |
344 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | 347 | getAuditIdFromRes(res), |
345 | new UserAuditView(user.toFormattedJSON()), | 348 | new UserAuditView(user.toFormattedJSON()), |
346 | oldUserAuditView | 349 | oldUserAuditView |
347 | ) | 350 | ) |
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index 113563c39..d4b7e3715 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -5,7 +5,8 @@ import { getFormattedObjects } from '../../../helpers/utils' | |||
5 | import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../../initializers' | 5 | import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../../initializers' |
6 | import { sendUpdateActor } from '../../../lib/activitypub/send' | 6 | import { sendUpdateActor } from '../../../lib/activitypub/send' |
7 | import { | 7 | import { |
8 | asyncMiddleware, asyncRetryTransactionMiddleware, | 8 | asyncMiddleware, |
9 | asyncRetryTransactionMiddleware, | ||
9 | authenticate, | 10 | authenticate, |
10 | commonVideosFiltersValidator, | 11 | commonVideosFiltersValidator, |
11 | paginationValidator, | 12 | paginationValidator, |
@@ -17,11 +18,11 @@ import { | |||
17 | usersVideoRatingValidator | 18 | usersVideoRatingValidator |
18 | } from '../../../middlewares' | 19 | } from '../../../middlewares' |
19 | import { | 20 | import { |
21 | areSubscriptionsExistValidator, | ||
20 | deleteMeValidator, | 22 | deleteMeValidator, |
21 | userSubscriptionsSortValidator, | 23 | userSubscriptionsSortValidator, |
22 | videoImportsSortValidator, | 24 | videoImportsSortValidator, |
23 | videosSortValidator, | 25 | videosSortValidator |
24 | areSubscriptionsExistValidator | ||
25 | } from '../../../middlewares/validators' | 26 | } from '../../../middlewares/validators' |
26 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 27 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
27 | import { UserModel } from '../../../models/account/user' | 28 | import { UserModel } from '../../../models/account/user' |
@@ -31,7 +32,7 @@ import { buildNSFWFilter, createReqFiles } from '../../../helpers/express-utils' | |||
31 | import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model' | 32 | import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model' |
32 | import { updateAvatarValidator } from '../../../middlewares/validators/avatar' | 33 | import { updateAvatarValidator } from '../../../middlewares/validators/avatar' |
33 | import { updateActorAvatarFile } from '../../../lib/avatar' | 34 | import { updateActorAvatarFile } from '../../../lib/avatar' |
34 | import { auditLoggerFactory, UserAuditView } from '../../../helpers/audit-logger' | 35 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' |
35 | import { VideoImportModel } from '../../../models/video/video-import' | 36 | import { VideoImportModel } from '../../../models/video/video-import' |
36 | import { VideoFilter } from '../../../../shared/models/videos/video-query.type' | 37 | import { VideoFilter } from '../../../../shared/models/videos/video-query.type' |
37 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 38 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
@@ -311,7 +312,7 @@ async function deleteMe (req: express.Request, res: express.Response) { | |||
311 | 312 | ||
312 | await user.destroy() | 313 | await user.destroy() |
313 | 314 | ||
314 | auditLogger.delete(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new UserAuditView(user.toFormattedJSON())) | 315 | auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) |
315 | 316 | ||
316 | return res.sendStatus(204) | 317 | return res.sendStatus(204) |
317 | } | 318 | } |
@@ -337,7 +338,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr | |||
337 | await sendUpdateActor(user.Account, t) | 338 | await sendUpdateActor(user.Account, t) |
338 | 339 | ||
339 | auditLogger.update( | 340 | auditLogger.update( |
340 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | 341 | getAuditIdFromRes(res), |
341 | new UserAuditView(user.toFormattedJSON()), | 342 | new UserAuditView(user.toFormattedJSON()), |
342 | oldUserAuditView | 343 | oldUserAuditView |
343 | ) | 344 | ) |
@@ -355,7 +356,7 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next | |||
355 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, account.Actor, account) | 356 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, account.Actor, account) |
356 | 357 | ||
357 | auditLogger.update( | 358 | auditLogger.update( |
358 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | 359 | getAuditIdFromRes(res), |
359 | new UserAuditView(user.toFormattedJSON()), | 360 | new UserAuditView(user.toFormattedJSON()), |
360 | oldUserAuditView | 361 | oldUserAuditView |
361 | ) | 362 | ) |