diff options
Diffstat (limited to 'server/controllers/api/users/me.ts')
-rw-r--r-- | server/controllers/api/users/me.ts | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index e886d4b2a..ff3a87b7f 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,12 +32,13 @@ 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' |
38 | import { JobQueue } from '../../../lib/job-queue' | 39 | import { JobQueue } from '../../../lib/job-queue' |
39 | import { logger } from '../../../helpers/logger' | 40 | import { logger } from '../../../helpers/logger' |
41 | import { AccountModel } from '../../../models/account/account' | ||
40 | 42 | ||
41 | const auditLogger = auditLoggerFactory('users-me') | 43 | const auditLogger = auditLoggerFactory('users-me') |
42 | 44 | ||
@@ -293,7 +295,7 @@ async function getUserVideoQuotaUsed (req: express.Request, res: express.Respons | |||
293 | } | 295 | } |
294 | 296 | ||
295 | async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) { | 297 | async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) { |
296 | const videoId = +req.params.videoId | 298 | const videoId = res.locals.video.id |
297 | const accountId = +res.locals.oauth.token.User.Account.id | 299 | const accountId = +res.locals.oauth.token.User.Account.id |
298 | 300 | ||
299 | const ratingObj = await AccountVideoRateModel.load(accountId, videoId, null) | 301 | const ratingObj = await AccountVideoRateModel.load(accountId, videoId, null) |
@@ -311,7 +313,7 @@ async function deleteMe (req: express.Request, res: express.Response) { | |||
311 | 313 | ||
312 | await user.destroy() | 314 | await user.destroy() |
313 | 315 | ||
314 | auditLogger.delete(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new UserAuditView(user.toFormattedJSON())) | 316 | auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) |
315 | 317 | ||
316 | return res.sendStatus(204) | 318 | return res.sendStatus(204) |
317 | } | 319 | } |
@@ -328,19 +330,17 @@ async function updateMe (req: express.Request, res: express.Response, next: expr | |||
328 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo | 330 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo |
329 | 331 | ||
330 | await sequelizeTypescript.transaction(async t => { | 332 | await sequelizeTypescript.transaction(async t => { |
333 | const userAccount = await AccountModel.load(user.Account.id) | ||
334 | |||
331 | await user.save({ transaction: t }) | 335 | await user.save({ transaction: t }) |
332 | 336 | ||
333 | if (body.displayName !== undefined) user.Account.name = body.displayName | 337 | if (body.displayName !== undefined) userAccount.name = body.displayName |
334 | if (body.description !== undefined) user.Account.description = body.description | 338 | if (body.description !== undefined) userAccount.description = body.description |
335 | await user.Account.save({ transaction: t }) | 339 | await userAccount.save({ transaction: t }) |
336 | 340 | ||
337 | await sendUpdateActor(user.Account, t) | 341 | await sendUpdateActor(userAccount, t) |
338 | 342 | ||
339 | auditLogger.update( | 343 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
340 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | ||
341 | new UserAuditView(user.toFormattedJSON()), | ||
342 | oldUserAuditView | ||
343 | ) | ||
344 | }) | 344 | }) |
345 | 345 | ||
346 | return res.sendStatus(204) | 346 | return res.sendStatus(204) |
@@ -350,15 +350,12 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next | |||
350 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] | 350 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] |
351 | const user: UserModel = res.locals.oauth.token.user | 351 | const user: UserModel = res.locals.oauth.token.user |
352 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) | 352 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) |
353 | const account = user.Account | ||
354 | 353 | ||
355 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, account.Actor, account) | 354 | const userAccount = await AccountModel.load(user.Account.id) |
356 | 355 | ||
357 | auditLogger.update( | 356 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) |
358 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | 357 | |
359 | new UserAuditView(user.toFormattedJSON()), | 358 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
360 | oldUserAuditView | ||
361 | ) | ||
362 | 359 | ||
363 | return res.json({ avatar: avatar.toFormattedJSON() }) | 360 | return res.json({ avatar: avatar.toFormattedJSON() }) |
364 | } | 361 | } |