Comments (6)
@lucaslrolim getAllRoles()
calls getAllNamedRoles()
internally, so it proves this function works for at least for the example.
from node-casbin.
Can you provide model conf.
from node-casbin.
@lucaslrolim We have added some tests here: 43e2654 . And it shows e.getAllRoles()
works. Can you try this test and see if there's anything wrong with your code.
from node-casbin.
@nodece
My model is:
[request_definition]
r = sub, obj, dom, act
[policy_definition]
p = sub, obj, dom, act
[role_definition]
g = _, _
g2 = _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = g(r.sub, p.sub) && g2(r.obj, p.obj) && (regexMatch(r.dom, p.dom) || r.dom === '') && (regexMatch(r.act, p.act) || p.act === 'all')
@hsluoyz I'm using getAllNamedRoles
, maybe this method has differences of getAllRoles
. I will double check my code.
from node-casbin.
dev env
node: v8.11.2
casbin: v1.1.9
simple test
async function test() {
const modelText = `
[request_definition]
r = sub, obj, dom, act
[policy_definition]
p = sub, obj, dom, act
[role_definition]
g = _, _
g2 = _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = g(r.sub, p.sub) && g2(r.obj, p.obj) && (regexMatch(r.dom, p.dom) || r.dom === '') && (regexMatch(r.act, p.act) || p.act === 'all')
`;
const m = newModel(modelText);
const e = await newEnforcer(m);
await e.addNamedGroupingPolicy('g', 'test_role', 'admin');
await e.addNamedGroupingPolicy('g', 'sub_role_test1', 'test_role');
await e.addNamedGroupingPolicy('g', 'sub_role_test2', 'test_role');
await e.addNamedGroupingPolicy('g', 'sub_role_test2', 'test_role');
await e.addNamedGroupingPolicy('g', 'test_role_2', 'admin');
await e.addNamedGroupingPolicy('g', 'user_test', 'just_test_role');
await e.addNamedGroupingPolicy('g2', 'glosas', 'plataforma');
await e.addNamedGroupingPolicy('g2', 'credentials', 'plataforma');
const g = e.getAllNamedRoles('g');
console.log(g, g.length !== 0 && g.some(n => n === 'admin'));
const g2 = e.getAllNamedRoles('g2');
console.log(g2, g2.length !== 0 && g2.some(n => n === 'plataforma'));
}
print result
[ 'admin', 'test_role', 'just_test_role' ] true
[ 'plataforma' ] true
You can try using the above test :)
from node-casbin.
The error was really related to the order of my Express routes. Sorry about the mistake e thank you for the help @hsluoyz and @nodece.
from node-casbin.
Related Issues (20)
- Problem "invalid group" with v5.24.4 and later HOT 10
- `RBAC with Domains API` # `e.getUsersForRoleInDomain` doesn't work. HOT 3
- FileAdapter doesn't escape values when saving policy HOT 6
- [Question] Policy_effect 'deny' does not work when combining multiple models in one model configuration HOT 3
- Prefered way to use casbin in a web framework with lots of users? HOT 2
- No Cloudflare Workers support? HOT 2
- Casbin Watcher for Prisma ORM HOT 4
- Add to Nest.js docs HOT 1
- KeyMatch5 does not match the expected result HOT 1
- [email protected]: The expression-eval npm package is no longer maintained HOT 5
- [feature] ABAC support for EnableAcceptJsonRequest() HOT 2
- enforcer.deleteUser() wiped out all data from `casbin_rule` table HOT 1
- Without enforcer.loadPolicy() Casbin behave unpredictably on mass updates. HOT 1
- [Bug] Can't resolve 'fs' HOT 7
- [bug] When using ‘watcherEx’, deletion does not trigger it; you need to configure a ‘watcher’ for it to work. HOT 2
- [Bug] The lack of a constructor results in the default configuration not taking effect. HOT 3
- addMatchingFunc HOT 2
- usage of addMatchingFunc HOT 2
- [Question] Can the cache stored in memory here be placed in Redis? HOT 3
- Why I can't use enforcer to judge the req using the rbac modle? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-casbin.