Comments (7)
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.
@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.
@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.
Yes. first delete all policy then renew add all policy.
from node-casbin.
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:
- Create a new enforcer with the rbac model and the mysql db connection detail
enforcer = await casbin.newEnforcer('./config/rbac_model.conf', conn); - Add policies or remove policies as required
enforcer.addPolicy(policy.userId,${serviceId}_${policy.category}
, policy.permission)); - save policy
await enforcer.savePolicy();
from node-casbin.
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.
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)
- 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.