0.0.5 • Published 6 years ago
egg-role v0.0.5
egg-role
role control plugin for eggjs.
Feature:
- All access controls are based on configuration.
- According to the application's own ctx.getRoles function to get the current user's role, the plugin itself does not provide the role management function.
- Can control access to router, service, etc.
- Custom access error information based on egg-i18n.
Configuration:
exports.role = {
get: 'getRoles', // this is default value, we will fetch user roles by 'ctx.getRoles';
policy: {
'user_admin': [ // role is 'user_admin'
'router:updateUser', // the role can access router which name is 'updateUser'
'service:user.listUsers' // the role can access service which name is 'user.listUsers' ignoring what the router is.
],
'comment_inspector': [
'router:denyComment',
'router:stickComment',
'service:comment.listComments'
]
}
};
JSON format policy Example
exports.role = {
policy: path.join(__dirname, 'policy.json');
};
yaml format policy Example
exports.role = {
policy: path.join(__dirname, 'policy.yaml');
};
Before commit your code:
cp pre-commit .git/hooks/