diff options
Diffstat (limited to 'server/controllers/api/users')
-rw-r--r-- | server/controllers/api/users/index.ts | 16 | ||||
-rw-r--r-- | server/controllers/api/users/me.ts | 28 |
2 files changed, 15 insertions, 29 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index a299167e8..d1163900b 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -267,15 +267,9 @@ async function updateUser (req: express.Request, res: express.Response, next: ex | |||
267 | const user = await userToUpdate.save() | 267 | const user = await userToUpdate.save() |
268 | 268 | ||
269 | // Destroy user token to refresh rights | 269 | // Destroy user token to refresh rights |
270 | if (roleChanged) { | 270 | if (roleChanged) await OAuthTokenModel.deleteUserToken(userToUpdate.id) |
271 | await OAuthTokenModel.deleteUserToken(userToUpdate.id) | ||
272 | } | ||
273 | 271 | ||
274 | auditLogger.update( | 272 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
275 | getAuditIdFromRes(res), | ||
276 | new UserAuditView(user.toFormattedJSON()), | ||
277 | oldUserAuditView | ||
278 | ) | ||
279 | 273 | ||
280 | // Don't need to send this update to followers, these attributes are not propagated | 274 | // Don't need to send this update to followers, these attributes are not propagated |
281 | 275 | ||
@@ -343,9 +337,5 @@ async function changeUserBlock (res: express.Response, user: UserModel, block: b | |||
343 | 337 | ||
344 | await Emailer.Instance.addUserBlockJob(user, block, reason) | 338 | await Emailer.Instance.addUserBlockJob(user, block, reason) |
345 | 339 | ||
346 | auditLogger.update( | 340 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
347 | getAuditIdFromRes(res), | ||
348 | new UserAuditView(user.toFormattedJSON()), | ||
349 | oldUserAuditView | ||
350 | ) | ||
351 | } | 341 | } |
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index d4b7e3715..eba1e7edd 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -38,6 +38,7 @@ import { VideoFilter } from '../../../../shared/models/videos/video-query.type' | |||
38 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 38 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
39 | import { JobQueue } from '../../../lib/job-queue' | 39 | import { JobQueue } from '../../../lib/job-queue' |
40 | import { logger } from '../../../helpers/logger' | 40 | import { logger } from '../../../helpers/logger' |
41 | import { AccountModel } from '../../../models/account/account' | ||
41 | 42 | ||
42 | const auditLogger = auditLoggerFactory('users-me') | 43 | const auditLogger = auditLoggerFactory('users-me') |
43 | 44 | ||
@@ -329,19 +330,17 @@ async function updateMe (req: express.Request, res: express.Response, next: expr | |||
329 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo | 330 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo |
330 | 331 | ||
331 | await sequelizeTypescript.transaction(async t => { | 332 | await sequelizeTypescript.transaction(async t => { |
333 | const userAccount = await AccountModel.load(user.Account.id) | ||
334 | |||
332 | await user.save({ transaction: t }) | 335 | await user.save({ transaction: t }) |
333 | 336 | ||
334 | if (body.displayName !== undefined) user.Account.name = body.displayName | 337 | if (body.displayName !== undefined) userAccount.name = body.displayName |
335 | if (body.description !== undefined) user.Account.description = body.description | 338 | if (body.description !== undefined) userAccount.description = body.description |
336 | await user.Account.save({ transaction: t }) | 339 | await userAccount.save({ transaction: t }) |
337 | 340 | ||
338 | await sendUpdateActor(user.Account, t) | 341 | await sendUpdateActor(userAccount, t) |
339 | 342 | ||
340 | auditLogger.update( | 343 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
341 | getAuditIdFromRes(res), | ||
342 | new UserAuditView(user.toFormattedJSON()), | ||
343 | oldUserAuditView | ||
344 | ) | ||
345 | }) | 344 | }) |
346 | 345 | ||
347 | return res.sendStatus(204) | 346 | return res.sendStatus(204) |
@@ -351,15 +350,12 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next | |||
351 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] | 350 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] |
352 | const user: UserModel = res.locals.oauth.token.user | 351 | const user: UserModel = res.locals.oauth.token.user |
353 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) | 352 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) |
354 | const account = user.Account | ||
355 | 353 | ||
356 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, account.Actor, account) | 354 | const userAccount = await AccountModel.load(user.Account.id) |
357 | 355 | ||
358 | auditLogger.update( | 356 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount.Actor, userAccount) |
359 | getAuditIdFromRes(res), | 357 | |
360 | new UserAuditView(user.toFormattedJSON()), | 358 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
361 | oldUserAuditView | ||
362 | ) | ||
363 | 359 | ||
364 | return res.json({ avatar: avatar.toFormattedJSON() }) | 360 | return res.json({ avatar: avatar.toFormattedJSON() }) |
365 | } | 361 | } |