aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/users/index.ts')
-rw-r--r--server/controllers/api/users/index.ts32
1 files changed, 13 insertions, 19 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 07edf3727..8b8ebcd23 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -27,13 +27,17 @@ import {
27 usersUpdateValidator 27 usersUpdateValidator
28} from '../../../middlewares' 28} from '../../../middlewares'
29import { 29import {
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'
33import { UserModel } from '../../../models/account/user' 36import { UserModel } from '../../../models/account/user'
34import { OAuthTokenModel } from '../../../models/oauth/oauth-token' 37import { OAuthTokenModel } from '../../../models/oauth/oauth-token'
35import { auditLoggerFactory, UserAuditView } from '../../../helpers/audit-logger' 38import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger'
36import { meRouter } from './me' 39import { meRouter } from './me'
40import { deleteUserToken } from '../../../lib/oauth-model'
37 41
38const auditLogger = auditLoggerFactory('users') 42const auditLogger = auditLoggerFactory('users')
39 43
@@ -166,7 +170,7 @@ async function createUser (req: express.Request, res: express.Response) {
166 170
167 const { user, account } = await createUserAccountAndChannel(userToCreate) 171 const { user, account } = await createUserAccountAndChannel(userToCreate)
168 172
169 auditLogger.create(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new UserAuditView(user.toFormattedJSON())) 173 auditLogger.create(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
170 logger.info('User %s with its channel and account created.', body.username) 174 logger.info('User %s with its channel and account created.', body.username)
171 175
172 return res.json({ 176 return res.json({
@@ -245,7 +249,7 @@ async function removeUser (req: express.Request, res: express.Response, next: ex
245 249
246 await user.destroy() 250 await user.destroy()
247 251
248 auditLogger.delete(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new UserAuditView(user.toFormattedJSON())) 252 auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
249 253
250 return res.sendStatus(204) 254 return res.sendStatus(204)
251} 255}
@@ -264,15 +268,9 @@ async function updateUser (req: express.Request, res: express.Response, next: ex
264 const user = await userToUpdate.save() 268 const user = await userToUpdate.save()
265 269
266 // Destroy user token to refresh rights 270 // Destroy user token to refresh rights
267 if (roleChanged) { 271 if (roleChanged) await deleteUserToken(userToUpdate.id)
268 await OAuthTokenModel.deleteUserToken(userToUpdate.id)
269 }
270 272
271 auditLogger.update( 273 auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView)
272 res.locals.oauth.token.User.Account.Actor.getIdentifier(),
273 new UserAuditView(user.toFormattedJSON()),
274 oldUserAuditView
275 )
276 274
277 // Don't need to send this update to followers, these attributes are not propagated 275 // Don't need to send this update to followers, these attributes are not propagated
278 276
@@ -333,16 +331,12 @@ async function changeUserBlock (res: express.Response, user: UserModel, block: b
333 user.blockedReason = reason || null 331 user.blockedReason = reason || null
334 332
335 await sequelizeTypescript.transaction(async t => { 333 await sequelizeTypescript.transaction(async t => {
336 await OAuthTokenModel.deleteUserToken(user.id, t) 334 await deleteUserToken(user.id, t)
337 335
338 await user.save({ transaction: t }) 336 await user.save({ transaction: t })
339 }) 337 })
340 338
341 await Emailer.Instance.addUserBlockJob(user, block, reason) 339 await Emailer.Instance.addUserBlockJob(user, block, reason)
342 340
343 auditLogger.update( 341 auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView)
344 res.locals.oauth.token.User.Account.Actor.getIdentifier(),
345 new UserAuditView(user.toFormattedJSON()),
346 oldUserAuditView
347 )
348} 342}