-
-
Notifications
You must be signed in to change notification settings - Fork 842
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
Policy Extender and Tests #2461
Conversation
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.
Just some minor comments
I think we should also mark the old (nvm, we'd have to do that after deprecating AbstractPolicy
class deprecated ?ScopeModelVisibility
event as well)
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.
Looking good, I just can't figure out where the policy classes are resolved through the container.
Does it happen in User::setGate($this->app->makeWith(Access\Gate::class, ['policies' => $this->app->make('flarum.policies.compiled')]));
?
It would be ideal to only instantiate the class when interacting with that model.
It happens in |
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.
Looks good to me!
8229dcf
to
31bfb13
Compare
713a53e
to
fb7237a
Compare
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.
Still haven't been able to test locally, but the code looks good. A few things.
One other thought: do we want to support returning |
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.
Thanks. Your changes solve the problem of delaying resolve, but not of selectively resolving.
Most of the time, one request will only interact with the polices for one model, so it would be best to not resolve all policies for all existing models in the application.
What about calling a new method around line 82 which takes the list of class names, and takes/stores instances from an array which is keyed by the class name and serves as a cache?
Could we maybe even use the container itself to store instances? We could check if Container::bound
, then Container::make
and Container::instance
store the policy.
Or alternatively, in the extender, register every policy as a singleton, then just use make
in the Gate.
Not sure which of the options is more performant if you end up with a large number of policies.
Regarding the I think allowing them might make things ambiguous, because what would they map to? However it would probably be great to have an error message if you return anything that's not |
Hmm, that makes sense. Making the policies singletons feels inefficient, but I see what you mean about resolving model by model. Will try that. |
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.
Testing locally via GUI attempting to break things everything went well. We'll for sure want QA to test the permission stuff more during that process. But overall I'm happy with the results.
- 4 tiers of results - Separate out into `Access` folders - Keep "old" policies for visibility scoping for now, these will be removed when visibility scoping extender PR is merged
[ci skip] [skip ci]
[ci skip] [skip ci]
[ci skip] [skip ci]
[ci skip] [skip ci]
[ci skip] [skip ci]
[ci skip] [skip ci]
[ci skip] [skip ci]
36cc936
to
28c2802
Compare
Foundation for fixing #1832
Part of #1891
Please note that most of this diff is moving policy implementation content from the root folder of each service directory to an
Access
subfolder.Changes proposed in this pull request:
Access
sub-namespaceReviewers should focus on:
Confirmed
composer test
).Required changes: