Giter Club home page Giter Club logo

Comments (7)

hsluoyz avatar hsluoyz commented on May 18, 2024 2

Good to hear it works! I have added your project to our site: https://casbin.org/ Let us know if you have more questions and welcome contributing back :)

from node-casbin.

devsatishm avatar devsatishm commented on May 18, 2024 1

@nodece @hsluoyz When we add a new policy, should we avoid calling savePolicy() after addPolicy() - To avoid cleanup of entries each time?

from node-casbin.

devsatishm avatar devsatishm commented on May 18, 2024 1

@hsluoyz Cool, thanks for the reply! We've just tested by removing the call to savePolicy() and it seems to work as you've mentioned.

Good work on the project, we have started using casbin for implementing the ACL/Permission model in our opensource project - https://github.com/tmobile/jazz. Also, we're thinking of contributing back by putting together DynamoDB adapter in NodeJs.

from node-casbin.

nodece avatar nodece commented on May 18, 2024

Yes. first delete all policy then renew add all policy.

from node-casbin.

pspani avatar pspani commented on May 18, 2024

Appreciate the quick response. I didn't understand your comment. On the adapter level, I see whenever we save policy we delete all the policies and add the polices again. But on the node-casbin level, after we create a new enforcer we only need to do an add policy and then a save policy.

In the code, we are saving the policy whenever we do add policy. What is happening is that for the inital number of policies, all is working fine. After a certain number of policies, the lib truncates the table and then adds the new policies. So instead of having all the old policies + new policies, we have only the new policies

The following is the basic structure that we follow:

  1. Create a new enforcer with the rbac model and the mysql db connection detail
    enforcer = await casbin.newEnforcer('./config/rbac_model.conf', conn);
  2. Add policies or remove policies as required
    enforcer.addPolicy(policy.userId, ${serviceId}_${policy.category}, policy.permission));
  3. save policy
    await enforcer.savePolicy();

from node-casbin.

nodece avatar nodece commented on May 18, 2024

casbin enable autosave by default.
Call addPolicy() method then casbin will add a new policy to DB.
savePolicy() method will delete all policy then save all policy.

from node-casbin.

hsluoyz avatar hsluoyz commented on May 18, 2024

Hi @devsatishm @pspani , when AutoSave feature is supported and enabled on the adapter, you don't need to call savePolicy() manually, each new policy rule will be automatically saved from local enforcer memory to the remote DB each time you call addPolicy(). See: https://casbin.org/docs/en/adapters#autosave savePolicy() deletes all policy rules in DB first, then save all the policy rules from local enforcer to the DB in bulk operations. It is not good for scenario of large number of policy rules.

As far as I know, all our Node.js adapters support AutoSave.

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.