0.0.5 • Published 6 years ago

egg-role v0.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

egg-role

role control plugin for eggjs.

Build Status codecov

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');
};

Default Configuration

Before commit your code:

cp pre-commit .git/hooks/

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago