Giter Site home page Giter Site logo

Comments (6)

hsluoyz avatar hsluoyz commented on May 12, 2024 1

@lucaslrolim getAllRoles() calls getAllNamedRoles() internally, so it proves this function works for at least for the example.

from node-casbin.

nodece avatar nodece commented on May 12, 2024

Can you provide model conf.

from node-casbin.

hsluoyz avatar hsluoyz commented on May 12, 2024

@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.

lucaslrolim avatar lucaslrolim commented on May 12, 2024

@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.

nodece avatar nodece commented on May 12, 2024

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.

lucaslrolim avatar lucaslrolim commented on May 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.