mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
d01c9d2dac
This drops usage of finn-eslint rules as they are no longer maintained.
30 lines
831 B
JavaScript
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();
|
|
};
|
|
};
|