Support from Acquia helps fund testing for Drupal Acquia logo

Comments

naveenvalecha created an issue. See original summary.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anonymous’s picture

Status: Active » Needs review
FileSize
7.15 KB

This patch will fail. Way to pass:

   protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
     if ($operation === 'view') {
-      return AccessResult::allowed();
+      return AccessResult::allowedIfHasPermission($account, 'administer menu');

Status: Needs review » Needs work

The last submitted patch, 3: rest_menu-2843783-3.patch, failed testing.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
8.51 KB
2.06 KB
Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Looks perfect, thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/system/src/MenuAccessControlHandler.php
@@ -19,7 +19,7 @@ class MenuAccessControlHandler extends EntityAccessControlHandler {
-      return AccessResult::allowed();
+      return AccessResult::allowedIfHasPermission($account, 'access content');

This needs more discussion. As per the other issues. See #2843772-15: EntityResource: Provide comprehensive test coverage for DateFormat entity

Anonymous’s picture

Status: Needs work » Needs review
FileSize
7.93 KB
2.2 KB
alexpott’s picture

@vaplas - we still need to discuss what is the right generic approach to viewing config entities on #2870018: Should the 'access content' permission be used to control access to viewing configuration entities via REST

Anonymous’s picture

Title: EntityResource: Provide comprehensive test coverage for Menu entity » [PP-1] EntityResource: Provide comprehensive test coverage for Menu entity
Status: Needs review » Postponed

@alexpott, thank you for the additional clarification and the special issue. I just wanted to connect Mr. Bot to the discussion too :).
Postponed by #2870018: Should the 'access content' permission be used to control access to viewing configuration entities via REST.

Wim Leers’s picture

Wim Leers’s picture

Title: [PP-1] EntityResource: Provide comprehensive test coverage for Menu entity » EntityResource: Provide comprehensive test coverage for Menu entity
Status: Postponed » Reviewed & tested by the community

Consensus was achieved! Quoting #2870018-35: Should the 'access content' permission be used to control access to viewing configuration entities via REST:

  1. config entities that do not yet have an access control handler nor an admin_permission (RdfMapping, Tour): add an admin_permission.
  2. update all access control handlers for entity types that currently grant access without requiring any permission (View, Menu, File, DateFormat): change them to require the entity type's admin_permission or the entity-type specific "view" permission (yet to be added), so for example: AccessResult::allowedIfHasPermissions($account, ['view menu', 'administer menu'], 'OR').

Turns out #8 already changed it in the necessary way! :D

clemens.tolboom’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/system/src/MenuAccessControlHandler.php
@@ -18,11 +18,8 @@ class MenuAccessControlHandler extends EntityAccessControlHandler {
   protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
-    if ($operation === 'view') {
-      return AccessResult::allowed();
-    }
     // Locked menus could not be deleted.
-    elseif ($operation == 'delete') {
+    if ($operation === 'delete') {
       if ($entity->isLocked()) {
         return AccessResult::forbidden()->addCacheableDependency($entity);
       }

I do not see the mentioned #12

AccessResult::allowedIfHasPermissions($account, ['view menu', 'administer menu'], 'OR')

This issue is on 8.3.x. Is that correct?

Wim Leers’s picture

Version: 8.3.x-dev » 8.4.x-dev
FileSize
7.79 KB
14.74 KB

Changing access control handlers means this can only be 8.4.x, good catch.

You don't see the "if has VIEW or ADMIN permission", because that'd require adding new permissions, which has yet other implications. That was the principle, but in applying the principle, we cannot add permissions in these issues; adding VIEW permissions must happen in other issues.

And per #2870018-47: Should the 'access content' permission be used to control access to viewing configuration entities via REST as well as #2843772-23: EntityResource: Provide comprehensive test coverage for DateFormat entity and subsequent comments, we must convert the view operation to the view label operation in the access control handler, to not break BC. Full test coverage added.

tedbow’s picture

+++ b/core/modules/system/src/MenuAccessControlHandler.php
@@ -17,14 +17,20 @@ class MenuAccessControlHandler extends EntityAccessControlHandler {
   protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
-    if ($operation === 'view') {
+    // There are no restrictions on viewing the label of a date format.
+    if ($operation === 'view label') {
       return AccessResult::allowed();
     }
     // Locked menus could not be deleted.
-    elseif ($operation == 'delete') {
+    elseif ($operation === 'delete') {
       if ($entity->isLocked()) {
-        return AccessResult::forbidden()->addCacheableDependency($entity);
+        return AccessResult::forbidden('The Menu config entity is locked.')->addCacheableDependency($entity);

Looking at this access controller and #2843772: EntityResource: Provide comprehensive test coverage for DateFormat entity aren't a bunch of config entity access controllers going to be exactly the same?

Would it make sense to make

class ConfigEntityAccessController extends EntityAccessControllor

Then we could set all config entities that follow this pattern to use ConfigEntityAccessController directly?

+++ b/core/modules/system/tests/src/Kernel/MenuAccessControlHandlerTest.php
@@ -0,0 +1,149 @@
+class MenuAccessControlHandlerTest extends KernelTestBase {

If we can't do ConfigEntityAccessController could either have
ConfigEntityAccessHandlerTestBase extends KernelTestBase
or ConfigEntityAccessHandlerTrait

Looking at #2843772: EntityResource: Provide comprehensive test coverage for DateFormat entity all these tests are going to be very similar. Just a thought.

If we don't want to do any of that refactoring I think this good to RTBC!

Wim Leers’s picture

Then we could set all config entities that follow this pattern to use ConfigEntityAccessController directly?

That's … a very good point :) Although I have to add that isLocked() is not actually on a generic interface yet. I think extracting a LockableInterface is going to be a hard requirement. I count at least 5 config entity types that'd need to use it (DateFormat, NodeType, Menu, ConfigurableLanguage, FieldStorageConfig). Then this issue would have to be blocked on that one.

On the other hand, I think many of these access control handlers will start to diverge over time. Their access control will get more refined. Particularly for complex and broadly/frequently used config entities like Menu.

So I personally think it's not worth it.

tedbow’s picture

Status: Needs review » Reviewed & tested by the community

Ok. sounds good. RTBC!

  • catch committed 5e2e4a8 on 8.4.x
    Issue #2843783 by vaplas, Wim Leers, tedbow: EntityResource: Provide...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 5e2e4a8 and pushed to 8.4.x. Thanks!

Wim Leers’s picture

Component: rest.module » menu system
Issue tags: +API-First Initiative

Thanks!

Status: Fixed » Closed (fixed)

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