mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-26 21:24:08 +00:00
21 lines
509 B
JavaScript
21 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();
|
|
};
|
|
}
|