Verified Commit e4134bce authored by Alex Pott's avatar Alex Pott
Browse files

Revert "Issue #3419548 by amateescu, smustgrave, malcomio: Workspace switcher...

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

This reverts commit 0a7cb790.
parent 5d048153
Loading
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -2,14 +2,11 @@

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;
@@ -85,15 +82,4 @@ 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');
  }

}
+0 −5
Original line number Diff line number Diff line
@@ -53,11 +53,6 @@ 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);
+1 −0
Original line number Diff line number Diff line
@@ -245,6 +245,7 @@ public function testWorkspaceFieldUi() {
   */
  public function testDeleteWorkspaceWithExistingContent() {
    $this->createContentType(['type' => 'test', 'label' => 'Test']);
    $this->setupWorkspaceSwitcherBlock();

    // Login and create a workspace.
    $this->drupalLogin($this->rootUser);
+4 −0
Original line number Diff line number Diff line
@@ -82,8 +82,12 @@ 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;
  }

+0 −22
Original line number Diff line number Diff line
@@ -223,26 +223,4 @@ 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));
  }

}