
This is a follow-up that was never filed for: #2939722: Do not provide routes for internal resource types
The motivation is that I would like to keep simplifying the RequestHandler/EntityResource. When the relationship field is a route parameter, we have to deal with more moving parts. E.g. if we get a request for `/jsonapi/node/foo/relationships/missingfield` we have to manually throw a 404 exception, rather than just letting the router handle that.
I already started working on this and just need to re-roll an older patch.
Comment | File | Size | Author |
---|---|---|---|
#30 | 2953346-30.patch | 35.87 KB | gabesullice |
#30 | interdiff-28-30.txt | 5.24 KB | gabesullice |
#28 | 2953346-28.patch | 32.94 KB | gabesullice |
#28 | interdiff-26-28.txt | 651 bytes | gabesullice |
#26 | 2953346-26.patch | 33.04 KB | gabesullice |
Comments
Comment #2
e0ipsoI think this is a better approach. I see us moving towards that path at some point. However I'd like to slate this for after core's inclusion. At this point I feel we ought to fix the remaining issues and move the bureaucracy forward.
What are your thoughts?
Comment #3
gabesulliceI don't think one should prevent the other. I think they can happen in parallel.
I agree that it is time for us to push the bureaucracy forward and indeed, I think we are! #2836165-37: New experimental module: JSON API
Comment #4
wim leersIf anything, this should happen before that. Architectural changes will be 10x slower once this is in core.
Comment #5
wim leersI think this probably makes sense to move this to 2.x?
Comment #6
wim leersTentatively moving.
Comment #7
gabesulliceI wonder if my name for this issue makes the task sound like a much bigger undertaking than it is. Perhaps that "static" part could have been taken to mean "in YAML" or config or something like that.
By "statically," I just meant that the field name shouldn't be a route parameter and that we should create a route for each possible field, rather than handle the field dynamically.
Having a param just adds edge cases for us to handle unecessarily, since we really don't need to check anything "at runtime"
Comment #8
gabesulliceThis would be a completely non-breaking change AFAICT
Comment #9
wim leersI think you're right, that simpler framing of things does make the scope much clearer. This would also solve #2960082: Spec Compliance: requests to "<resource>/relationships" should result in 404 response, currently results in fatal PHP error.
The only complication I can think of is that this would require route rebuilds whenever fields are added. We'll need something like
\Drupal\rest\EventSubscriber\RestConfigSubscriber
to trigger a route rebuild whenever entity or field config are modified.Comment #10
wim leersClosing #2960082: Spec Compliance: requests to "<resource>/relationships" should result in 404 response, currently results in fatal PHP error as a duplicate. Moving over @BR0kEN's explicit failing test coverage from #2960082-5: Spec Compliance: requests to "<resource>/relationships" should result in 404 response, currently results in fatal PHP error.
Comment #12
wim leersCrediting @BR0kEN.
Comment #13
wim leersBecause of #9/#10, this also affects DX. Tagging.
Comment #14
wim leersTitle typo.
Comment #15
gabesulliceComment #16
gabesulliceGetting this started again.
This patch won't apply until #2973784: JSON API should check entity access during routing, not in controller, for the "individual" route lands.
Comment #17
wim leersCould be changed to
!$request->isMethodSafe()
. Don't feel strongly about it though, I'll let you choose.This
@todo
is addressed 👍This one is not❓
Can't we now also remove these?
Comment #18
gabesulliceHaven't seriously addressed the review in #17, this is still a WIP. Although I did take the
isMethodSafe
suggestion.This primarily gets rid of the access checks that the route-level access check makes obsolete.
One notable change that this introduces is that the errors no longer contain a pointer. That makes sense, there's no document to point at. Pointers only make sense when PATCHing a resource. They "point" to errors in the submission.
Comment #19
gabesullice#2973784: JSON API should check entity access during routing, not in controller, for the "individual" route is in. Kicking tests. Still a WIP.
Comment #22
gabesulliceHandles the low-hanging fruit in those failures.
Comment #23
gabesulliceMore orchard harvesting.
These kernel tests can all be removed because
EntityResource
no longer needs to check for 404s. Those routes don't even exist anymore!Comment #25
gabesulliceCode standards.
Comment #26
gabesullice🤞should be green.
Even if green, still not done. The next step will be to convert/remove the
related
route default (mentioned in #17.4). I'm not sure that we should remove it entirely, it's still useful as a parameter, but maybe it should be a route parameter (underoptions
) rather than a default.Comment #27
gabesulliceSo happy to finally be doing this :)
Now, we're actually getting a correct error code :)
All of the above "request-time" logic is replaced by:
🙂
Comment #28
gabesullice#17.1: Done, changed to
isMethodCacheable()
because of a deprecation warning.2. ✔️
3. I just tried to do this, but I don't think it makes sense to do. I think that todo shouldn't have been put there. I think it had more to do with the normalizer's use of the request object than that default being a bad one.
4. #16 discusses this. It's a correct and useful value, it doesn't need to be removed. Removing it would mean having to inspect the route object again, which we tried hard to remove.
Comment #29
wim leersNit: Let's remove this.
Even if there is no reason, I think we still want that default message to be shown. We can transform a reasonless access result into one that has at least the generic text.
::createRelationship()
anddeleteRelationship()
are still explicitly calling$field_list->access()
. I think that already was unnecessary.(Actually,
relationshipAccess()
was being called with, and that method called entity access and field access with that operation. That's fine for entity access, but WRONG for field access. Thanks to the explicit extra field access check — the one I'm asking you to remove — a security vulnerability was averted! 😱)
🎉
You still need to remove
\Drupal\jsonapi\Controller\EntityResource::relationshipAccess()
:D🎉
Comment #30
gabesulliceAddresses #29.
Comment #31
wim leers👌
Comment #34
wim leers