casbin 5.13.1 → 5.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [5.14.0](https://github.com/casbin/node-casbin/compare/v5.13.2...v5.14.0) (2022-03-18)
2
+
3
+
4
+ ### Features
5
+
6
+ * **rbac:** add `getUsersForRoleInDomain` & `getRolesForUserInDomain` ([#351](https://github.com/casbin/node-casbin/issues/351)) ([4896ca2](https://github.com/casbin/node-casbin/commit/4896ca260c2f35672b9b520969898155ec616f0b)), closes [#304](https://github.com/casbin/node-casbin/issues/304)
7
+
8
+ ## [5.13.2](https://github.com/casbin/node-casbin/compare/v5.13.1...v5.13.2) (2022-03-02)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * *matcher result should be boolean or number* for KeyGet2 ([#347](https://github.com/casbin/node-casbin/issues/347)) ([0257078](https://github.com/casbin/node-casbin/commit/0257078e1302f5ef081ec143afe5c470f4f862e9))
14
+
1
15
  ## [5.13.1](https://github.com/casbin/node-casbin/compare/v5.13.0...v5.13.1) (2022-02-22)
2
16
 
3
17
 
@@ -0,0 +1,11 @@
1
+ [request_definition]
2
+ r = sub, obj
3
+
4
+ [policy_definition]
5
+ p = sub, obj
6
+
7
+ [policy_effect]
8
+ e = some(where (p.eft == allow))
9
+
10
+ [matchers]
11
+ m = keyGet2(r.obj, p.obj, 'id')
@@ -0,0 +1 @@
1
+ p, alice, /data/:id
@@ -387,8 +387,16 @@ class CoreEnforcer {
387
387
  eftRes = result;
388
388
  }
389
389
  break;
390
+ case 'string':
391
+ if (result === '') {
392
+ eftRes = effect_1.Effect.Indeterminate;
393
+ }
394
+ else {
395
+ eftRes = effect_1.Effect.Allow;
396
+ }
397
+ break;
390
398
  default:
391
- throw new Error('matcher result should be boolean or number');
399
+ throw new Error('matcher result should only be of type boolean, number, or string');
392
400
  }
393
401
  const eft = parameters['p_eft'];
394
402
  if (eft && eftRes === effect_1.Effect.Allow) {
@@ -186,6 +186,24 @@ export declare class Enforcer extends ManagementEnforcer {
186
186
  * But getImplicitUsersForRole("user") will get: ["role:admin", "alice"].
187
187
  */
188
188
  getImplicitUsersForRole(role: string, ...domain: string[]): Promise<string[]>;
189
+ /**
190
+ * getRolesForUserInDomain gets the roles that a user has inside a domain
191
+ * An alias for getRolesForUser with the domain params.
192
+ *
193
+ * @param name the user.
194
+ * @param domain the domain.
195
+ * @return the roles that the user has.
196
+ */
197
+ getRolesForUserInDomain(name: string, domain: string): Promise<string[]>;
198
+ /**
199
+ * getUsersForRoleInFomain gets the users that has a role inside a domain
200
+ * An alias for getUsesForRole with the domain params.
201
+ *
202
+ * @param name the role.
203
+ * @param domain the domain.
204
+ * @return the users that has the role.
205
+ */
206
+ getUsersForRoleInDomain(name: string, domain: string): Promise<string[]>;
189
207
  /**
190
208
  * getImplicitUsersForPermission gets implicit users for a permission.
191
209
  * For example:
@@ -348,6 +348,28 @@ class Enforcer extends managementEnforcer_1.ManagementEnforcer {
348
348
  }
349
349
  return Array.from(res);
350
350
  }
351
+ /**
352
+ * getRolesForUserInDomain gets the roles that a user has inside a domain
353
+ * An alias for getRolesForUser with the domain params.
354
+ *
355
+ * @param name the user.
356
+ * @param domain the domain.
357
+ * @return the roles that the user has.
358
+ */
359
+ async getRolesForUserInDomain(name, domain) {
360
+ return this.getRolesForUser(name, domain);
361
+ }
362
+ /**
363
+ * getUsersForRoleInFomain gets the users that has a role inside a domain
364
+ * An alias for getUsesForRole with the domain params.
365
+ *
366
+ * @param name the role.
367
+ * @param domain the domain.
368
+ * @return the users that has the role.
369
+ */
370
+ async getUsersForRoleInDomain(name, domain) {
371
+ return this.getUsersForRole(name, domain);
372
+ }
351
373
  /**
352
374
  * getImplicitUsersForPermission gets implicit users for a permission.
353
375
  * For example:
@@ -384,8 +384,16 @@ export class CoreEnforcer {
384
384
  eftRes = result;
385
385
  }
386
386
  break;
387
+ case 'string':
388
+ if (result === '') {
389
+ eftRes = Effect.Indeterminate;
390
+ }
391
+ else {
392
+ eftRes = Effect.Allow;
393
+ }
394
+ break;
387
395
  default:
388
- throw new Error('matcher result should be boolean or number');
396
+ throw new Error('matcher result should only be of type boolean, number, or string');
389
397
  }
390
398
  const eft = parameters['p_eft'];
391
399
  if (eft && eftRes === Effect.Allow) {
@@ -186,6 +186,24 @@ export declare class Enforcer extends ManagementEnforcer {
186
186
  * But getImplicitUsersForRole("user") will get: ["role:admin", "alice"].
187
187
  */
188
188
  getImplicitUsersForRole(role: string, ...domain: string[]): Promise<string[]>;
189
+ /**
190
+ * getRolesForUserInDomain gets the roles that a user has inside a domain
191
+ * An alias for getRolesForUser with the domain params.
192
+ *
193
+ * @param name the user.
194
+ * @param domain the domain.
195
+ * @return the roles that the user has.
196
+ */
197
+ getRolesForUserInDomain(name: string, domain: string): Promise<string[]>;
198
+ /**
199
+ * getUsersForRoleInFomain gets the users that has a role inside a domain
200
+ * An alias for getUsesForRole with the domain params.
201
+ *
202
+ * @param name the role.
203
+ * @param domain the domain.
204
+ * @return the users that has the role.
205
+ */
206
+ getUsersForRoleInDomain(name: string, domain: string): Promise<string[]>;
189
207
  /**
190
208
  * getImplicitUsersForPermission gets implicit users for a permission.
191
209
  * For example:
@@ -345,6 +345,28 @@ export class Enforcer extends ManagementEnforcer {
345
345
  }
346
346
  return Array.from(res);
347
347
  }
348
+ /**
349
+ * getRolesForUserInDomain gets the roles that a user has inside a domain
350
+ * An alias for getRolesForUser with the domain params.
351
+ *
352
+ * @param name the user.
353
+ * @param domain the domain.
354
+ * @return the roles that the user has.
355
+ */
356
+ async getRolesForUserInDomain(name, domain) {
357
+ return this.getRolesForUser(name, domain);
358
+ }
359
+ /**
360
+ * getUsersForRoleInFomain gets the users that has a role inside a domain
361
+ * An alias for getUsesForRole with the domain params.
362
+ *
363
+ * @param name the role.
364
+ * @param domain the domain.
365
+ * @return the users that has the role.
366
+ */
367
+ async getUsersForRoleInDomain(name, domain) {
368
+ return this.getUsersForRole(name, domain);
369
+ }
348
370
  /**
349
371
  * getImplicitUsersForPermission gets implicit users for a permission.
350
372
  * For example:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "casbin",
3
- "version": "5.13.1",
3
+ "version": "5.14.0",
4
4
  "description": "An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS",
5
5
  "main": "lib/cjs/index.js",
6
6
  "typings": "lib/cjs/index.d.ts",