-
Notifications
You must be signed in to change notification settings - Fork 18
automatically initialize adapter + enforcer #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@techoner @nodece @GopherJ @divypatel9881 please review. |
|
@gerbyzation please resolve conflicts. |
|
@hsluoyz done |
|
Why don't expose adapter + enforcer? How does a user do if he wants to customize the enforcer? |
|
@hsluoyz Pycasbin by design queries all the existing policy rules from the linked storage into memory when it's initialised. In django this is problematic because it will query the database before django is ready. Several options to mitigate this:
To be able to implement option 3 we need to control the enforcer so we can manage the timing of it's initialization. I could think of two ways of doing that:
As it's less hacky and fits well with the django ecosystem option 2 seemed like the obvious choice to me. To configure casbin this PR adds several settings: To summarise this attempts to offer a ready made solution to the initialization problem for users, plus also provide a more way more fitting for django on how casbin is added to an application. Also note that the use Hope that answers your question? |
|
@techoner @nodece @GopherJ @divypatel9881 please review. |
divy9881
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is fine.
|
looks good. |
|
🎉 This PR is included in version 1.0.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
as mentioned in #2 there are still some challenges on how to initialize the enforcer:
This is an attempt to solve that problem and making the package easier to use. It adds a proxy wrapper around the enforcer that defers it's initialization until django fires it's
readyevent and checks the migrations have been run.Configuratin now happends through django settings, where
CASBIN_MODEL,CASBIN_LOG_ENABLED,CASBIN_WATCHERandCASBIN_ROLE_MANAGERcan be set. When the enforcer is initialised they will be passed to the enforcer or appropriate methods called to set them.Let me know what you think of this approach. I'll be testing this in our app this week.
If you're happy to pursue this I can have a look at adding some more test coverage.