Commit 7bf1e5a4 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2449633 by joshi.rohit100, pjonckiere, willzyx, andypost:...

Issue #2449633 by joshi.rohit100, pjonckiere, willzyx, andypost: ShortcutsBlock does not respect the 'access shortcuts' permission
parent a805ce2d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
namespace Drupal\shortcut\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Session\AccountInterface;

/**
 * Provides a 'Shortcut' block.
@@ -29,4 +30,11 @@ public function build() {
    );
  }

  /**
   * {@inheritdoc}
   */
  protected function blockAccess(AccountInterface $account) {
    return $account->hasPermission('access shortcuts');
  }

}
+24 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
   *
   * @var array
   */
  public static $modules = array('router_test', 'views');
  public static $modules = array('router_test', 'views', 'block');

  /**
   * Tests that creating a shortcut works properly.
@@ -327,4 +327,27 @@ private function verifyAccessShortcutsPermissionForEditPages() {
    }
  }

  /**
   * Tests that the 'access shortcuts' permission is required to access the
   * shortcut block.
   */
  public function testShortcutBlockAccess() {
    // Creates a block instance and place in a region through api.
    $block = $this->drupalPlaceBlock('shortcuts');

    // Verify that users with the 'access shortcuts' permission can see the
    // shortcut block.
    $this->drupalLogin($this->shortcutUser);
    $this->drupalGet('');
    $this->assertBlockAppears($block);

    $this->drupalLogout();

    // Verify that users without the 'access shortcuts' permission can see the
    // shortcut block.
    $this->drupalLogin($this->drupalCreateUser(array()));
    $this->drupalGet('');
    $this->assertNoBlockAppears($block);
  }

}