It seems sometimes we need to getReferenceableEntities with some access control.

An example is on Matt Glaman (mglaman)'s Commerce Marketplace
https://github.com/mglaman/commerce_marketplace/blob/master/src/Plugin/E...

It would be more than helpful to have a generic extend for Entity references selection, when we can use the EntityAccessControlHandler to get the right Entities based on user permissions to use those references.

Other example is at #2885534-2: Create order type permission doesn't allow orders to be created
In this issue it's about "commerce_entity_select" form input element.
First i think we need to use, somehow, the EntityReferenceSelection, instead of having its own processEntitySelect().
And second, in the issue, it's about access based on "create" entity permission.
So the access control here, should be aware about entity operations access.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vasike created an issue. See original summary.

vasike’s picture

Status: Active » Needs review
FileSize
8.8 KB

Here is a try on this matter

- New "EntityReferenceSelection" plugin : CommerceDefaultSelection
which extends the default one.

- Add new "operation_access" setting to "entity_reference_selection" schema
This new setting could be used to specify the entity operation is needed for (create, update, delete, view)
And implement it for the configuration form

- "Create" operation - specific case, when we need a list of Config entities that are "bundleOf" an entity type
For example the need for "OrderAddForm"
Alter getReferenceableEntities with EntityAccessControlHandler for create

- For the other operations, alter the "buildEntityQuery"
Several scenarios there based on operations, ownership and bundle permissions.
Not sure about ownership if we do not have owner field as "annotation", could be anything else than "uid".

- Update the "EntitySelect" (commerce_entity_select) element and include a new '#operations_access' property.
And use the EntityReferenceSelection to get the referenced entities.

- Example: in "OrderAddForm" for "Order type" and "Store" elements.

Not sure if we could imagine a generic solution, that could be included in Entity module, or Core.
Anyway, at least we could discuss about this and maybe find a (better) solution, at least for Commerce.

Feedback, please

zenimagine’s picture

- Do you think it is possible to control the access to payment methods by shop?
This means that each shop owner can configure his payment method.
For example each shop may have a different PayPal account.

- Same question for shipping methods.

bojanz’s picture

Status: Needs review » Closed (won't fix)

This is no longer needed, since Commerce 2.10 uses the Entity Query Access API added to Entity API 8.x-1.0-rc1.

See #2499645: Start using the entity query access API on orders, products and stores.