Commit 54f0ac6e authored by Bart Feenstra's avatar Bart Feenstra Committed by David Snopek
Browse files

Issue #2716071 by Xano: PanelizerFieldPanelsStorage::access() calls entity...

Issue #2716071 by Xano: PanelizerFieldPanelsStorage::access() calls entity access with incorrect operations and excludes cacheability metadata
parent 40ec9a33
Loading
Loading
Loading
Loading
+18 −9
Changes for src/Plugin/PanelsStorage/PanelizerFieldPanelsStorage.php: 18 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -154,21 +154,30 @@ class PanelizerFieldPanelsStorage extends PanelsStorageBase implements Container
   */
  public function access($id, $op, AccountInterface $account) {
    if ($entity = $this->loadEntity($id)) {
      if ($op == 'change layout') {
        $entity_op = 'update';
      }
      else {
        $entity_op = $op;
      }
      if ($entity->access($entity_op, $account) && $entity instanceof FieldableEntityInterface) {
      $access = AccessResult::neutral()
        ->addCacheableDependency($account);

      // We do not support "create", as this method's interface dictates,
      // because we work with existing entities here.
      $entity_operations = [
        'read' => 'view',
        'update' => 'update',
        'delete'=> 'delete',
        'change layout' => 'update',
      ];
      // Do not add entity cacheability metadata to the forbidden result,
      // because it depends on the Panels operation, and not on the entity.
      $access->orIf(isset($entity_operations[$op]) ? $entity->access($entity_operations[$op], $account, TRUE) : AccessResult::forbidden());

      if (!$access->isForbidden() && $entity instanceof FieldableEntityInterface) {
        list (,, $view_mode) = explode(':', $id);
        if ($op == 'change layout') {
          if ($this->panelizer->hasEntityPermission('change layout', $entity, $view_mode, $account)) {
            return AccessResult::allowed();
            return $access->orIf(AccessResult::allowed());
          }
        }
        else if ($op == 'read' || $this->panelizer->hasEntityPermission('change content', $entity, $view_mode, $account)) {
          return AccessResult::allowed();
          return $access->orIf(AccessResult::allowed());
        }
      }
    }
+8 −7
Changes for tests/src/Unit/PanelizerFieldPanelsStorageTest.php: 8 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -211,8 +211,8 @@ class PanelizerFieldPanelsStorageTest extends UnitTestCase {
    $account = $this->prophesize(AccountInterface::class);

    $entity = $this->prophesize(FieldableEntityInterface::class);
    $entity->access('read', $account->reveal())
      ->willReturn(TRUE);
    $entity->access('view', $account->reveal(), TRUE)
      ->willReturn(AccessResult::allowed());

    $this->storage->load('123')->willReturn($entity->reveal());

@@ -245,8 +245,8 @@ class PanelizerFieldPanelsStorageTest extends UnitTestCase {
    $account = $this->prophesize(AccountInterface::class);

    $entity = $this->prophesize(FieldableEntityInterface::class);
    $entity->access('update', $account->reveal())
      ->willReturn(TRUE);
    $entity->access('update', $account->reveal(), TRUE)
      ->willReturn(AccessResult::allowed());

    $this->storage->load('123')->willReturn($entity->reveal());

@@ -255,7 +255,8 @@ class PanelizerFieldPanelsStorageTest extends UnitTestCase {
    $this->panelizer->hasEntityPermission('change content', $entity->reveal(), 'view_mode', $account->reveal())
      ->willReturn(TRUE);

    $this->assertEquals(AccessResult::allowed(), $this->panelsStorage->access('entity_type_id:123:view_mode', 'update', $account->reveal()));
    $access = $this->panelsStorage->access('entity_type_id:123:view_mode', 'update', $account->reveal());
    $this->assertEquals(AccessResult::allowed(), $access);
  }

  /**
@@ -266,8 +267,8 @@ class PanelizerFieldPanelsStorageTest extends UnitTestCase {
    $account = $this->prophesize(AccountInterface::class);

    $entity = $this->prophesize(FieldableEntityInterface::class);
    $entity->access('update', $account->reveal())
      ->willReturn(TRUE);
    $entity->access('update', $account->reveal(), TRUE)
      ->willReturn(AccessResult::allowed());

    $this->storage->load('123')->willReturn($entity->reveal());