-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
Model Visibility Scoping Extender and Tests #2460
Conversation
While my code in There seems to be only 3 third-party extensions importing the class. https://query.flarum.dev/q/8296c9a1-fa6f-48ca-b73e-96447cab9315 Looking through the PR, I'm a bit lost, but having the event out of the picture does seem to make the code a bit more logical to read. |
You should be able to replace that line with:
Considering how complex it would be to provide BC for this, I think we should be fine just breaking it then.
I'll add a writeup explaining the key changes, sorry should have done that to begin with. One other concern I thought of: in the change to Notification.php, we assume that any subject model will necessarily be visiblity-scopable, but this isn't necessarily the case. I suppose we could check that the class in question has the proper methods? |
@clarkwinkelmann To briefly summarize changes: Under the current model visibility scoping system, a developer can dispatch a We replace the event with a more-or-less standard, callback-based solution:
Code that triggers scoping by calling And then, of course, there's the extender and tests. |
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'm glad this moves us away from the magic of view
=> find
and findWithPermission
, the code is more clear and explicit now, easier to read.
The logic looks good to me, I only have a few minor code style comments.
a8bf467
to
f160d90
Compare
…lbacks assigned via static attributes
[ci skip] [skip ci]
f160d90
to
7e0d211
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.
Looking good code-wise!
I'm just a bit confused by the default
naming.
First the pseudo-constant. Reading the past comments it's seems it's a workaround for not being able to use a real constant? But the way it stands right now it seems like it's intended to be modifiable by classes that extend it.
Since it's used in only two places (?) couldn't we just hard-code *
? If we leave it like it is now, I think a phpdoc comment with a proper explanation and @internal
is in order.
Second I just don't think the name fits the feature. Default makes it sound like it will run if no other scoper runs, instead it really is a catch-all/listen-all. What about scopeAll
/ scopeAny
for the name of the extender method?
Fixes part of #1891
Changes proposed in this pull request:
Reviewers should focus on:
Several areas of potential concern:
whereVisibleTo
. However, dispatching aScopeModelVisibility
event will only apply visibility scopers registered via the old system (policies). I think this is reasonable though, since the only use cases of dispatchingScopeModelVisibility
I've found occur in core and bundled extensions.--process-isolation
flag tocomposer.json
, because otherwise the visibility scopers are added statically EVERY TIME a test runs, which makes things very slow. This isn't a problem for actual web requests in production, since each request is handled separately. That being said, we should move away from static stuff as much as possible after the extender API is finishedConfirmed
composer test
).