refactor: refs #7323 improve role resolver #2989
|
@ -0,0 +1 @@
|
|||
DELETE FROM salix.ACL WHERE model = 'Worker' AND property = 'findById' AND principalId = 'employee';
|
|
@ -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);
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue