Users with 'access commerce_promotion overview' permission cannot access the promotion collection page, while the analogous permissions of orders and products work.

The difference is, that the others use a View with the appropriate permission set, while the original collection routes won't check for that permission.

I'll see that the best solution in the long run would be to add/fix this directly in Entity API, where the permission providers and the the access control handlers derive from.

I'm not sure, if there are any other similar routes in Commerce concerned.

I'd strongly vote for fixing this bug in Commerce for this route specifically. Then we can still discuss, if Entity API should already ship with that default for collection routes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

agoradesign created an issue. See original summary.

agoradesign’s picture

Status: Active » Needs review
FileSize
658 bytes

here's the patch

Status: Needs review » Needs work

The last submitted patch, 2: fix_promotion_collection_access-2945286-2.patch, failed testing. View results

agoradesign’s picture

Status: Needs work » Needs review
FileSize
688 bytes

next try

mglaman’s picture

Issue tags: +Needs tests

Needs functional test to verify bug then fix.

agoradesign’s picture

Assigned: Unassigned » agoradesign

I'll provide one

The last submitted patch, 7: fix_promotion_collection_access-2945286-7.patch, failed testing. View results

agoradesign’s picture

ooops... accidentially deleted a line immediately before patch creation...

agoradesign’s picture

The last submitted patch, 10: fix_promotion_collection_access-2945286-10-test_only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

agoradesign’s picture

ok cool.. test and patch are both working.. here's the cleaned up version having the unused imports removed

mglaman’s picture

+++ b/modules/promotion/commerce_promotion.routing.yml
@@ -23,3 +23,11 @@ entity.commerce_promotion_coupon.generate_form:
+    _permission: 'access commerce_promotion overview+administer commerce_promotion'

I'm curious why we need to manually define this route and fix the permissions.

I want to look into the route provider as well to see what is up. This permission access commerce_promotion overview does not exist, as far as I know. Unless Drupal\commerce\EntityPermissionProvider is providing it (I don't think so?)

Thanks for the tests!

agoradesign’s picture

Yes it does, to be more precise: the permission provider of Entity API is providing it, but apparently not caring about its usage on collection routes... so that's why I wrote in teh summary:

I'll see that the best solution in the long run would be to add/fix this directly in Entity API, where the permission providers and the the access control handlers derive from.

So it's a bug or rather missing feature of Entity API, resulting in an annoying bug in Commerce. That's why I'm proposing this patch for Commerce. I don't think that Entity API will get this in soon

mglaman’s picture

Issue tags: -Needs tests

Discussed in Slack: we need to open an issue in the Entity API queue about the bug and add a # @todo Remove once :link resolved

mglaman’s picture

There is nothing to do in Entity API, actually. It is providing the generally accepted permission of "overview". However, Drupal core does not support that type of permission granularity.

The route itself uses the admin permission

      $route = new Route($entity_type->getLinkTemplate('collection'));
      $route
        ->addDefaults([
          '_entity_list' => $entity_type->id(),
          '_title' => $label->getUntranslatedString(),
          '_title_arguments' => $label->getArguments(),
          '_title_context' => $label->getOption('context'),
        ])
        ->setRequirement('_permission', $admin_permission);

This means the permission bug is present on any entity collection overridden by a View. So we need to provide an overridden RouterProvider or keep the manual fix in the routing.yml.

mglaman’s picture

Assigned: agoradesign » mglaman

Discussed with bojanz and agoradesign. It sounds like the way forward would still be a patch in Entity API. Entity API should have a route provider which respects the overview permission. It will need to check that the entity uses the EntityPermissionProvider handler and adds the overview permission alongside the admin permission.

mglaman’s picture

Status: Needs review » Postponed

I'm going to postpone this on the other issue. Just makes the issue queue easier to grok.

agoradesign’s picture

Status: Postponed » Needs review
FileSize
3.12 KB

Now that the issue is unblocked, here's an updated patch using the new route provider

bojanz’s picture

Title: Users with 'access commerce_promotion overview' permission cannot access the promotion collection page » The "access overview" permission is not used/respected
Status: Needs review » Needs work

We should make the change in all of our entity types. Product attributes have the same problem (since they don't use a view), and others could easily trigger this if someone disables a shipped view.

We probably don't need a test, since we're relying on Entity API (and at one point core) to do the heavy lifting.

mglaman’s picture

Assigned: mglaman » Unassigned
Status: Needs work » Needs review
FileSize
4.22 KB

It's only for Order and Product. Product Attributes we only have the admin permission.

Status: Needs review » Needs work

The last submitted patch, 23: the_access_overview-2945286-23.patch, failed testing. View results

mglaman’s picture

Status: Needs work » Needs review
FileSize
4.25 KB

Retry on patch.

bojanz’s picture

Assigned: Unassigned » bojanz
Status: Needs review » Needs work

We definitely have the following permissions:
- Access the product attributes overview page
- Access the stores overview page

I'll go ahead and convert ProductAttribute and Store as well.

  • bojanz committed 3641d2e on 8.x-2.x authored by agoradesign
    Issue #2945286 by agoradesign, mglaman, bojanz: The "access overview"...
bojanz’s picture

Status: Needs work » Fixed

Fixed Store and ProductAttribute, updated the references to the PermissionProvider while I was at it (the Commerce one has been deprecated in 2.0 but was still used).

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.