1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/lib/middleware/permission-checker.js
Ivar Conradi Østhus d01c9d2dac
fix: use airbnb lint rules directly (#583)
This drops usage of finn-eslint rules as they are no
longer maintained.
2020-04-14 22:29:11 +02:00

30 lines
831 B
JavaScript

'use strict';
const MissingPermission = require('../missing-permission');
const { ADMIN } = require('../permissions');
module.exports = function(config, permission) {
if (!permission || !config.extendedPermissions) {
return (req, res, next) => next();
}
return (req, res, next) => {
if (
req.user &&
req.user.permissions &&
(req.user.permissions.indexOf(ADMIN) !== -1 ||
req.user.permissions.indexOf(permission) !== -1)
) {
return next();
}
return res
.status(403)
.json(
new MissingPermission({
permission,
message: `You require ${permission} to perform this action`,
}),
)
.end();
};
};