|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | const apiHooks = require('@dendra-science/api-hooks-common'); |
| 4 | +const auth = require('feathers-authentication'); |
| 5 | +const authHooks = require('feathers-authentication-hooks'); |
| 6 | +const commonHooks = require('feathers-hooks-common'); |
4 | 7 | const globalHooks = require('../../../hooks'); |
5 | | -const hooks = require('feathers-hooks-common'); |
6 | 8 | const { asyncHashDigest } = require('../../../lib/utils'); |
7 | 9 | const { errors } = require('feathers-errors'); |
8 | 10 |
|
@@ -301,23 +303,29 @@ exports.computeHashes = computeHashes; // For testing |
301 | 303 | exports.before = { |
302 | 304 | // all: [], |
303 | 305 |
|
304 | | - find: apiHooks.coerceQuery(), |
| 306 | + find: [apiHooks.coerceQuery()], |
305 | 307 |
|
306 | 308 | // get: [], |
307 | 309 |
|
308 | | - create: [hooks.discard('_computed', '_elapsed', '_include'), globalHooks.validate(SCHEMA_NAME), apiHooks.timestamp(), apiHooks.coerce(), apiHooks.uniqueArray('data.tags'), computeAttributesInfo(), computeTagsInfo(), computeHashes()], |
| 310 | + create: [auth.hooks.authenticate('jwt'), authHooks.restrictToRoles({ |
| 311 | + roles: ['sys-admin'] |
| 312 | + }), commonHooks.discard('_computed', '_elapsed', '_include'), globalHooks.validate(SCHEMA_NAME), apiHooks.timestamp(), apiHooks.coerce(), apiHooks.uniqueArray('data.tags'), computeAttributesInfo(), computeTagsInfo(), computeHashes()], |
309 | 313 |
|
310 | | - update: [hooks.discard('_computed', '_elapsed', '_include'), globalHooks.validate(SCHEMA_NAME), apiHooks.timestamp(), apiHooks.coerce(), apiHooks.uniqueArray('data.tags'), computeAttributesInfo(), computeTagsInfo(), computeHashes(), hook => { |
| 314 | + update: [auth.hooks.authenticate('jwt'), authHooks.restrictToRoles({ |
| 315 | + roles: ['sys-admin'] |
| 316 | + }), commonHooks.discard('_computed', '_elapsed', '_include'), globalHooks.validate(SCHEMA_NAME), apiHooks.timestamp(), apiHooks.coerce(), apiHooks.uniqueArray('data.tags'), computeAttributesInfo(), computeTagsInfo(), computeHashes(), hook => { |
311 | 317 | // TODO: Optimize with find/$select to return fewer fields? |
312 | 318 | return hook.app.service('/datastreams').get(hook.id).then(doc => { |
313 | 319 | hook.data.created_at = doc.created_at; |
314 | 320 | return hook; |
315 | 321 | }); |
316 | 322 | }], |
317 | 323 |
|
318 | | - patch: hooks.disallow('rest') |
| 324 | + patch: [commonHooks.disallow('rest')], |
319 | 325 |
|
320 | | - // remove: [] |
| 326 | + remove: [auth.hooks.authenticate('jwt'), authHooks.restrictToRoles({ |
| 327 | + roles: ['sys-admin'] |
| 328 | + })] |
321 | 329 | }; |
322 | 330 |
|
323 | 331 | const uomSchema = { |
@@ -350,7 +358,7 @@ const preferredUomsSchema = { |
350 | 358 | }; |
351 | 359 |
|
352 | 360 | exports.after = { |
353 | | - all: [hooks.populate({ schema: uomSchema }), hooks.populate({ schema: convertibleToUomsSchema }), hooks.populate({ schema: preferredUomsSchema })] |
| 361 | + all: [commonHooks.populate({ schema: uomSchema }), commonHooks.populate({ schema: convertibleToUomsSchema }), commonHooks.populate({ schema: preferredUomsSchema })] |
354 | 362 |
|
355 | 363 | // find: [], |
356 | 364 | // get: [], |
|
0 commit comments