@cobuildlab/rbac
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -17,6 +17,6 @@ "use strict"; | ||
RBAC.prototype.createRule = function (roleName, permissionName, test, message) { | ||
var _a, _b; | ||
Object.assign(this.rules, (_a = {}, | ||
_a[roleName] = (_b = {}, | ||
_b[permissionName] = { | ||
var _a, _b, _c; | ||
if (this.rules[roleName]) { | ||
Object.assign(this.rules[roleName], (_a = {}, | ||
_a[permissionName] = { | ||
can: typeof test === 'boolean' ? test : undefined, | ||
@@ -26,4 +26,15 @@ dynamic: typeof test === 'function' ? test : undefined, | ||
}, | ||
_b), | ||
_a)); | ||
_a)); | ||
} | ||
else { | ||
Object.assign(this.rules, (_b = {}, | ||
_b[roleName] = (_c = {}, | ||
_c[permissionName] = { | ||
can: typeof test === 'boolean' ? test : undefined, | ||
dynamic: typeof test === 'function' ? test : undefined, | ||
message: message, | ||
}, | ||
_c), | ||
_b)); | ||
} | ||
}; | ||
@@ -30,0 +41,0 @@ /** |
{ | ||
"name": "@cobuildlab/rbac", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -11,2 +11,3 @@ import { test, expect } from '@jest/globals'; | ||
DASHBOARD = 'DASHBOARD', | ||
SETTINGS = 'SETTINGS', | ||
} | ||
@@ -23,2 +24,8 @@ | ||
staticRules.createRule( | ||
Roles.ADMIN, | ||
Permissions.SETTINGS, | ||
true, | ||
'Access granted', | ||
); | ||
staticRules.createRule( | ||
Roles.MANAGER, | ||
@@ -33,2 +40,6 @@ Permissions.DASHBOARD, | ||
]); | ||
expect(staticRules.check(Roles.ADMIN, Permissions.SETTINGS)).toStrictEqual([ | ||
true, | ||
'Access granted', | ||
]); | ||
expect( | ||
@@ -35,0 +46,0 @@ staticRules.check(Roles.MANAGER, Permissions.DASHBOARD), |
@@ -31,4 +31,4 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
): void { | ||
Object.assign(this.rules, { | ||
[roleName]: { | ||
if (this.rules[roleName]) { | ||
Object.assign(this.rules[roleName], { | ||
[permissionName]: { | ||
@@ -39,4 +39,14 @@ can: typeof test === 'boolean' ? test : undefined, | ||
}, | ||
}, | ||
}); | ||
}); | ||
} else { | ||
Object.assign(this.rules, { | ||
[roleName]: { | ||
[permissionName]: { | ||
can: typeof test === 'boolean' ? test : undefined, | ||
dynamic: typeof test === 'function' ? test : undefined, | ||
message, | ||
}, | ||
}, | ||
}); | ||
} | ||
} | ||
@@ -43,0 +53,0 @@ |
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
27239
476