diff options
author | lutangar <johan.dufour@gmail.com> | 2021-11-24 14:33:14 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-11-25 09:54:22 +0100 |
commit | 7226e90fdc61a3c6cad5ccab18b6707d55cf0992 (patch) | |
tree | 0bdd7304352b1af2d9ae87439486a138e02d46e8 /server/controllers/api/users | |
parent | 5098098d96164c93f84ec8419e98fbd83ba8dc71 (diff) | |
download | PeerTube-7226e90fdc61a3c6cad5ccab18b6707d55cf0992.tar.gz PeerTube-7226e90fdc61a3c6cad5ccab18b6707d55cf0992.tar.zst PeerTube-7226e90fdc61a3c6cad5ccab18b6707d55cf0992.zip |
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.
Diffstat (limited to 'server/controllers/api/users')
-rw-r--r-- | server/controllers/api/users/index.ts | 12 | ||||
-rw-r--r-- | server/controllers/api/users/token.ts | 2 |
2 files changed, 7 insertions, 7 deletions
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) { | |||
212 | await Emailer.Instance.addPasswordCreateEmailJob(userToCreate.username, user.email, url) | 212 | await Emailer.Instance.addPasswordCreateEmailJob(userToCreate.username, user.email, url) |
213 | } | 213 | } |
214 | 214 | ||
215 | Hooks.runAction('action:api.user.created', { body, user, account, videoChannel }) | 215 | Hooks.runAction('action:api.user.created', { body, user, account, videoChannel, req, res }) |
216 | 216 | ||
217 | return res.json({ | 217 | return res.json({ |
218 | user: { | 218 | user: { |
@@ -254,7 +254,7 @@ async function registerUser (req: express.Request, res: express.Response) { | |||
254 | 254 | ||
255 | Notifier.Instance.notifyOnNewUserRegistration(user) | 255 | Notifier.Instance.notifyOnNewUserRegistration(user) |
256 | 256 | ||
257 | Hooks.runAction('action:api.user.registered', { body, user, account, videoChannel }) | 257 | Hooks.runAction('action:api.user.registered', { body, user, account, videoChannel, req, res }) |
258 | 258 | ||
259 | return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end() | 259 | return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end() |
260 | } | 260 | } |
@@ -264,7 +264,7 @@ async function unblockUser (req: express.Request, res: express.Response) { | |||
264 | 264 | ||
265 | await changeUserBlock(res, user, false) | 265 | await changeUserBlock(res, user, false) |
266 | 266 | ||
267 | Hooks.runAction('action:api.user.unblocked', { user }) | 267 | Hooks.runAction('action:api.user.unblocked', { user, req, res }) |
268 | 268 | ||
269 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | 269 | return res.status(HttpStatusCode.NO_CONTENT_204).end() |
270 | } | 270 | } |
@@ -275,7 +275,7 @@ async function blockUser (req: express.Request, res: express.Response) { | |||
275 | 275 | ||
276 | await changeUserBlock(res, user, true, reason) | 276 | await changeUserBlock(res, user, true, reason) |
277 | 277 | ||
278 | Hooks.runAction('action:api.user.blocked', { user }) | 278 | Hooks.runAction('action:api.user.blocked', { user, req, res }) |
279 | 279 | ||
280 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | 280 | return res.status(HttpStatusCode.NO_CONTENT_204).end() |
281 | } | 281 | } |
@@ -312,7 +312,7 @@ async function removeUser (req: express.Request, res: express.Response) { | |||
312 | await user.destroy({ transaction: t }) | 312 | await user.destroy({ transaction: t }) |
313 | }) | 313 | }) |
314 | 314 | ||
315 | Hooks.runAction('action:api.user.deleted', { user }) | 315 | Hooks.runAction('action:api.user.deleted', { user, req, res }) |
316 | 316 | ||
317 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | 317 | return res.status(HttpStatusCode.NO_CONTENT_204).end() |
318 | } | 318 | } |
@@ -345,7 +345,7 @@ async function updateUser (req: express.Request, res: express.Response) { | |||
345 | 345 | ||
346 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) | 346 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
347 | 347 | ||
348 | Hooks.runAction('action:api.user.updated', { user }) | 348 | Hooks.runAction('action:api.user.updated', { user, req, res }) |
349 | 349 | ||
350 | // Don't need to send this update to followers, these attributes are not federated | 350 | // Don't need to send this update to followers, these attributes are not federated |
351 | 351 | ||
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 | |||
66 | res.set('Cache-Control', 'no-store') | 66 | res.set('Cache-Control', 'no-store') |
67 | res.set('Pragma', 'no-cache') | 67 | res.set('Pragma', 'no-cache') |
68 | 68 | ||
69 | Hooks.runAction('action:api.user.oauth2-got-token', { username: token.user.username, ip: req.ip }) | 69 | Hooks.runAction('action:api.user.oauth2-got-token', { username: token.user.username, ip: req.ip, req, res }) |
70 | 70 | ||
71 | return res.json({ | 71 | return res.json({ |
72 | token_type: 'Bearer', | 72 | token_type: 'Bearer', |