Closed (fixed)
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Order
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
7 May 2020 at 16:04 UTC
Updated:
18 Sep 2020 at 16:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mglamanThis should be fixed with the latest Entity API release which fixed the JSON:API security layer with existing Entity API permission setup. Can you let me know if this is still broken?
Comment #3
skyredwangSee the discussion below, @mglaman pin pointed the cause, and have a solution in mind.
Comment #4
skyredwangI wrote this patch below. But, it doesn't seem to solve the problem, and the code is not even called by JSON:API.
Comment #5
skyredwangI used
commerce_order_jsonapi_commerce_order_filter_accesshook instead, then it gets called. I debugged the return of the function, the result is good. However, filter in JSON:API still doesn't return anything.Comment #6
mglamanThe generic is hook_jsonapi_entity_filter_access and specific entity overrides in hook_jsonapi_ENTITY_TYPE_filter_access. jsonapi.module actually does this. So we need commerce_order_jsonapi_commerce_order_filter_access.
Comment #7
skyredwangI did try that, here is the problem
https://git.drupalcode.org/project/drupal/-/blob/8.9.x/core/modules/json...
L347 $access_results["filter_among_own"] is allowed, but
L387 still expects owner key for non-user entity, and $access_results["filter_among_own"] isn't checked until it finds the owner.
So, I am guessing this hook won't help us solve the problem?
Comment #8
mglamanWorking on this! It is vital for customer order history pages.
Comment #10
mglamanAs @skyredwang has pointed out, the hook results used in \Drupal\jsonapi\Access\TemporaryQueryGuard::getAccessConditionForKnownSubsets will not do us any good. This supports the following entity keys for mapping:
If no conditions are set, the query access is marked as
static::alwaysFalse($entity_type);.This result is used in \Drupal\jsonapi\Access\TemporaryQueryGuard::getAccessCondition.
Since orders do not have an owner entity key, the
JSONAPI_FILTER_AMONG_OWNaccess result is ignored.However, order's actually have entity query access through Entity API. So we can choose to bypass the TemporaryQueryGuard provided by JSON:API. I think the correct fix is to make
JSONAPI_FILTER_AMONG_ALLallowed.If it is allowed, then the entire JSON:API layer that intends to create an entity query access layer is bypassed.
This should allow
\Drupal\commerce_order\OrderQueryAccessHandlerto do its job.Comment #11
mglamanI got ahead of myself and ruined the test only run. DrupalCI queues after each commit, but it runs ahead the merge request's branch HEAD. Not each commit.
Either way, this seems to be the right fix!
Comment #12
skyredwangIt works well!
Comment #13
mglamanI want to add test coverage for an admin filtering and anonymous users. Then I think we can commit.
Comment #14
introfini commentedIt's working. Thanks!
Comment #15
mglamanOkay, in https://git.drupalcode.org/project/commerce/-/merge_requests/5/diffs?com... I have expanded test to
view own commerce_ordercannot find any ordersview commerce_ordercan find all orders.Comment #16
mglamanBack to RTBC per @skyredwang in #12, confirmed by @introfini in #14!
Comment #18
mglaman🥳 Committed!