Comparing version 2.0.2 to 2.0.3
@@ -14,4 +14,4 @@ import { Effector } from './effect'; | ||
protected adapter: FilteredAdapter | Adapter; | ||
protected watcher: Watcher; | ||
private rm; | ||
protected watcher: Watcher | null; | ||
protected rm: RoleManager; | ||
private enabled; | ||
@@ -18,0 +18,0 @@ protected autoSave: boolean; |
@@ -37,5 +37,2 @@ "use strict"; | ||
constructor() { | ||
// @ts-ignore | ||
this.adapter = null; | ||
// @ts-ignore | ||
this.watcher = null; | ||
@@ -46,3 +43,2 @@ } | ||
this.eft = new effect_1.DefaultEffector(); | ||
// @ts-ignore | ||
this.watcher = null; | ||
@@ -49,0 +45,0 @@ this.enabled = true; |
@@ -144,2 +144,25 @@ import { ManagementEnforcer } from './managementEnforcer'; | ||
hasPermissionForUser(user: string, ...permission: string[]): boolean; | ||
/** | ||
* getImplicitRolesForUser gets implicit roles that a user has. | ||
* Compared to getRolesForUser(), this function retrieves indirect roles besides direct roles. | ||
* For example: | ||
* g, alice, role:admin | ||
* g, role:admin, role:user | ||
* | ||
* getRolesForUser("alice") can only get: ["role:admin"]. | ||
* But getImplicitRolesForUser("alice") will get: ["role:admin", "role:user"]. | ||
*/ | ||
getImplicitRolesForUser(name: string, ...domain: string[]): string[]; | ||
/** | ||
* getImplicitPermissionsForUser gets implicit permissions for a user or role. | ||
* Compared to getPermissionsForUser(), this function retrieves permissions for inherited roles. | ||
* For example: | ||
* p, admin, data1, read | ||
* p, alice, data2, read | ||
* g, alice, admin | ||
* | ||
* getPermissionsForUser("alice") can only get: [["alice", "data2", "read"]]. | ||
* But getImplicitPermissionsForUser("alice") will get: [["admin", "data1", "read"], ["alice", "data2", "read"]]. | ||
*/ | ||
getImplicitPermissionsForUser(user: string): string[][]; | ||
} |
@@ -281,3 +281,41 @@ "use strict"; | ||
} | ||
/** | ||
* getImplicitRolesForUser gets implicit roles that a user has. | ||
* Compared to getRolesForUser(), this function retrieves indirect roles besides direct roles. | ||
* For example: | ||
* g, alice, role:admin | ||
* g, role:admin, role:user | ||
* | ||
* getRolesForUser("alice") can only get: ["role:admin"]. | ||
* But getImplicitRolesForUser("alice") will get: ["role:admin", "role:user"]. | ||
*/ | ||
getImplicitRolesForUser(name, ...domain) { | ||
const res = []; | ||
const roles = this.rm.getRoles(name, ...domain); | ||
res.push(...roles); | ||
roles.forEach(n => { | ||
res.push(...this.getImplicitRolesForUser(n, ...domain)); | ||
}); | ||
return res; | ||
} | ||
/** | ||
* getImplicitPermissionsForUser gets implicit permissions for a user or role. | ||
* Compared to getPermissionsForUser(), this function retrieves permissions for inherited roles. | ||
* For example: | ||
* p, admin, data1, read | ||
* p, alice, data2, read | ||
* g, alice, admin | ||
* | ||
* getPermissionsForUser("alice") can only get: [["alice", "data2", "read"]]. | ||
* But getImplicitPermissionsForUser("alice") will get: [["admin", "data1", "read"], ["alice", "data2", "read"]]. | ||
*/ | ||
getImplicitPermissionsForUser(user) { | ||
const roles = [user, ...this.getImplicitRolesForUser(user)]; | ||
const res = []; | ||
roles.forEach(n => { | ||
res.push(...this.getPermissionsForUser(n)); | ||
}); | ||
return res; | ||
} | ||
} | ||
exports.Enforcer = Enforcer; |
@@ -38,3 +38,3 @@ "use strict"; | ||
} | ||
if (this.adapter !== null && this.autoSave) { | ||
if (this.adapter && this.autoSave) { | ||
try { | ||
@@ -48,3 +48,3 @@ yield this.adapter.addPolicy(sec, ptype, rule); | ||
} | ||
if (this.watcher !== null) { | ||
if (this.watcher) { | ||
// error intentionally ignored | ||
@@ -66,3 +66,3 @@ this.watcher.update(); | ||
} | ||
if (this.adapter !== null && this.autoSave) { | ||
if (this.adapter && this.autoSave) { | ||
try { | ||
@@ -76,3 +76,3 @@ yield this.adapter.removePolicy(sec, ptype, rule); | ||
} | ||
if (this.watcher !== null) { | ||
if (this.watcher) { | ||
// error intentionally ignored | ||
@@ -94,3 +94,3 @@ this.watcher.update(); | ||
} | ||
if (this.adapter !== null && this.autoSave) { | ||
if (this.adapter && this.autoSave) { | ||
try { | ||
@@ -104,3 +104,3 @@ yield this.adapter.removeFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues); | ||
} | ||
if (this.watcher !== null) { | ||
if (this.watcher) { | ||
// error intentionally ignored | ||
@@ -107,0 +107,0 @@ this.watcher.update(); |
@@ -66,3 +66,3 @@ "use strict"; | ||
if (!this.hasRole(name1) || !this.hasRole(name2)) { | ||
throw new Error('error: name1 or name2 does not exist'); | ||
return; | ||
} | ||
@@ -85,3 +85,3 @@ const role1 = this.createRole(name1); | ||
if (!this.hasRole(name)) { | ||
throw new Error('error: name does not exist'); | ||
return []; | ||
} | ||
@@ -106,3 +106,3 @@ let roles = this.createRole(name).getRoles(); | ||
if (!this.hasRole(name)) { | ||
throw new Error('error: name does not exist'); | ||
return []; | ||
} | ||
@@ -109,0 +109,0 @@ let users = [...this.allRoles.values()] |
{ | ||
"name": "casbin", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
169884
97
3784