-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Match operations with permission objects with set operators #21
base: main
Are you sure you want to change the base?
Conversation
- Also matches the initial premise on the permission objects.
I am doing this to make way for a proper |
At risk of sounding stupid, is this basically to get operators between permissions to behave like set operators? |
I guess I should have included some more examples. Yes, the overridden operators wasn't documented, and then if the permissions are read out in English it didn't make sense. Previously, given this: Permission(RoleNeed('manager') & Permission(RoleNeed('reviewer')) Implies that a new permission object will be constructed such that both the manager and reviewer permissions will be required, i.e. the Identity must also have both the 'manager' and 'reviewer' role in order to access the resource. However, what actually happened was that union was used, resulted in this Permission(RoleNeed('manager'), RoleNeed('reviewer')) Which, as per the documentations, results in a Permission object that checks for either the 'manager' or the 'reviewer' role, which the Now as for |
What about something like: Permission(RoleNeed('manager') and Permission(RoleNeed('reviewer')) or Permission(RoleNeed('manager') or Permission(RoleNeed('reviewer')) That, read out in English, makes sense to me. |
While they read out the same in English, the two operators are not quite the same thing (boolean operator vs. set operator), given that we are working with sets:
I guess this is why I am hesitant in implementing this because this might be too complicated for a simple library to handle. |
I totally hear you. Though, I think a problem has arisen here. I believe this is a significant API change due to the fundamental change in operator overloading. One must think differently, in terms of sets, instead of conditionals. However, if it is agreed that this is a significant API change then I'm afraid that anyone that uses Flask-Principal and uses conditional operators to compose permission schemes will experience some problems if they want to upgrade. That being said, I am also aware of the fact that there is no documentation on using operators to compose permissions schemes. Anyone who happens to be using this approach most likely looked into the code or hacked something together a little differently. I believe the set operators make more sense. However, they finally need to be documented, thoroughly, with some easy to follow examples. Are you willing to contribute a draft? |
I'll take a shot, might take me a while. I have a few ideas that also includes the 'and' and 'not' operators, but having these may require a radical change (i.e. parent class for the Permission object). Part of the inspiration for this comes from the sqlalchemy ORM filters, so aside from the two implemented operators the others may differ from the "real" set operators. I will continue work on this branch unless there are objections. It may take me a while to fully formalize this as I have limited spare time until early next year. |
- Have this class contain all the basic methods we need currently that are still needed by the Permission class.
- Can't just test one role...
- Allows the creation of permission objects that check for any of the nested permissions.
- Have the ``AndPermission`` similar to the ``OrPermission``.
Might as well show you what my intention is. Note my implementation of I will still write the docs, but I figured I should have what I really wanted to do coded out before I go and write the docs. |
- Done by testing that those singular bits of permission don't result in accessing of private bad data.
- Could keep them outside not behind those special override methods and have those call the actual implementation.
First cut of documenting of what I added (bitwise operator) was done at 680a474. |
It seems very interesting and useful ! |
+1 with @noirbizarre |
This makes much more sense to me, is there a plan of merging this? |
This seems to be ready for a merge... |
Correct the operator terms to match what one might expect if they were working with permission objects as an encapsulation of sets of roles.
Test cases enclosed to demonstrate how this compares to working with the sets directly.