refactor: refs #7323 improve role resolver #2989

Merged
jorgep merged 2 commits from 7323-fixResolver into master 2024-09-18 10:38:45 +00:00
2 changed files with 4 additions and 6 deletions

View File

@ -0,0 +1 @@
DELETE FROM salix.ACL WHERE model = 'Worker' AND property = 'findById' AND principalId = 'employee';

View File

@ -1,12 +1,9 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = async function(app) { module.exports = async function(app) {
const models = app.models; const models = app.models;
models.VnRole.registerResolver('$subordinate', async(role, ctx) => { models.VnRole.registerResolver('$subordinate', async(role, ctx) => {
Object.assign(ctx, {req: {accessToken: {userId: ctx.accessToken.userId}}}); if (!ctx.accessToken) return false;
const httpCtx = {req: {accessToken: {userId: ctx.accessToken.userId}}};
const isSubordinate = await models.Worker.isSubordinate(ctx, +ctx.modelId); return models.Worker.isSubordinate(httpCtx, +ctx.modelId);
if (!isSubordinate) throw new UserError(`You don't have enough privileges`);
}); });
}; };