From a6168e61f12fdaf46a15af0bcc782e02442b1aa2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 18 Sep 2024 12:19:49 +0200 Subject: [PATCH] refactor: refs #7323 improve role resolver --- db/versions/11246-whiteMonstera/00-firstScript.sql | 1 + loopback/server/boot/role-resolver.js | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) create mode 100644 db/versions/11246-whiteMonstera/00-firstScript.sql diff --git a/db/versions/11246-whiteMonstera/00-firstScript.sql b/db/versions/11246-whiteMonstera/00-firstScript.sql new file mode 100644 index 000000000..72c46cf79 --- /dev/null +++ b/db/versions/11246-whiteMonstera/00-firstScript.sql @@ -0,0 +1 @@ +DELETE FROM salix.ACL WHERE model = 'Worker' AND property = 'findById' AND principalId = 'employee'; \ No newline at end of file diff --git a/loopback/server/boot/role-resolver.js b/loopback/server/boot/role-resolver.js index cf70abb39..183d64de1 100644 --- a/loopback/server/boot/role-resolver.js +++ b/loopback/server/boot/role-resolver.js @@ -1,12 +1,9 @@ -const UserError = require('vn-loopback/util/user-error'); - module.exports = async function(app) { const models = app.models; models.VnRole.registerResolver('$subordinate', async(role, ctx) => { - Object.assign(ctx, {req: {accessToken: {userId: ctx.accessToken.userId}}}); - - const isSubordinate = await models.Worker.isSubordinate(ctx, +ctx.modelId); - if (!isSubordinate) throw new UserError(`You don't have enough privileges`); + if (!ctx.accessToken) return false; + const httpCtx = {req: {accessToken: {userId: ctx.accessToken.userId}}}; + return models.Worker.isSubordinate(httpCtx, +ctx.modelId); }); };