Files
habitica/website/server/middlewares/ensureAccessRight.js
2024-03-11 09:59:57 -05:00

22 lines
509 B
JavaScript

import {
NotAuthorized,
} from '../libs/errors';
import { apiError } from '../libs/apiError';
export function ensurePermission (permission) {
return function ensurePermissionHandler (req, res, next) {
const { user } = res.locals;
if (user.permissions.fullAccess) {
// No matter what is checked, fullAccess admins can do it
return next();
}
if (!user.permissions[permission]) {
return next(new NotAuthorized(apiError('noPrivAccess')));
}
return next();
};
}