Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

egg-rbac

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-rbac - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

19

app/middleware/rbac.js

@@ -8,17 +8,6 @@ 'use strict';

return function* rbac(next) {
// this is instance of Context
// TODO support session
let permissions;
if (!this.session.permission) {
const roleName = yield options.getRoleName(this);
if (roleName) {
permissions = yield this.app.rbac.getRolePermission(roleName);
this.role = new Role(roleName, permissions);
this.session.permission = {
roleName,
permissions,
};
}
} else {
this.role = new Role(this.session.permission.roleName, this.session.permission.permissions);
const roleName = yield options.getRoleName(this);
if (roleName) {
const permissions = yield this.app.rbac.getRolePermission(roleName);
this.role = new Role(roleName, permissions);
}

@@ -25,0 +14,0 @@

@@ -17,2 +17,6 @@ 'use strict';

},
superRole: {
name: 'superrole',
alias: '超级管理员',
},
};

@@ -29,3 +29,3 @@ 'use strict';

const data = require(appRbacFilePath);
return this.initData(data.permissions, data.roles);
return this.initData(data.permissions, data.roles, app.config.rbac.superRole);
}

@@ -45,6 +45,9 @@ });

* @param {string} roles[].alias - role alias
* @param {object} superRole super role info
* @param {string} superRole.name role name
* @param {string} superRole.alias role alias
* @return {object} error object
* @yields {boolean}
*/
initData(permissions, roles) {
initData(permissions, roles, superRole) {
if (!permissions || permissions.length === 0) {

@@ -59,3 +62,3 @@ throw new Error('[egg-rbac] initData parameter permissions is undefined');

return this._initPermissions(permissions)
.then(() => this._initRole(roles));
.then(() => this._initRole(roles, superRole));
}

@@ -100,5 +103,8 @@

* @param {string} roles[].alias - role alias
* @param {object} superRole super role info
* @param {string} superRole.name role name
* @param {string} superRole.alias role alias
* @return {object} promise
*/
_initRole(roles) {
_initRole(roles, superRole) {
const arr = roles.map(roleData => {

@@ -120,6 +126,6 @@ return Promise.all([

this.getAllPermission().then(allPermission => allPermission.map(per => per._id)),
this.storage.getRole('superadmin'),
this.storage.getRole(superRole.name),
]).then(([ ids, admin ]) => {
if (admin === null) {
return this.newRole({ name: 'superadmin', alias: '超级管理员', grants: ids });
return this.newRole({ name: superRole.name, alias: superRole.alias, grants: ids });
}

@@ -126,0 +132,0 @@ return this.addPermission(admin._id, ids);

{
"name": "egg-rbac",
"version": "0.2.0",
"version": "0.3.0",
"description": "Role Based Access Control for eggjs",

@@ -17,3 +17,5 @@ "eggPlugin": {

],
"dependencies": {},
"dependencies": {
"debug": "^3.1.0"
},
"devDependencies": {

@@ -23,3 +25,2 @@ "autod": "^2.10.1",

"await-event": "^2.1.0",
"debug": "^3.1.0",
"egg": "^1.10.0",

@@ -26,0 +27,0 @@ "egg-bin": "^4.3.5",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc