From 7226e90fdc61a3c6cad5ccab18b6707d55cf0992 Mon Sep 17 00:00:00 2001 From: lutangar Date: Wed, 24 Nov 2021 14:33:14 +0100 Subject: Add `req` and `res` as controllers hooks parameters Hooks prefixed by `action:api` now give access the original express req and res. Checkout guide.md for possible usage. --- server/controllers/api/users/index.ts | 12 ++++++------ server/controllers/api/users/token.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'server/controllers/api/users') diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index bc47e5fec..11d3525e4 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts @@ -212,7 +212,7 @@ async function createUser (req: express.Request, res: express.Response) { await Emailer.Instance.addPasswordCreateEmailJob(userToCreate.username, user.email, url) } - Hooks.runAction('action:api.user.created', { body, user, account, videoChannel }) + Hooks.runAction('action:api.user.created', { body, user, account, videoChannel, req, res }) return res.json({ user: { @@ -254,7 +254,7 @@ async function registerUser (req: express.Request, res: express.Response) { Notifier.Instance.notifyOnNewUserRegistration(user) - Hooks.runAction('action:api.user.registered', { body, user, account, videoChannel }) + Hooks.runAction('action:api.user.registered', { body, user, account, videoChannel, req, res }) return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end() } @@ -264,7 +264,7 @@ async function unblockUser (req: express.Request, res: express.Response) { await changeUserBlock(res, user, false) - Hooks.runAction('action:api.user.unblocked', { user }) + Hooks.runAction('action:api.user.unblocked', { user, req, res }) return res.status(HttpStatusCode.NO_CONTENT_204).end() } @@ -275,7 +275,7 @@ async function blockUser (req: express.Request, res: express.Response) { await changeUserBlock(res, user, true, reason) - Hooks.runAction('action:api.user.blocked', { user }) + Hooks.runAction('action:api.user.blocked', { user, req, res }) return res.status(HttpStatusCode.NO_CONTENT_204).end() } @@ -312,7 +312,7 @@ async function removeUser (req: express.Request, res: express.Response) { await user.destroy({ transaction: t }) }) - Hooks.runAction('action:api.user.deleted', { user }) + Hooks.runAction('action:api.user.deleted', { user, req, res }) return res.status(HttpStatusCode.NO_CONTENT_204).end() } @@ -345,7 +345,7 @@ async function updateUser (req: express.Request, res: express.Response) { auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) - Hooks.runAction('action:api.user.updated', { user }) + Hooks.runAction('action:api.user.updated', { user, req, res }) // Don't need to send this update to followers, these attributes are not federated diff --git a/server/controllers/api/users/token.ts b/server/controllers/api/users/token.ts index d5dbe921c..1d4004ce0 100644 --- a/server/controllers/api/users/token.ts +++ b/server/controllers/api/users/token.ts @@ -66,7 +66,7 @@ async function handleToken (req: express.Request, res: express.Response, next: e res.set('Cache-Control', 'no-store') res.set('Pragma', 'no-cache') - Hooks.runAction('action:api.user.oauth2-got-token', { username: token.user.username, ip: req.ip }) + Hooks.runAction('action:api.user.oauth2-got-token', { username: token.user.username, ip: req.ip, req, res }) return res.json({ token_type: 'Bearer', -- cgit v1.2.3