|
1 | 1 | import { Parse } from 'parse/node'; |
2 | 2 | import PromiseRouter from '../PromiseRouter'; |
3 | 3 | import { HooksController } from '../Controllers/HooksController'; |
4 | | - |
5 | | -function enforceMasterKeyAccess(req) { |
6 | | - if (!req.auth.isMaster) { |
7 | | - throw new Parse.Error(403, "unauthorized: master key is required"); |
8 | | - } |
9 | | -} |
| 4 | +import * as middleware from "../middlewares"; |
10 | 5 |
|
11 | 6 | export class HooksRouter extends PromiseRouter { |
12 | | - |
13 | 7 | createHook(aHook, config) { |
14 | 8 | return config.hooksController.createHook(aHook).then( (hook) => ({response: hook})); |
15 | 9 | }; |
@@ -93,14 +87,14 @@ export class HooksRouter extends PromiseRouter { |
93 | 87 | } |
94 | 88 |
|
95 | 89 | mountRoutes() { |
96 | | - this.route('GET', '/hooks/functions', enforceMasterKeyAccess, this.handleGetFunctions.bind(this)); |
97 | | - this.route('GET', '/hooks/triggers', enforceMasterKeyAccess, this.handleGetTriggers.bind(this)); |
98 | | - this.route('GET', '/hooks/functions/:functionName', enforceMasterKeyAccess, this.handleGetFunctions.bind(this)); |
99 | | - this.route('GET', '/hooks/triggers/:className/:triggerName', enforceMasterKeyAccess, this.handleGetTriggers.bind(this)); |
100 | | - this.route('POST', '/hooks/functions', enforceMasterKeyAccess, this.handlePost.bind(this)); |
101 | | - this.route('POST', '/hooks/triggers', enforceMasterKeyAccess, this.handlePost.bind(this)); |
102 | | - this.route('PUT', '/hooks/functions/:functionName', enforceMasterKeyAccess, this.handlePut.bind(this)); |
103 | | - this.route('PUT', '/hooks/triggers/:className/:triggerName', enforceMasterKeyAccess, this.handlePut.bind(this)); |
| 90 | + this.route('GET', '/hooks/functions', middleware.promiseEnforceMasterKeyAccess, this.handleGetFunctions.bind(this)); |
| 91 | + this.route('GET', '/hooks/triggers', middleware.promiseEnforceMasterKeyAccess, this.handleGetTriggers.bind(this)); |
| 92 | + this.route('GET', '/hooks/functions/:functionName', middleware.promiseEnforceMasterKeyAccess, this.handleGetFunctions.bind(this)); |
| 93 | + this.route('GET', '/hooks/triggers/:className/:triggerName', middleware.promiseEnforceMasterKeyAccess, this.handleGetTriggers.bind(this)); |
| 94 | + this.route('POST', '/hooks/functions', middleware.promiseEnforceMasterKeyAccess, this.handlePost.bind(this)); |
| 95 | + this.route('POST', '/hooks/triggers', middleware.promiseEnforceMasterKeyAccess, this.handlePost.bind(this)); |
| 96 | + this.route('PUT', '/hooks/functions/:functionName', middleware.promiseEnforceMasterKeyAccess, this.handlePut.bind(this)); |
| 97 | + this.route('PUT', '/hooks/triggers/:className/:triggerName', middleware.promiseEnforceMasterKeyAccess, this.handlePut.bind(this)); |
104 | 98 | } |
105 | 99 | } |
106 | 100 |
|
|
0 commit comments