diff --git a/api/src/services.js b/api/src/services.js index 7c48c030..43b3296e 100644 --- a/api/src/services.js +++ b/api/src/services.js @@ -2,7 +2,7 @@ import path from 'path' import fs from 'fs-extra' import { fileURLToPath } from 'url' import makeDebug from 'debug' -import kCore, { permissions, createDefaultUsers } from '@kalisio/kdk/core.api.js' +import kCore, { permissions, createDefaultUsers, decorateDistributedService } from '@kalisio/kdk/core.api.js' import kMap, { createFeaturesServiceForLayer, createDefaultCatalogLayers } from '@kalisio/kdk/map.api.js' const __dirname = path.dirname(fileURLToPath(import.meta.url)) @@ -34,22 +34,13 @@ export default async function () { app.on('service', service => { // Make remote services compliant with our internal app services so that permissions can be used if (service.key === 'weacast') { - // Remote service are registered according to their path, ie with API prefix (but without trailing /) - const remoteService = app.service(service.path) - // Get name from service path without api prefix - const name = service.path.replace(app.get('apiPath').substring(1) + '/', '') - remoteService.name = name - // As remote services have no context, from the internal point of view path = name - // Unfortunately this property is already set and used by feathers-distributed and should not be altered - // remoteService.path = name - remoteService.app = app - remoteService.getPath = function (withApiPrefix) { return (withApiPrefix ? app.get('apiPath') + '/' + name : name) } + decorateDistributedService.call(app, service) // Register default permissions for it - debug('Registering permissions for remote service ', name) + debug('Registering permissions for remote service ', service.name) permissions.defineAbilities.registerHook((subject, can, cannot) => { - can('service', name) - can('read', name) - if (name === 'probes') can('create', name) + can('service', service.name) + can('read', service.name) + if (service.name === 'probes') can('create', service.name) }) // We then need to update abilities cache const authorisationService = app.getService('authorisations')