Merge pull request 'refactor: refs #7323 improve role resolver' (!2989) from 7323-fixResolver into master
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2989
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Jorge Penadés 2024-09-18 10:38:44 +00:00
commit 4068cfe5da
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);
});
};