refactor: refs #7323 improve role resolver
gitea/salix/pipeline/pr-master Build queued... Details

This commit is contained in:
Jorge Penadés 2024-09-18 12:19:49 +02:00
parent 91ee956fbd
commit a6168e61f1
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) {
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);
});
};