Skip to content
Snippets Groups Projects
Verified Commit 0a7cb790 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3419548 by amateescu, smustgrave, malcomio: Workspace switcher block does not check access

(cherry picked from commit bed3a77a)
parent bdcf4705
No related branches found
No related tags found
6 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...
Pipeline #130562 passed with warnings
Pipeline: drupal

#130579

    Pipeline: drupal

    #130570

      ......@@ -2,11 +2,14 @@
      namespace Drupal\workspaces\Plugin\Block;
      use Drupal\Core\Access\AccessResult;
      use Drupal\Core\Access\AccessResultInterface;
      use Drupal\Core\Block\Attribute\Block;
      use Drupal\Core\Block\BlockBase;
      use Drupal\Core\Entity\EntityTypeManagerInterface;
      use Drupal\Core\Form\FormBuilderInterface;
      use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
      use Drupal\Core\Session\AccountInterface;
      use Drupal\Core\StringTranslation\TranslatableMarkup;
      use Drupal\workspaces\Form\WorkspaceSwitcherForm;
      use Symfony\Component\DependencyInjection\ContainerInterface;
      ......@@ -82,4 +85,15 @@ public function build() {
      return $build;
      }
      /**
      * {@inheritdoc}
      */
      protected function blockAccess(AccountInterface $account): AccessResultInterface {
      return AccessResult::allowedIfHasPermissions($account, [
      'view own workspace',
      'view any workspace',
      'administer workspaces',
      ], 'OR');
      }
      }
      ......@@ -53,6 +53,11 @@ public function testSwitchingWorkspaces() {
      $gravity = $this->createWorkspaceThroughUi('Gravity', 'gravity');
      // Confirm the block shows on the front page.
      $this->drupalGet('<front>');
      $page = $this->getSession()->getPage();
      $this->assertTrue($page->hasContent('Workspace switcher'));
      $this->drupalGet('/admin/config/workflow/workspaces/manage/' . $gravity->id() . '/activate');
      $this->assertSession()->statusCodeEquals(200);
      ......
      ......@@ -245,7 +245,6 @@ public function testWorkspaceFieldUi() {
      */
      public function testDeleteWorkspaceWithExistingContent() {
      $this->createContentType(['type' => 'test', 'label' => 'Test']);
      $this->setupWorkspaceSwitcherBlock();
      // Login and create a workspace.
      $this->drupalLogin($this->rootUser);
      ......
      ......@@ -82,12 +82,8 @@ protected function setupWorkspaceSwitcherBlock() {
      'region' => 'sidebar_first',
      'label' => 'Workspace switcher',
      ]);
      // Confirm the block shows on the front page.
      $this->drupalGet('<front>');
      $page = $this->getSession()->getPage();
      $this->assertTrue($page->hasContent('Workspace switcher'));
      $this->switcherBlockConfigured = TRUE;
      }
      ......
      ......@@ -223,4 +223,26 @@ public function testWorkspaceSelection() {
      $this->assertEquals($expected_top, array_keys($selection_handler->getReferenceableEntities('top')['workspace']));
      }
      /**
      * @covers \Drupal\workspaces\Plugin\Block\WorkspaceSwitcherBlock::blockAccess
      */
      public function testWorkspaceSwitcherBlock(): void {
      $own_permission_user = $this->createUser(['view own workspace']);
      $any_permission_user = $this->createUser(['view any workspace']);
      $admin_permission_user = $this->createUser(['administer workspaces']);
      $access_content_user = $this->createUser(['access content']);
      $no_permission_user = $this->createUser();
      /** @var \Drupal\Core\Block\BlockManagerInterface $block_manager */
      $block_manager = \Drupal::service('plugin.manager.block');
      /** @var \Drupal\Core\Block\BlockPluginInterface $switcher_block */
      $switcher_block = $block_manager->createInstance('workspace_switcher');
      $this->assertTrue($switcher_block->access($own_permission_user));
      $this->assertTrue($switcher_block->access($any_permission_user));
      $this->assertTrue($switcher_block->access($admin_permission_user));
      $this->assertFalse($switcher_block->access($access_content_user));
      $this->assertFalse($switcher_block->access($no_permission_user));
      }
      }
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Finish editing this message first!
      Please register or to comment