node-casbin: Can not add role for a user in case g = _, _, _
I have the following role definition:
[role_definition]
g = _, _, _
But, when I am trying to add a role for a user, the function addRoleForUser accepts only two parameters (it is hardcoded), so I can not provide the domain.
Here is the test-case I wrote to check that:
it('Should properly add new role to user and remove it from the enforcer', async () => {
const enforcer = await getEnforcer();
assert.deepEqual(await enforcer.getGroupingPolicy(), []);
// here I am trying to add role, but signature for the method accepts only user and role
assert.isTrue(await enforcer.addRoleForUser('subject', 'role', 'domain'));
});
So, as a result, I am getting the following error:
Error: grouping policy elements do not meet role definition
at Assertion.buildRoleLinks (node_modules/casbin/lib/model/assertion.js:40:23)
at astMap.forEach.value (node_modules/casbin/lib/model/model.js:123:19)
at Map.forEach (<anonymous>)
at Model.buildRoleLinks (node_modules/casbin/lib/model/model.js:122:16)
at Enforcer.buildRoleLinks (node_modules/casbin/lib/coreEnforcer.js:246:20)
at Enforcer.<anonymous> (node_modules/casbin/lib/managementEnforcer.js:339:22)
at Generator.next (<anonymous>)
at fulfilled (node_modules/casbin/lib/managementEnforcer.js:17:58)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (18 by maintainers)
Hi. The
domainparam has been added, see: https://github.com/casbin/node-casbin/commit/e876217bcf4e352fc73bd98949c74812661c0e47 and https://github.com/casbin/node-casbin/commit/290355f9c411d7ca929c2a2752a379729e6ba4b0